2010-05-03 17:13:09 +00:00
|
|
|
#
|
|
|
|
# Meterpreter script for running multiple console commands on a meterpreter session
|
|
|
|
# Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
|
|
|
|
# Verion: 0.1
|
|
|
|
#
|
|
|
|
|
2010-04-24 14:52:54 +00:00
|
|
|
################## Variable Declarations ##################
|
2010-06-13 01:20:58 +00:00
|
|
|
@client = client
|
2010-05-03 17:13:09 +00:00
|
|
|
|
2010-04-24 14:52:54 +00:00
|
|
|
# Setting Arguments
|
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
2013-09-30 18:47:53 +00:00
|
|
|
"-h" => [ false,"Help menu." ],
|
|
|
|
"-cl" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],
|
|
|
|
"-rc" => [ true,"Text file with list of commands, one per line."]
|
2010-04-24 14:52:54 +00:00
|
|
|
)
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-04-24 14:52:54 +00:00
|
|
|
#Setting Argument variables
|
|
|
|
commands = []
|
|
|
|
script = []
|
|
|
|
help = 0
|
|
|
|
|
|
|
|
################## Function Declarations ##################
|
|
|
|
# Function for running a list of commands stored in a array, returs string
|
2010-06-13 01:20:58 +00:00
|
|
|
def list_con_exec(cmdlst)
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Running Command List ...")
|
|
|
|
cmdout = ""
|
|
|
|
cmdlst.each do |cmd|
|
|
|
|
next if cmd.strip.length < 1
|
|
|
|
next if cmd[0,1] == "#"
|
|
|
|
begin
|
|
|
|
print_status "\tRunning command #{cmd}"
|
|
|
|
@client.console.run_single(cmd)
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error Running Command #{cmd}: #{e.class} #{e}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cmdout
|
2010-04-24 14:52:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def usage
|
2013-09-30 18:47:53 +00:00
|
|
|
print_line("Console Multi Command Execution Meterpreter Script ")
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
2010-04-24 14:52:54 +00:00
|
|
|
end
|
|
|
|
################## Main ##################
|
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
2013-09-30 18:47:53 +00:00
|
|
|
case opt
|
2013-09-17 15:42:58 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
when "-cl"
|
|
|
|
commands = val.split(",")
|
|
|
|
when "-rc"
|
|
|
|
script = val
|
|
|
|
if not ::File.exists?(script)
|
|
|
|
raise "Command List File does not exists!"
|
|
|
|
else
|
|
|
|
::File.open(script, "r").each_line do |line|
|
|
|
|
commands << line.chomp
|
|
|
|
end
|
|
|
|
end
|
2013-09-17 15:42:58 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
when "-h"
|
|
|
|
help = 1
|
|
|
|
end
|
2010-04-24 14:52:54 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 02:43:07 +00:00
|
|
|
if args.length == 0 or help == 1
|
2013-09-30 18:47:53 +00:00
|
|
|
usage
|
2010-04-24 14:52:54 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
list_con_exec(commands)
|
|
|
|
raise Rex::Script::Completed
|
2010-04-24 14:52:54 +00:00
|
|
|
end
|
2010-06-06 02:43:07 +00:00
|
|
|
|