1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00
metasploit-framework/scripts/meterpreter/multiscript.rb
James Lee 1afbd3da5f print_status -> print_line in usage
git-svn-id: file:///home/svn/framework3/trunk@7361 4d416f70-5f16-0410-b530-b9f4589650da
2009-11-05 00:38:05 +00:00

67 lines
1.8 KiB
Ruby

# $Id$
#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
# Setting Argument
@@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
commands = ""
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 ...")
scrptlst.each_line do |scrpt|
begin
print_status "\trunning script #{scrpt.chomp}"
client = session
args = scrpt.chomp.split
session.execute_script(args.shift,binding)
rescue ::Exception => e
print_error("Error: #{e.class} #{e}")
print_error("Error in script: #{scrpt}")
end
end
end
def usage
print_line("Multi Script Execution Meterpreter Script ")
print_line(@@exec_opts.usage)
end
################## Main ##################
@@exec_opts.parse(args) do |opt, idx, val|
case opt
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
end
when "-h"
help = 1
end
end
if args.length == 0 or help == 1
usage
else
print_status("Running Multiscript script.....")
script_exec(session,commands)
end