Skip to content

Commit c2bc182

Browse files
committed
Fix rapid7#4430 - Add support for -o to save the payload to disk
Fix rapid7#4430
1 parent 337b2d7 commit c2bc182

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

msfvenom

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,14 @@ require 'msf/core/payload_generator'
117117
opts[:keep] = true
118118
end
119119

120-
opt.on('-o', '--options', "List the payload's standard options") do
120+
opt.on('--payload-options', "List the payload's standard options") do
121121
opts[:list_options] = true
122122
end
123123

124+
opt.on('-o', '--out <path>', 'Save the payload') do |x|
125+
opts[:out] = x
126+
end
127+
124128
opt.on('-v', '--var-name <name>', String, 'Specify a custom variable name to use for certain output formats') do |x|
125129
opts[:var_name] = x
126130
end
@@ -308,8 +312,21 @@ if __FILE__ == $0
308312
$stderr.puts e.message
309313
end
310314

311-
output_stream = $stdout
312-
output_stream.binmode
313-
output_stream.write payload
315+
if generator_opts[:out]
316+
begin
317+
::File.open(generator_opts[:out], 'wb') do |f|
318+
f.write(payload)
319+
end
320+
$stderr.puts "Saved as: #{generator_opts[:out]}"
321+
rescue ::Exception => e
322+
# If I can't save it, then I can't save it. I don't think it matters what error.
323+
elog("#{e.class} : #{e.message}\n#{e.backtrace * "\n"}")
324+
$stderr.puts e.message
325+
end
326+
else
327+
output_stream = $stdout
328+
output_stream.binmode
329+
output_stream.write payload
330+
end
314331

315332
end

0 commit comments

Comments
 (0)