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/multi_console_command.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 console commands on a meterpreter session
10
# Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
11
# Version: 0.1
12
#
13
14
################## Variable Declarations ##################
15
@client = client
16
17
# Setting Arguments
18
@@exec_opts = Rex::Parser::Arguments.new(
19
"-h" => [ false,"Help menu." ],
20
"-s" => [ false,"Hide commands output for work in background sessions"],
21
"-c" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],
22
"-r" => [ true,"Text file with list of commands, one per line."]
23
)
24
25
commands = nil
26
script = []
27
help = false
28
silence = false
29
30
def usage
31
print_line("Console Multi Command Execution Meterpreter Script ")
32
print_line(@@exec_opts.usage)
33
raise Rex::Script::Completed
34
end
35
36
@@exec_opts.parse(args) { |opt, idx, val|
37
case opt
38
39
when "-c"
40
commands = val.split(",")
41
when "-r"
42
script = val
43
if not ::File.exist?(script)
44
raise "Command List File does not exist!"
45
else
46
commands = []
47
::File.open(script, "r").each_line do |line|
48
commands << line.chomp
49
end
50
end
51
52
when "-h"
53
help = true
54
when "-s"
55
silence = true
56
end
57
}
58
59
if args.length == 0 or help or commands.nil?
60
usage
61
end
62
63
print_status("Running Command List ...")
64
65
commands.each do |cmd|
66
next if cmd.strip.length < 1
67
next if cmd[0,1] == "#"
68
begin
69
print_status "\tRunning command #{cmd}"
70
if silence
71
@client.console.disable_output = true
72
end
73
74
@client.console.run_single(cmd)
75
76
if silence
77
@client.console.disable_output = false
78
end
79
80
rescue ::Exception => e
81
print_status("Error Running Command #{cmd}: #{e.class} #{e}")
82
end
83
end
84
85