2011-03-22 22:59:01 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-03-22 22:59:01 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Post
|
2011-03-22 22:59:01 +00:00
|
|
|
|
2023-02-08 13:47:34 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'Multi Gather Run Shell Command Resource File',
|
|
|
|
|
'Description' => %q{
|
|
|
|
|
This module will read shell commands from a resource file and
|
|
|
|
|
execute the commands in the specified Meterpreter or shell session.
|
|
|
|
|
},
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
|
'Platform' => %w[bsd linux osx unix win],
|
|
|
|
|
'SessionTypes' => ['meterpreter']
|
|
|
|
|
)
|
|
|
|
|
)
|
2013-09-05 13:41:25 -05:00
|
|
|
register_options(
|
|
|
|
|
[
|
|
|
|
|
OptString.new('RESOURCE', [true, 'Full path to resource file to read commands from.', nil])
|
2011-03-22 22:59:01 +00:00
|
|
|
|
2023-02-08 13:47:34 +00:00
|
|
|
]
|
|
|
|
|
)
|
2011-03-22 22:59:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
|
def run
|
|
|
|
|
print_status("Running module against #{sysinfo['Computer']}")
|
2023-02-08 13:47:34 +00:00
|
|
|
if !::File.exist?(datastore['RESOURCE'])
|
|
|
|
|
raise 'Resource File does not exist!'
|
2011-06-10 03:36:48 +00:00
|
|
|
else
|
2023-02-08 13:47:34 +00:00
|
|
|
::File.open(datastore['RESOURCE'], 'rb').each_line do |cmd|
|
|
|
|
|
next if cmd.strip.empty?
|
|
|
|
|
next if cmd[0, 1] == '#'
|
|
|
|
|
|
2011-03-22 22:59:01 +00:00
|
|
|
begin
|
|
|
|
|
tmpout = "\n"
|
|
|
|
|
tmpout << "*****************************************\n"
|
|
|
|
|
tmpout << " Output of #{cmd}\n"
|
|
|
|
|
tmpout << "*****************************************\n"
|
|
|
|
|
print_status "Running command #{cmd.chomp}"
|
2015-06-29 11:36:28 -05:00
|
|
|
tmpout << cmd_exec(cmd.chomp)
|
2011-07-15 15:33:35 +00:00
|
|
|
vprint_status tmpout
|
2023-02-08 13:47:34 +00:00
|
|
|
command_log = store_loot('host.command', 'text/plain', session, tmpout,
|
|
|
|
|
"#{cmd.gsub(%r{\.|/|\s}, '_')}.txt", "Command Output \'#{cmd.chomp}\'")
|
2017-07-19 13:02:49 +01:00
|
|
|
print_good("Command output saved to: #{command_log}")
|
2011-03-22 22:59:01 +00:00
|
|
|
rescue ::Exception => e
|
2017-07-19 13:02:49 +01:00
|
|
|
print_bad("Error Running Command #{cmd.chomp}: #{e.class} #{e}")
|
2011-03-22 22:59:01 +00:00
|
|
|
end
|
2011-06-10 03:36:48 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-03-22 22:59:01 +00:00
|
|
|
end
|
2011-07-15 15:33:35 +00:00
|
|
|
end
|