CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/scripts/meterpreter/multiscript.rb
Views: 11766
1
##
2
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
3
# If you'd like to improve this script, please try to port it as a post
4
# module instead. Thank you.
5
##
6
7
8
9
#Meterpreter script for running multiple scripts on a Meterpreter Session
10
#Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
11
#Version: 0.2
12
################## Variable Declarations ##################
13
session = client
14
# Setting Argument
15
16
@@exec_opts = Rex::Parser::Arguments.new(
17
"-h" => [ false,"Help menu." ],
18
"-c" => [ true,"Collection of scripts to execute. Each script command must be enclosed in double quotes and separated by a semicolon."],
19
"-r" => [ true,"Text file with list of commands, one per line."]
20
)
21
#Setting Argument variables
22
commands = ""
23
script = []
24
help = 0
25
26
################## Function Declarations ##################
27
# Function for running a list of scripts stored in a array
28
def script_exec(session,scrptlst)
29
print_status("Running script List ...")
30
scrptlst.each_line do |scrpt|
31
next if scrpt.strip.length < 1
32
next if scrpt[0,1] == "#"
33
34
begin
35
script_components = scrpt.split
36
script = script_components.shift
37
script_args = script_components
38
print_status "\trunning script #{scrpt.chomp}"
39
session.execute_script(script, script_args)
40
rescue ::Exception => e
41
print_error("Error: #{e.class} #{e}")
42
print_error("Error in script: #{scrpt}")
43
end
44
end
45
end
46
47
def usage
48
print_line("Multi Script Execution Meterpreter Script ")
49
print_line(@@exec_opts.usage)
50
end
51
52
################## Main ##################
53
@@exec_opts.parse(args) do |opt, idx, val|
54
case opt
55
56
when "-c"
57
commands = val.gsub(/;/,"\n")
58
when "-r"
59
script = val
60
if not ::File.exist?(script)
61
raise "Script List File does not exist!"
62
else
63
::File.open(script, "rb").each_line do |line|
64
commands << line
65
end
66
end
67
when "-h"
68
help = 1
69
end
70
end
71
72
73
if args.length == 0 or help == 1
74
usage
75
else
76
print_status("Running Multiscript script.....")
77
script_exec(session,commands)
78
end
79
80