2011-10-17 04:20:53 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-10-17 04:20:53 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => "Windows Gather IP Range Reverse Lookup",
|
2011-10-23 11:56:13 +00:00
|
|
|
'Description' => %q{
|
2011-10-17 04:20:53 +00:00
|
|
|
This module uses Railgun, calling the gethostbyaddr function to resolve a hostname
|
|
|
|
to an IP.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => ['win'],
|
2011-10-17 04:20:53 +00:00
|
|
|
'SessionTypes' => ['meterpreter'],
|
2012-10-22 21:01:58 +00:00
|
|
|
'Author' => [ 'mubix' ]
|
2011-10-17 04:20:53 +00:00
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform reverse lookup against.'])
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-10-17 04:20:53 +00:00
|
|
|
def run
|
2011-10-23 11:56:13 +00:00
|
|
|
|
|
|
|
#Add ws2_32 just in case it isn't there...
|
2011-10-17 04:20:53 +00:00
|
|
|
session.railgun.ws2_32
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-10-17 04:20:53 +00:00
|
|
|
#Check if gethostbyaddr is available to us
|
|
|
|
modhandle = session.railgun.kernel32.GetModuleHandleA('ws2_32.dll')
|
|
|
|
if modhandle['return'] == 0
|
|
|
|
print_error("WS2_32 isn't available at this time, exiting")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
procaddr = session.railgun.kernel32.GetProcAddress(modhandle['return'],'gethostbyaddr')
|
|
|
|
if procaddr['return'] == 0
|
|
|
|
print_error("WS2_32 was loaded but does not have the gethostbyaddr function, exiting")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-10-17 04:20:53 +00:00
|
|
|
#Generates IP list based on RHOSTS - RangeWalker rocks....
|
|
|
|
iplist = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
|
|
|
|
|
|
|
|
iplist.each do |x|
|
|
|
|
#Converts an IP in string formate to network byte order format
|
|
|
|
nbi = Rex::Socket.addr_aton(x)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2011-10-17 04:20:53 +00:00
|
|
|
#Call gethostbyaddr
|
|
|
|
result = session.railgun.ws2_32.gethostbyaddr(nbi.to_s,nbi.size,2)
|
|
|
|
if result['return'] == 0
|
|
|
|
vprint_status("#{x} did not resolve")
|
|
|
|
else
|
|
|
|
struct = session.railgun.memread(result['return'],100)
|
|
|
|
hostname = struct.split(nbi)[1].split("\0")[0]
|
|
|
|
print_good("#{x} resolves to #{hostname}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|