@@ -6,90 +6,86 @@ module Msf
6
6
module Ui
7
7
module Console
8
8
module CommandDispatcher
9
- ###
10
- #
11
- # Payload module command dispatcher.
12
- #
13
- ###
14
- class Payload
15
-
16
- include Msf ::Ui ::Console ::ModuleCommandDispatcher
17
-
18
- # Load supported formats
19
- supported_formats = Msf ::Simple ::Buffer . transform_formats + Msf ::Util ::EXE . to_executable_fmt_formats
20
-
21
- @@generate_opts = Rex ::Parser ::Arguments . new (
22
- "-b" => [ true , "The list of characters to avoid: '\\ x00\\ xff'" ] ,
23
- "-E" => [ false , "Force encoding." ] ,
24
- "-e" => [ true , "The name of the encoder module to use." ] ,
25
- "-h" => [ false , "Help banner." ] ,
26
- "-o" => [ true , "A comma separated list of options in VAR=VAL format." ] ,
27
- "-s" => [ true , "NOP sled length." ] ,
28
- "-f" => [ true , "The output file name (otherwise stdout)" ] ,
29
- "-t" => [ true , "The output format: #{ supported_formats . join ( ',' ) } " ] ,
30
- "-p" => [ true , "The Platform for output." ] ,
31
- "-k" => [ false , "Keep the template executable functional" ] ,
32
- "-x" => [ true , "The executable template to use" ] ,
33
- "-i" => [ true , "the number of encoding iterations." ] )
34
-
35
- #
36
- # Returns the hash of commands specific to payload modules.
37
- #
38
- def commands
39
- super . update ( {
40
- "generate" => "Generates a payload" ,
41
- "to_handler" => "Creates a handler with the specified payload"
42
- } )
43
- end
44
-
45
- def cmd_to_handler ( *args )
46
- handler = framework . modules . create ( 'exploit/multi/handler' )
47
-
48
- handler_opts = {
49
- 'Payload' => mod . refname , #mod.fullname,
50
- 'LocalInput' => driver . input ,
51
- 'LocalOutput' => driver . output ,
52
- 'ExitOnSession' => false ,
53
- 'RunAsJob' => true
54
- }
55
-
56
- #handler.datastore.reverse_merge!(mod.datastore)
57
- handler . datastore . merge! ( mod . datastore )
58
- handler . exploit_simple ( handler_opts )
59
- job_id = handler . job_id
60
-
61
- print_status "Payload Handler Started as Job #{ job_id } "
9
+ ###
10
+ # Payload module command dispatcher.
11
+ ###
12
+ class Payload
13
+ include Msf ::Ui ::Console ::ModuleCommandDispatcher
14
+
15
+ # Load supported formats
16
+ supported_formats = \
17
+ Msf ::Simple ::Buffer . transform_formats + \
18
+ Msf ::Util ::EXE . to_executable_fmt_formats
19
+
20
+ @@generate_opts = Rex ::Parser ::Arguments . new (
21
+ "-b" => [ true , "The list of characters to avoid: '\\ x00\\ xff'" ] ,
22
+ "-E" => [ false , "Force encoding." ] ,
23
+ "-e" => [ true , "The name of the encoder module to use." ] ,
24
+ "-h" => [ false , "Help banner." ] ,
25
+ "-o" => [ true , "A comma separated list of options in VAR=VAL format." ] ,
26
+ "-s" => [ true , "NOP sled length." ] ,
27
+ "-f" => [ true , "The output file name (otherwise stdout)" ] ,
28
+ "-t" => [ true , "The output format: #{ supported_formats . join ( ',' ) } " ] ,
29
+ "-p" => [ true , "The Platform for output." ] ,
30
+ "-k" => [ false , "Keep the template executable functional" ] ,
31
+ "-x" => [ true , "The executable template to use" ] ,
32
+ "-i" => [ true , "the number of encoding iterations." ]
33
+ )
34
+
35
+ #
36
+ # Returns the hash of commands specific to payload modules.
37
+ #
38
+ def commands
39
+ super . update (
40
+ "generate" => "Generates a payload" ,
41
+ "to_handler" => "Creates a handler with the specified payload"
42
+ )
43
+ end
62
44
45
+ def cmd_to_handler ( *_args )
46
+ handler = framework . modules . create ( 'exploit/multi/handler' )
63
47
64
- end
48
+ handler_opts = {
49
+ 'Payload' => mod . refname ,
50
+ 'LocalInput' => driver . input ,
51
+ 'LocalOutput' => driver . output ,
52
+ 'ExitOnSession' => false ,
53
+ 'RunAsJob' => true
54
+ }
65
55
66
- #
67
- # Returns the command dispatcher name.
68
- #
69
- def name
70
- return "Payload"
71
- end
56
+ handler . datastore . merge! ( mod . datastore )
57
+ handler . exploit_simple ( handler_opts )
58
+ job_id = handler . job_id
72
59
73
- #
74
- # Generates a payload.
75
- #
76
- def cmd_generate ( *args )
60
+ print_status "Payload Handler Started as Job #{ job_id } "
61
+ end
77
62
78
- # Parse the arguments
79
- encoder_name = nil
80
- sled_size = nil
81
- option_str = nil
82
- badchars = nil
83
- type = "ruby"
84
- ofile = nil
85
- iter = 1
86
- force = nil
87
- template = nil
88
- plat = nil
89
- keep = false
63
+ #
64
+ # Returns the command dispatcher name.
65
+ #
66
+ def name
67
+ "Payload"
68
+ end
90
69
91
- @@generate_opts . parse ( args ) { |opt , idx , val |
92
- case opt
70
+ #
71
+ # Generates a payload.
72
+ #
73
+ def cmd_generate ( *args )
74
+ # Parse the arguments
75
+ encoder_name = nil
76
+ sled_size = nil
77
+ option_str = nil
78
+ badchars = nil
79
+ type = "ruby"
80
+ ofile = nil
81
+ iter = 1
82
+ force = nil
83
+ template = nil
84
+ plat = nil
85
+ keep = false
86
+
87
+ @@generate_opts . parse ( args ) do |opt , _idx , val |
88
+ case opt
93
89
when '-b'
94
90
badchars = Rex ::Text . hex_to_raw ( val )
95
91
when '-e'
@@ -114,51 +110,48 @@ def cmd_generate(*args)
114
110
template = val
115
111
when '-h'
116
112
print (
117
- "Usage: generate [options]\n \n " +
113
+ "Usage: generate [options]\n \n " \
118
114
"Generates a payload.\n " +
119
- @@generate_opts . usage )
115
+ @@generate_opts . usage
116
+ )
120
117
return true
118
+ end
119
+ end
120
+ if encoder_name . nil? && mod . datastore [ 'ENCODER' ]
121
+ encoder_name = mod . datastore [ 'ENCODER' ]
121
122
end
122
- }
123
- if ( encoder_name . nil? and mod . datastore [ 'ENCODER' ] )
124
- encoder_name = mod . datastore [ 'ENCODER' ]
125
- end
126
-
127
123
128
- # Generate the payload
129
- begin
130
- buf = mod . generate_simple (
131
- 'BadChars' => badchars ,
132
- 'Encoder' => encoder_name ,
133
- 'Format' => type ,
134
- 'NopSledSize' => sled_size ,
135
- 'OptionStr' => option_str ,
136
- 'ForceEncode' => force ,
137
- 'Template' => template ,
138
- 'Platform' => plat ,
139
- 'KeepTemplateWorking' => keep ,
140
- 'Iterations' => iter )
141
- rescue
142
- log_error ( "Payload generation failed: #{ $!} " )
143
- return false
144
- end
124
+ # Generate the payload
125
+ begin
126
+ buf = mod . generate_simple (
127
+ 'BadChars' => badchars ,
128
+ 'Encoder' => encoder_name ,
129
+ 'Format' => type ,
130
+ 'NopSledSize' => sled_size ,
131
+ 'OptionStr' => option_str ,
132
+ 'ForceEncode' => force ,
133
+ 'Template' => template ,
134
+ 'Platform' => plat ,
135
+ 'KeepTemplateWorking' => keep ,
136
+ 'Iterations' => iter
137
+ )
138
+ rescue
139
+ log_error ( "Payload generation failed: #{ $ERROR_INFO} " )
140
+ return false
141
+ end
145
142
146
- if ( not ofile )
147
- # Display generated payload
148
- print ( buf )
149
- else
150
- print_status ( "Writing #{ buf . length } bytes to #{ ofile } ..." )
151
- fd = File . open ( ofile , "wb" )
152
- fd . write ( buf )
153
- fd . close
143
+ if !ofile
144
+ # Display generated payload
145
+ print ( buf )
146
+ else
147
+ print_status ( "Writing #{ buf . length } bytes to #{ ofile } ..." )
148
+ fd = File . open ( ofile , "wb" )
149
+ fd . write ( buf )
150
+ fd . close
151
+ end
152
+ true
154
153
end
155
-
156
- return true
157
-
158
154
end
159
-
160
- end
161
-
162
155
end
163
156
end
164
157
end
0 commit comments