22
22
"-rc" => [ true , "Text file with list of commands, one per line." ]
23
23
)
24
24
25
- #Setting Argument variables
26
25
commands = nil
27
26
script = [ ]
28
- help = 0
29
- silence = 0
30
-
31
- ################## Function Declarations ##################
32
- # Function for running a list of commands stored in a array, returs string
33
- def list_con_exec ( cmdlst , silence )
34
- print_status ( "Running Command List ..." )
35
- cmdout = ""
36
- cmdlst . each do |cmd |
37
- next if cmd . strip . length < 1
38
- next if cmd [ 0 , 1 ] == "#"
39
- begin
40
- print_status "\t Running command #{ cmd } "
41
- if silence == 1
42
- @client . console . disable_output = true
43
- end
44
-
45
- @client . console . run_single ( cmd )
46
-
47
- if silence == 1
48
- @client . console . disable_output = false
49
- end
50
-
51
- rescue ::Exception => e
52
- print_status ( "Error Running Command #{ cmd } : #{ e . class } #{ e } " )
53
- end
54
- end
55
- cmdout
56
- end
57
-
27
+ help = false
28
+ silence = false
58
29
59
30
def usage
60
31
print_line ( "Console Multi Command Execution Meterpreter Script " )
61
32
print_line ( @@exec_opts . usage )
62
33
raise Rex ::Script ::Completed
63
34
end
64
- ################## Main ##################
35
+
65
36
@@exec_opts . parse ( args ) { |opt , idx , val |
66
37
case opt
67
38
@@ -79,16 +50,34 @@ def usage
79
50
end
80
51
81
52
when "-h"
82
- help = 1
53
+ help = true
83
54
when "-sl"
84
- silence = 1
55
+ silence = true
85
56
end
86
57
}
87
58
88
- if args . length == 0 or help == 1 or commands . nil?
59
+ if args . length == 0 or help or commands . nil?
89
60
usage
90
- else
91
- list_con_exec ( commands , silence )
92
- raise Rex ::Script ::Completed
93
61
end
94
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