2014-09-16 23:41:14 +02:00
|
|
|
##
|
|
|
|
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
|
2018-02-13 12:30:05 +01:00
|
|
|
# If you'd like to improve this script, please try to port it as a post
|
2014-09-16 23:41:14 +02:00
|
|
|
# module instead. Thank you.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
2010-05-03 19:13:09 +02:00
|
|
|
#
|
|
|
|
# Meterpreter script for running multiple console commands on a meterpreter session
|
|
|
|
# Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
|
2024-01-07 19:20:40 +01:00
|
|
|
# Version: 0.1
|
2010-05-03 19:13:09 +02:00
|
|
|
#
|
|
|
|
|
2010-04-24 16:52:54 +02:00
|
|
|
################## Variable Declarations ##################
|
2010-06-13 03:20:58 +02:00
|
|
|
@client = client
|
2010-05-03 19:13:09 +02:00
|
|
|
|
2010-04-24 16:52:54 +02:00
|
|
|
# Setting Arguments
|
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
2013-09-30 20:47:53 +02:00
|
|
|
"-h" => [ false,"Help menu." ],
|
2017-08-07 00:46:05 +02:00
|
|
|
"-s" => [ false,"Hide commands output for work in background sessions"],
|
|
|
|
"-c" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],
|
|
|
|
"-r" => [ true,"Text file with list of commands, one per line."]
|
2010-04-24 16:52:54 +02:00
|
|
|
)
|
2011-10-23 13:56:13 +02:00
|
|
|
|
2013-11-22 03:47:04 +01:00
|
|
|
commands = nil
|
2010-04-24 16:52:54 +02:00
|
|
|
script = []
|
2017-01-12 04:06:34 +01:00
|
|
|
help = false
|
|
|
|
silence = false
|
2010-04-24 16:52:54 +02:00
|
|
|
|
|
|
|
def usage
|
2013-09-30 20:47:53 +02:00
|
|
|
print_line("Console Multi Command Execution Meterpreter Script ")
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
2010-04-24 16:52:54 +02:00
|
|
|
end
|
2017-01-12 04:06:34 +01:00
|
|
|
|
2010-04-24 16:52:54 +02:00
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
2013-09-30 20:47:53 +02:00
|
|
|
case opt
|
2013-09-17 17:42:58 +02:00
|
|
|
|
2017-08-07 00:46:05 +02:00
|
|
|
when "-c"
|
2013-09-30 20:47:53 +02:00
|
|
|
commands = val.split(",")
|
2017-08-07 00:46:05 +02:00
|
|
|
when "-r"
|
2013-09-30 20:47:53 +02:00
|
|
|
script = val
|
2016-04-20 14:11:34 +02:00
|
|
|
if not ::File.exist?(script)
|
2020-12-23 04:36:38 +01:00
|
|
|
raise "Command List File does not exist!"
|
2013-09-30 20:47:53 +02:00
|
|
|
else
|
2013-11-22 03:47:04 +01:00
|
|
|
commands = []
|
2013-09-30 20:47:53 +02:00
|
|
|
::File.open(script, "r").each_line do |line|
|
|
|
|
commands << line.chomp
|
|
|
|
end
|
|
|
|
end
|
2013-09-17 17:42:58 +02:00
|
|
|
|
2013-09-30 20:47:53 +02:00
|
|
|
when "-h"
|
2017-01-12 04:06:34 +01:00
|
|
|
help = true
|
2017-08-07 00:46:05 +02:00
|
|
|
when "-s"
|
2017-01-12 04:06:34 +01:00
|
|
|
silence = true
|
2013-09-30 20:47:53 +02:00
|
|
|
end
|
2010-04-24 16:52:54 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 04:06:34 +01:00
|
|
|
if args.length == 0 or help or commands.nil?
|
2013-09-30 20:47:53 +02:00
|
|
|
usage
|
2010-04-24 16:52:54 +02:00
|
|
|
end
|
2010-06-06 04:43:07 +02:00
|
|
|
|
2017-01-12 04:06:34 +01:00
|
|
|
print_status("Running Command List ...")
|
|
|
|
|
|
|
|
commands.each do |cmd|
|
|
|
|
next if cmd.strip.length < 1
|
|
|
|
next if cmd[0,1] == "#"
|
|
|
|
begin
|
|
|
|
print_status "\tRunning command #{cmd}"
|
|
|
|
if silence
|
|
|
|
@client.console.disable_output = true
|
|
|
|
end
|
|
|
|
|
|
|
|
@client.console.run_single(cmd)
|
|
|
|
|
|
|
|
if silence
|
|
|
|
@client.console.disable_output = false
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error Running Command #{cmd}: #{e.class} #{e}")
|
|
|
|
end
|
|
|
|
end
|