2011-11-03 03:00:51 +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-11-03 03:00:51 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2012-02-20 19:49:23 +00:00
|
|
|
'Name' => 'Windows Gather Domain Enumeration',
|
2011-11-04 08:16:36 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module enumerates currently the domains a host can see and the domain
|
2011-11-20 01:53:25 +00:00
|
|
|
controllers for that domain.
|
2011-11-04 08:16:36 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2012-10-22 21:01:58 +00:00
|
|
|
'Author' => [ 'mubix' ],
|
2012-10-23 18:33:01 +00:00
|
|
|
'Platform' => [ 'win' ],
|
2011-11-04 08:16:36 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
2011-11-03 03:00:51 +00:00
|
|
|
end
|
2011-11-06 22:02:26 +00:00
|
|
|
|
2011-11-03 03:00:51 +00:00
|
|
|
def run
|
|
|
|
|
|
|
|
domain_enum = 2147483648 # SV_TYPE_DOMAIN_ENUM = hex 80000000
|
|
|
|
buffersize = 500
|
|
|
|
result = client.railgun.netapi32.NetServerEnum(nil,100,4,buffersize,4,4,domain_enum,nil,nil)
|
|
|
|
print_status("Finding the right buffersize...")
|
|
|
|
while result['return'] == 234
|
|
|
|
print_status("Tested #{buffersize}, got #{result['entriesread']} of #{result['totalentries']}")
|
|
|
|
buffersize = buffersize + 500
|
|
|
|
result = client.railgun.netapi32.NetServerEnum(nil,100,4,buffersize,4,4,domain_enum,nil,nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
count = result['totalentries']
|
|
|
|
print_status("#{count} domain(s) found.")
|
|
|
|
startmem = result['bufptr']
|
|
|
|
|
|
|
|
base = 0
|
|
|
|
domains = []
|
|
|
|
mem = client.railgun.memread(startmem, 8*count)
|
|
|
|
count.times{|i|
|
|
|
|
x = {}
|
|
|
|
x[:platform] = mem[(base + 0),4].unpack("V*")[0]
|
|
|
|
nameptr = mem[(base + 4),4].unpack("V*")[0]
|
|
|
|
x[:domain] = client.railgun.memread(nameptr,255).split("\0\0")[0].split("\0").join
|
|
|
|
domains << x
|
|
|
|
base = base + 8
|
|
|
|
}
|
|
|
|
|
2011-11-20 01:53:25 +00:00
|
|
|
domaincontrollers = 24 # 10 + 8 (SV_TYPE_DOMAIN_BAKCTRL || SV_TYPE_DOMAIN_CTRL)
|
2011-11-03 03:00:51 +00:00
|
|
|
|
|
|
|
domains.each do |x|
|
|
|
|
print_status("Enumerating DCs for #{x[:domain]}")
|
|
|
|
result = client.railgun.netapi32.NetServerEnum(nil,100,4,buffersize,4,4,domaincontrollers,x[:domain],nil)
|
|
|
|
while result['return'] == 234
|
|
|
|
buffersize = buffersize + 500
|
|
|
|
result = client.railgun.netapi32.NetServerEnum(nil,100,4,buffersize,4,4,domaincontrollers,x[:domain],nil)
|
|
|
|
end
|
|
|
|
if result['totalentries'] == 0
|
|
|
|
print_error("No Domain Controllers found...")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
count = result['totalentries']
|
|
|
|
startmem = result['bufptr']
|
|
|
|
|
|
|
|
base = 0
|
|
|
|
x[:dc] = []
|
|
|
|
mem = client.railgun.memread(startmem, 8*count)
|
|
|
|
count.times{|i|
|
|
|
|
t = {}
|
|
|
|
t[:platform] = mem[(base + 0),4].unpack("V*")[0]
|
|
|
|
nameptr = mem[(base + 4),4].unpack("V*")[0]
|
|
|
|
t[:dc_hostname] = client.railgun.memread(nameptr,255).split("\0\0")[0].split("\0").join
|
|
|
|
x[:dc] << t
|
|
|
|
base = base + 8
|
|
|
|
print_status(t[:dc_hostname])
|
2011-11-10 08:16:25 +00:00
|
|
|
|
|
|
|
report_note(
|
|
|
|
:host => session,
|
|
|
|
:type => 'domain.hostnames',
|
|
|
|
:data => t[:dc_hostname],
|
|
|
|
:update => :unique_data
|
|
|
|
)
|
2011-11-03 03:00:51 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|