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
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => "Windows Gather IP Range Reverse Lookup",
|
|
|
|
'Description' => %q{
|
|
|
|
This module uses Railgun, calling the gethostbyaddr function to resolve a hostname
|
|
|
|
to an IP.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Platform' => ['win'],
|
|
|
|
'SessionTypes' => ['meterpreter'],
|
|
|
|
'Author' => [ 'mubix' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform reverse lookup against.'])
|
2011-10-17 04:20:53 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
2011-10-17 04:20:53 +00:00
|
|
|
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#Add ws2_32 just in case it isn't there...
|
|
|
|
session.railgun.ws2_32
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2013-08-30 21:28:54 +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
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#Generates IP list based on RHOSTS - RangeWalker rocks....
|
|
|
|
iplist = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
|
2011-10-17 04:20:53 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
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
|
|
|
|
2013-08-30 21:28:54 +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
|
2011-10-17 04:20:53 +00:00
|
|
|
end
|