metasploit-framework/modules/post/windows/gather/enum_domain_users.rb

93 lines
2.7 KiB
Ruby
Raw Normal View History

2013-07-15 20:02:46 +00:00
require 'msf/core'
require 'rex'
require 'msf/core/post/common'
require 'msf/core/post/windows/registry'
2013-09-02 19:24:54 +00:00
require 'msf/core/post/windows/netapi'
2013-07-15 20:02:46 +00:00
class Metasploit3 < Msf::Post
2013-09-05 19:30:08 +00:00
include Msf::Post::Common
include Msf::Post::Windows::Registry
include Msf::Post::Windows::NetAPI
2014-02-18 20:31:31 +00:00
include Msf::Post::Windows::Accounts
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
def initialize(info={})
super( update_info( info,
'Name' => 'Windows Gather Enumerate Active Domain Users',
'Description' => %q{
This module will enumerate computers included in the primary Domain and attempt
to list all locations the targeted user has sessions on. If a the HOST option is specified
the module will target only that host. If the HOST is specified and USER is set to nil, all users
logged into that host will be returned.'
},
'License' => MSF_LICENSE,
'Author' => [
'Etienne Stalmans <etienne[at]sensepost.com>',
'Ben Campbell'
],
2013-09-05 19:30:08 +00:00
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter' ]
))
register_options(
[
2014-02-18 20:31:31 +00:00
OptString.new('USER', [false, 'Target User for NetSessionEnum']),
OptString.new('HOST', [false, 'Target a specific host']),
2013-09-05 19:30:08 +00:00
], self.class)
end
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
def run
sessions = []
user = datastore['USER']
host = datastore['HOST']
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
if host
if user
print_status("Attempting to identify #{user} on #{host}...")
else
print_status("Attempting to get all logged in users on #{host}...")
end
sessions = net_session_enum(host, user)
elsif user
2014-02-18 23:30:29 +00:00
# Domain must be NETBIOS style rather than DNS style
2014-02-18 23:34:17 +00:00
domain = get_domain
2013-09-02 19:24:54 +00:00
2014-02-18 23:34:17 +00:00
if domain.blank?
fail_with(Failure::Unknown, "Machine is not part of a domain.")
else
domain = domain.split('.').first.upcase
2014-02-18 20:31:31 +00:00
print_status("Using domain: #{domain}")
print_status("Getting list of domain hosts...")
2013-09-05 19:30:08 +00:00
end
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
hosts = net_server_enum(SV_TYPE_ALL, domain)
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
if hosts
len = hosts.count
print_status("#{len} host(s) found")
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
hosts.each do |host|
sessions << net_session_enum(host[:name], user)
end
end
2013-09-02 20:57:11 +00:00
2013-09-05 19:30:08 +00:00
sessions.flatten!
else
2014-02-18 20:31:31 +00:00
fail_with(Failure::BadConfig, "Invalid options, either HOST or USER must be specified.")
2013-09-05 19:30:08 +00:00
end
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
if sessions.nil? or sessions.count == 0
2014-02-18 20:31:31 +00:00
fail_with(Failure::Unknown, "No sessions found")
2013-09-05 19:30:08 +00:00
else
print_status("#{sessions.count} session(s) identified")
2013-09-02 19:24:54 +00:00
2013-09-05 19:30:08 +00:00
sessions.each do |s|
if s
print_good("#{s[:username]} logged in at #{s[:hostname]} and has been idle for #{s[:idletime]} seconds")
end
end
end
end
2013-09-02 19:24:54 +00:00
end
2014-02-18 20:31:31 +00:00