Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/dnscache_dump.rb
Views: 11655
##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'Compat' => {18'Meterpreter' => {19'Commands' => %w[20stdapi_railgun_api21stdapi_railgun_memread22]23}24}25)26)27end2829def run30rtable = Rex::Text::Table.new(31'Header' => 'DNS Cached Entries',32'Indent' => 3,33'Columns' => ['TYPE', 'DOMAIN']34)3536client.railgun.add_dll('dnsapi') if !client.railgun.get_dll('dnsapi')37client.railgun.add_function('dnsapi', 'DnsGetCacheDataTable', 'DWORD', [['PBLOB', 'cacheEntries', 'inout']])38result = client.railgun.dnsapi.DnsGetCacheDataTable('aaaa')39address = result['cacheEntries'].unpack1('V')4041# typedef struct _DNS_CACHE_ENTRY42# struct _DNS_CACHE_ENTRY* pNext;43# PWSTR pszName;44# unsigned short wType;45# unsigned short wDataLength;46# unsigned long dwFlags;4748while (address != 0)49struct_pointer = client.railgun.memread(address, 10)50# Get the pointer to the DNS record name51domain_pointer = struct_pointer[4, 4].unpack1('V')52dns_type = struct_pointer[8, 2].unpack1('h*').reverse53# According to the restrictions on valid host names, we read a maximum of 255 characters for each entry54domain_name = client.railgun.memread(domain_pointer, 255).split("\x00\x00").first55rtable << [dns_type, domain_name]56# Get the next _DNS_CACHE_ENTRY struct pointer57address = struct_pointer[0, 4].unpack1('V')58end59print_status(rtable.to_s)60end61end626364