Skip to content

Commit fd1c5fb

Browse files
author
Brent Cook
committed
Land rapid7#7763, add -sl to multi_console_command to run silently
2 parents 899ff35 + 0af363d commit fd1c5fb

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

scripts/meterpreter/multi_console_command.rb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,22 @@
1717
# Setting Arguments
1818
@@exec_opts = Rex::Parser::Arguments.new(
1919
"-h" => [ false,"Help menu." ],
20+
"-sl" => [ false,"Hide commands output for work in background sessions"],
2021
"-cl" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],
2122
"-rc" => [ true,"Text file with list of commands, one per line."]
2223
)
2324

24-
#Setting Argument variables
2525
commands = nil
2626
script = []
27-
help = 0
28-
29-
################## Function Declarations ##################
30-
# Function for running a list of commands stored in a array, returs string
31-
def list_con_exec(cmdlst)
32-
print_status("Running Command List ...")
33-
cmdout = ""
34-
cmdlst.each do |cmd|
35-
next if cmd.strip.length < 1
36-
next if cmd[0,1] == "#"
37-
begin
38-
print_status "\tRunning command #{cmd}"
39-
@client.console.run_single(cmd)
40-
rescue ::Exception => e
41-
print_status("Error Running Command #{cmd}: #{e.class} #{e}")
42-
end
43-
end
44-
cmdout
45-
end
46-
27+
help = false
28+
silence = false
4729

4830
def usage
4931
print_line("Console Multi Command Execution Meterpreter Script ")
5032
print_line(@@exec_opts.usage)
5133
raise Rex::Script::Completed
5234
end
53-
################## Main ##################
35+
5436
@@exec_opts.parse(args) { |opt, idx, val|
5537
case opt
5638

@@ -68,14 +50,34 @@ def usage
6850
end
6951

7052
when "-h"
71-
help = 1
53+
help = true
54+
when "-sl"
55+
silence = true
7256
end
7357
}
7458

75-
if args.length == 0 or help == 1 or commands.nil?
59+
if args.length == 0 or help or commands.nil?
7660
usage
77-
else
78-
list_con_exec(commands)
79-
raise Rex::Script::Completed
8061
end
8162

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

0 commit comments

Comments
 (0)