Files
metasploit-gs/modules/post/windows/gather/enum_domain_users.rb
T

94 lines
2.8 KiB
Ruby
Raw Normal View History

2017-07-13 23:53:59 +01:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2017-07-13 23:53:59 +01:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2013-07-15 22:02:46 +02:00
require 'msf/core/post/common'
require 'msf/core/post/windows/registry'
2013-09-02 20:24:54 +01:00
require 'msf/core/post/windows/netapi'
2013-07-15 22:02:46 +02:00
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-09-05 14:30:08 -05: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 20:24:54 +01:00
2013-09-05 14:30:08 -05: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
2017-09-17 16:00:04 -04:00
to list all locations the targeted user has sessions on. If the HOST option is specified
2013-09-05 14:30:08 -05:00
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' => [
2014-02-22 12:24:56 +02:00
'Etienne Stalmans <etienne[at]sensepost.com>',
'Ben Campbell'
2014-02-22 12:24:56 +02:00
],
2013-09-05 14:30:08 -05: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 14:30:08 -05:00
end
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05:00
def run
sessions = []
user = datastore['USER']
host = datastore['HOST']
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05: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 20:24:54 +01: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 14:30:08 -05:00
end
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05:00
hosts = net_server_enum(SV_TYPE_ALL, domain)
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05:00
if hosts
len = hosts.count
print_status("#{len} host(s) found")
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05:00
hosts.each do |host|
sessions << net_session_enum(host[:name], user)
end
end
2013-09-02 21:57:11 +01:00
2013-09-05 14:30:08 -05: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 14:30:08 -05:00
end
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05: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 14:30:08 -05:00
else
print_status("#{sessions.count} session(s) identified")
2013-09-02 20:24:54 +01:00
2013-09-05 14:30:08 -05: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 20:24:54 +01:00
end
2014-02-18 20:31:31 +00:00