Files
metasploit-gs/scripts/meterpreter/multiscript.rb
T

79 lines
2.0 KiB
Ruby
Raw Normal View History

##
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
# If you'd like to imporve this script, please try to port it as a post
# module instead. Thank you.
##
#Meterpreter script for running multiple scripts on a Meterpreter Session
#Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
#Verion: 0.2
################## Variable Declarations ##################
session = client
2010-05-03 17:13:09 +00:00
# Setting Argument
@@exec_opts = Rex::Parser::Arguments.new(
2013-09-30 13:47:53 -05:00
"-h" => [ false,"Help menu." ],
2017-08-06 17:58:13 -05:00
"-c" => [ true,"Collection of scripts to execute. Each script command must be enclosed in double quotes and separated by a semicolon."],
"-r" => [ true,"Text file with list of commands, one per line."]
)
#Setting Argument variables
commands = ""
script = []
help = 0
################## Function Declarations ##################
# Function for running a list of scripts stored in a array
def script_exec(session,scrptlst)
2013-09-30 13:47:53 -05:00
print_status("Running script List ...")
scrptlst.each_line do |scrpt|
next if scrpt.strip.length < 1
next if scrpt[0,1] == "#"
2010-10-08 18:35:43 +00:00
2013-09-30 13:47:53 -05:00
begin
script_components = scrpt.split
script = script_components.shift
script_args = script_components
print_status "\trunning script #{scrpt.chomp}"
session.execute_script(script, script_args)
rescue ::Exception => e
print_error("Error: #{e.class} #{e}")
print_error("Error in script: #{scrpt}")
end
end
end
def usage
2013-09-30 13:47:53 -05:00
print_line("Multi Script Execution Meterpreter Script ")
print_line(@@exec_opts.usage)
end
################## Main ##################
@@exec_opts.parse(args) do |opt, idx, val|
2013-09-30 13:47:53 -05:00
case opt
2017-08-06 17:58:13 -05:00
when "-c"
2013-09-30 13:47:53 -05:00
commands = val.gsub(/;/,"\n")
2017-08-06 17:58:13 -05:00
when "-r"
2013-09-30 13:47:53 -05:00
script = val
2016-04-20 08:11:34 -04:00
if not ::File.exist?(script)
2013-09-30 13:47:53 -05:00
raise "Script List File does not exists!"
else
::File.open(script, "rb").each_line do |line|
commands << line
end
end
when "-h"
help = 1
end
end
2010-10-08 18:35:43 +00:00
2010-05-03 17:13:09 +00:00
if args.length == 0 or help == 1
2013-09-30 13:47:53 -05:00
usage
else
2013-09-30 13:47:53 -05:00
print_status("Running Multiscript script.....")
script_exec(session,commands)
end