17
17
# Setting Arguments
18
18
@@exec_opts = Rex ::Parser ::Arguments . new (
19
19
"-h" => [ false , "Help menu." ] ,
20
+ "-sl" => [ false , "Hide commands output for work in background sessions" ] ,
20
21
"-cl" => [ true , "Commands to execute. The command must be enclosed in double quotes and separated by a comma." ] ,
21
22
"-rc" => [ true , "Text file with list of commands, one per line." ]
22
23
)
23
24
24
- #Setting Argument variables
25
25
commands = nil
26
26
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 "\t Running 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
47
29
48
30
def usage
49
31
print_line ( "Console Multi Command Execution Meterpreter Script " )
50
32
print_line ( @@exec_opts . usage )
51
33
raise Rex ::Script ::Completed
52
34
end
53
- ################## Main ##################
35
+
54
36
@@exec_opts . parse ( args ) { |opt , idx , val |
55
37
case opt
56
38
@@ -68,14 +50,34 @@ def usage
68
50
end
69
51
70
52
when "-h"
71
- help = 1
53
+ help = true
54
+ when "-sl"
55
+ silence = true
72
56
end
73
57
}
74
58
75
- if args . length == 0 or help == 1 or commands . nil?
59
+ if args . length == 0 or help or commands . nil?
76
60
usage
77
- else
78
- list_con_exec ( commands )
79
- raise Rex ::Script ::Completed
80
61
end
81
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 "\t Running 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