Path: blob/master/modules/post/windows/gather/enum_domain_users.rb
19534 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Common7include Msf::Post::Windows::Registry8include Msf::Post::Windows::NetAPI9include Msf::Post::Windows::Accounts1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Windows Gather Enumerate Active Domain Users',16'Description' => %q{17This module will enumerate computers included in the primary Domain and attempt18to list all locations the targeted user has sessions on. If the HOST option is specified19the module will target only that host. If the HOST is specified and USER is set to nil, all users20logged into that host will be returned.'21},22'License' => MSF_LICENSE,23'Author' => [24'Etienne Stalmans <etienne[at]sensepost.com>',25'Ben Campbell'26],27'Platform' => [ 'win' ],28'SessionTypes' => [ 'meterpreter' ],29'Notes' => {30'Stability' => [CRASH_SAFE],31'SideEffects' => [],32'Reliability' => []33}34)35)36register_options(37[38OptString.new('USER', [false, 'Target User for NetSessionEnum']),39OptString.new('HOST', [false, 'Target a specific host']),40]41)42end4344def run45sessions = []46user = datastore['USER']47host = datastore['HOST']4849if host50if user51print_status("Attempting to identify #{user} on #{host}...")52else53print_status("Attempting to get all logged in users on #{host}...")54end55sessions = net_session_enum(host, user)56elsif user57# Domain must be NETBIOS style rather than DNS style58domain = get_domain5960if domain.blank?61fail_with(Failure::Unknown, 'Machine is not part of a domain.')62else63domain = domain.split('.').first.upcase64print_status("Using domain: #{domain}")65print_status('Getting list of domain hosts...')66end6768hosts = net_server_enum(SV_TYPE_ALL, domain)6970if hosts71len = hosts.count72print_status("#{len} host(s) found")7374hosts.each do |host|75sessions << net_session_enum(host[:name], user)76end77end7879sessions.flatten!80else81fail_with(Failure::BadConfig, 'Invalid options, either HOST or USER must be specified.')82end8384if sessions.nil? || (sessions.count == 0)85fail_with(Failure::Unknown, 'No sessions found')86else87print_status("#{sessions.count} session(s) identified")8889sessions.each do |s|90if s91print_good("#{s[:username]} logged in at #{s[:hostname]} and has been idle for #{s[:idletime]} seconds")92end93end94end95end96end979899