2009-10-26 15:14:28 +00:00
|
|
|
# $Id$
|
2009-07-25 02:35:35 +00:00
|
|
|
#Meterpreter script for running multiple scripts on a Meterpreter Session
|
|
|
|
#Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
|
2009-10-02 00:46:05 +00:00
|
|
|
#Verion: 0.2
|
2009-07-25 02:35:35 +00:00
|
|
|
################## Variable Declarations ##################
|
|
|
|
session = client
|
2010-05-03 17:13:09 +00:00
|
|
|
# Setting Argument
|
2009-10-02 00:46:05 +00:00
|
|
|
|
2009-07-25 02:35:35 +00:00
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
|
|
|
"-h" => [ false,"Help menu." ],
|
|
|
|
"-c" => [ true,"Collection of scripts to execute. Each script command must be enclosed in double quotes and separated by a semicolon."],
|
|
|
|
"-s" => [ true,"Text file with list of commands, one per line."]
|
|
|
|
)
|
|
|
|
#Setting Argument variables
|
2009-10-02 01:10:22 +00:00
|
|
|
commands = ""
|
2009-07-25 02:35:35 +00:00
|
|
|
script = []
|
|
|
|
help = 0
|
|
|
|
|
|
|
|
################## Function Declarations ##################
|
|
|
|
# Function for running a list of scripts stored in a array
|
|
|
|
def script_exec(session,scrptlst)
|
|
|
|
print_status("Running script List ...")
|
2009-10-02 01:10:22 +00:00
|
|
|
scrptlst.each_line do |scrpt|
|
2009-07-25 02:35:35 +00:00
|
|
|
begin
|
2010-04-24 13:22:49 +00:00
|
|
|
script_components = scrpt.split
|
2010-03-08 03:15:57 +00:00
|
|
|
script = script_components.shift
|
2010-04-24 13:22:49 +00:00
|
|
|
script_args = script_components
|
2009-10-02 10:51:52 +00:00
|
|
|
print_status "\trunning script #{scrpt.chomp}"
|
2010-04-24 13:22:49 +00:00
|
|
|
session.execute_script(script, script_args)
|
2009-07-25 02:35:35 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("Error: #{e.class} #{e}")
|
|
|
|
print_error("Error in script: #{scrpt}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage
|
2009-10-25 20:57:23 +00:00
|
|
|
print_line("Multi Script Execution Meterpreter Script ")
|
2009-11-05 00:38:05 +00:00
|
|
|
print_line(@@exec_opts.usage)
|
2009-07-25 02:35:35 +00:00
|
|
|
end
|
2009-10-25 20:57:23 +00:00
|
|
|
|
2009-07-25 02:35:35 +00:00
|
|
|
################## Main ##################
|
2009-10-25 20:57:23 +00:00
|
|
|
@@exec_opts.parse(args) do |opt, idx, val|
|
2010-03-08 03:15:57 +00:00
|
|
|
case opt
|
2009-07-25 02:35:35 +00:00
|
|
|
|
2010-03-08 03:15:57 +00:00
|
|
|
when "-c"
|
|
|
|
commands = val.gsub(/;/,"\n")
|
|
|
|
when "-s"
|
|
|
|
script = val
|
|
|
|
if not ::File.exists?(script)
|
|
|
|
raise "Script List File does not exists!"
|
|
|
|
else
|
|
|
|
::File.open(script, "r").each_line do |line|
|
|
|
|
commands << line
|
|
|
|
end
|
2009-10-25 20:57:23 +00:00
|
|
|
end
|
2010-03-08 03:15:57 +00:00
|
|
|
when "-h"
|
|
|
|
help = 1
|
2009-10-25 20:57:23 +00:00
|
|
|
end
|
|
|
|
end
|
2009-07-25 02:35:35 +00:00
|
|
|
|
2010-05-03 17:13:09 +00:00
|
|
|
if args.length == 0 or help == 1
|
2009-10-25 20:57:23 +00:00
|
|
|
usage
|
2009-07-25 02:35:35 +00:00
|
|
|
else
|
2009-10-25 20:57:23 +00:00
|
|
|
print_status("Running Multiscript script.....")
|
|
|
|
script_exec(session,commands)
|
2009-07-25 02:35:35 +00:00
|
|
|
end
|