@@ -15,19 +15,19 @@ def initialize(info={})
15
15
'Name' => 'Windows Recon Resolve Hostname' ,
16
16
'Description' => %q{ This module resolves a hostname to IP address via the victim, similiar to the Unix dig command} ,
17
17
'License' => MSF_LICENSE ,
18
- 'Author' => [ 'Rob Fuller <mubix[at]hak5.org>' ] ,
18
+ 'Author' => [ 'mubix <mubix[at]hak5.org>' ] ,
19
19
'Platform' => [ 'windows' ] ,
20
20
'SessionTypes' => [ 'meterpreter' ]
21
21
) )
22
22
23
23
register_options (
24
24
[
25
- OptString . new ( 'HOSTNAME' , [ true , 'Hostname to lookup' , nil ] )
25
+ OptString . new ( 'HOSTNAME' , [ false , 'Hostname to lookup' , nil ] ) ,
26
+ OptPath . new ( 'HOSTFILE' , [ false , 'Line separated file with hostnames to resolve' , nil ] )
26
27
] , self . class )
27
28
end
28
29
29
- def run
30
- ### MAIN ###
30
+ def resolve_hostname ( hostname )
31
31
32
32
if client . platform =~ /^x64/
33
33
size = 64
@@ -37,14 +37,11 @@ def run
37
37
addrinfoinmem = 24
38
38
end
39
39
40
- hostname = datastore [ 'HOSTNAME' ]
41
-
42
- ## get IP for host
43
40
begin
44
41
vprint_status ( "Looking up IP for #{ hostname } " )
45
42
result = client . railgun . ws2_32 . getaddrinfo ( hostname , nil , nil , 4 )
46
43
if result [ 'GetLastError' ] == 11001
47
- print_error ( "Failed to resolve the host " )
44
+ print_error ( "Failed to resolve #{ hostname } " )
48
45
return
49
46
end
50
47
addrinfo = client . railgun . memread ( result [ 'ppResult' ] , size )
@@ -53,9 +50,23 @@ def run
53
50
ip = sockaddr [ 4 , 4 ] . unpack ( 'N' ) . first
54
51
hostip = Rex ::Socket . addr_itoa ( ip )
55
52
print_status ( "#{ hostname } resolves to #{ hostip } " )
56
- rescue ::Exception => e
57
- print_error ( e )
53
+ rescue Rex ::Post ::Meterpreter ::RequestError
58
54
print_status ( 'Windows 2000 and prior does not support getaddrinfo' )
59
55
end
56
+
57
+ end
58
+
59
+ def run
60
+ if datastore [ 'HOSTNAME' ]
61
+ resolve_hostname ( datastore [ 'HOSTNAME' ] )
62
+ end
63
+
64
+ if datastore [ 'HOSTFILE' ]
65
+ ::File . open ( datastore [ 'HOSTFILE' ] , "rb" ) . each_line do |hostname |
66
+ if hostname . strip != ""
67
+ resolve_hostname ( hostname . strip )
68
+ end
69
+ end
70
+ end
60
71
end
61
72
end
0 commit comments