Skip to content

Commit 2e4ac41

Browse files
committed
Land rapid7#4437, msfvenoms new output switch
2 parents ded1765 + fb35a45 commit 2e4ac41

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

msfvenom

Lines changed: 24 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,24 @@ 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+
# No payload generated, no point to go on
316+
exit(-1) unless payload
317+
318+
if generator_opts[:out]
319+
begin
320+
::File.open(generator_opts[:out], 'wb') do |f|
321+
f.write(payload)
322+
end
323+
$stderr.puts "Saved as: #{generator_opts[:out]}"
324+
rescue ::Exception => e
325+
# If I can't save it, then I can't save it. I don't think it matters what error.
326+
elog("#{e.class} : #{e.message}\n#{e.backtrace * "\n"}")
327+
$stderr.puts e.message
328+
end
329+
else
330+
output_stream = $stdout
331+
output_stream.binmode
332+
output_stream.write payload
333+
end
314334

315335
end

0 commit comments

Comments
 (0)