Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/enum_domain_users.rb
Views: 11655
##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)30)31register_options(32[33OptString.new('USER', [false, 'Target User for NetSessionEnum']),34OptString.new('HOST', [false, 'Target a specific host']),35]36)37end3839def run40sessions = []41user = datastore['USER']42host = datastore['HOST']4344if host45if user46print_status("Attempting to identify #{user} on #{host}...")47else48print_status("Attempting to get all logged in users on #{host}...")49end50sessions = net_session_enum(host, user)51elsif user52# Domain must be NETBIOS style rather than DNS style53domain = get_domain5455if domain.blank?56fail_with(Failure::Unknown, 'Machine is not part of a domain.')57else58domain = domain.split('.').first.upcase59print_status("Using domain: #{domain}")60print_status('Getting list of domain hosts...')61end6263hosts = net_server_enum(SV_TYPE_ALL, domain)6465if hosts66len = hosts.count67print_status("#{len} host(s) found")6869hosts.each do |host|70sessions << net_session_enum(host[:name], user)71end72end7374sessions.flatten!75else76fail_with(Failure::BadConfig, 'Invalid options, either HOST or USER must be specified.')77end7879if sessions.nil? || (sessions.count == 0)80fail_with(Failure::Unknown, 'No sessions found')81else82print_status("#{sessions.count} session(s) identified")8384sessions.each do |s|85if s86print_good("#{s[:username]} logged in at #{s[:hostname]} and has been idle for #{s[:idletime]} seconds")87end88end89end90end91end929394