Skip to content

Commit 35bb725

Browse files
author
Brent Cook
committed
rubocop fixes for payload dispatcher
1 parent cb0a798 commit 35bb725

File tree

1 file changed

+109
-116
lines changed

1 file changed

+109
-116
lines changed

lib/msf/ui/console/command_dispatcher/payload.rb

Lines changed: 109 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -6,90 +6,86 @@ module Msf
66
module Ui
77
module Console
88
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
6244

45+
def cmd_to_handler(*_args)
46+
handler = framework.modules.create('exploit/multi/handler')
6347

64-
end
48+
handler_opts = {
49+
'Payload' => mod.refname,
50+
'LocalInput' => driver.input,
51+
'LocalOutput' => driver.output,
52+
'ExitOnSession' => false,
53+
'RunAsJob' => true
54+
}
6555

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
7259

73-
#
74-
# Generates a payload.
75-
#
76-
def cmd_generate(*args)
60+
print_status "Payload Handler Started as Job #{job_id}"
61+
end
7762

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
9069

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
9389
when '-b'
9490
badchars = Rex::Text.hex_to_raw(val)
9591
when '-e'
@@ -114,51 +110,48 @@ def cmd_generate(*args)
114110
template = val
115111
when '-h'
116112
print(
117-
"Usage: generate [options]\n\n" +
113+
"Usage: generate [options]\n\n" \
118114
"Generates a payload.\n" +
119-
@@generate_opts.usage)
115+
@@generate_opts.usage
116+
)
120117
return true
118+
end
119+
end
120+
if encoder_name.nil? && mod.datastore['ENCODER']
121+
encoder_name = mod.datastore['ENCODER']
121122
end
122-
}
123-
if (encoder_name.nil? and mod.datastore['ENCODER'])
124-
encoder_name = mod.datastore['ENCODER']
125-
end
126-
127123

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
145142

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
154153
end
155-
156-
return true
157-
158154
end
159-
160-
end
161-
162155
end
163156
end
164157
end

0 commit comments

Comments
 (0)