2005-07-10 10:08:10 +00:00
|
|
|
require 'rex/parser/arguments'
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Console
|
|
|
|
module CommandDispatcher
|
|
|
|
|
|
|
|
class Payload
|
|
|
|
|
2005-07-10 10:08:10 +00:00
|
|
|
@@generate_opts = Rex::Parser::Arguments.new(
|
2005-07-14 06:34:58 +00:00
|
|
|
"-b" => [ true, "The list of characters to avoid: '\\x00\\xff'" ],
|
2005-07-10 19:21:40 +00:00
|
|
|
"-e" => [ true, "The name of the encoder module to use." ],
|
2005-07-14 06:34:58 +00:00
|
|
|
"-h" => [ false, "Help banner." ],
|
|
|
|
"-o" => [ true, "A comma separated list of options in VAR=VAL format." ],
|
2005-07-13 21:09:07 +00:00
|
|
|
"-s" => [ true, "NOP sled length." ],
|
2005-07-14 06:34:58 +00:00
|
|
|
"-t" => [ true, "The output type: ruby, perl, c, or raw." ])
|
2005-07-10 10:08:10 +00:00
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
include Msf::Ui::Console::ModuleCommandDispatcher
|
|
|
|
|
2005-07-10 10:08:10 +00:00
|
|
|
def commands
|
2005-07-14 06:34:58 +00:00
|
|
|
{
|
|
|
|
"generate" => "Generates a payload",
|
|
|
|
}
|
2005-07-10 10:08:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generates a payload
|
|
|
|
#
|
2005-07-14 06:34:58 +00:00
|
|
|
def cmd_generate(*args)
|
2005-07-10 10:08:10 +00:00
|
|
|
|
|
|
|
# Parse the arguments
|
|
|
|
encoder_name = nil
|
2005-07-13 21:09:07 +00:00
|
|
|
sled_size = nil
|
2005-07-10 19:21:40 +00:00
|
|
|
option_str = nil
|
2005-07-10 10:08:10 +00:00
|
|
|
badchars = nil
|
|
|
|
type = "ruby"
|
|
|
|
|
|
|
|
@@generate_opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when '-b'
|
2005-07-13 23:01:34 +00:00
|
|
|
badchars = Rex::Text.hex_to_raw(val)
|
2005-07-10 10:08:10 +00:00
|
|
|
when '-t'
|
|
|
|
type = val
|
|
|
|
when '-e'
|
|
|
|
encoder_name = val
|
2005-07-10 19:21:40 +00:00
|
|
|
when '-o'
|
|
|
|
option_str = val
|
2005-07-13 21:09:07 +00:00
|
|
|
when '-s'
|
|
|
|
sled_size = val.to_i
|
2005-07-10 10:08:10 +00:00
|
|
|
when '-h'
|
2005-07-10 19:21:40 +00:00
|
|
|
print(
|
|
|
|
"Usage: generate [options]\n\n" +
|
|
|
|
"Generates a payload.\n" +
|
|
|
|
@@generate_opts.usage)
|
2005-07-10 10:08:10 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2005-07-10 10:41:11 +00:00
|
|
|
# Generate the payload
|
2005-07-10 10:08:10 +00:00
|
|
|
begin
|
2005-07-14 06:34:58 +00:00
|
|
|
buf = mod.generate_simple(
|
2005-07-13 21:09:07 +00:00
|
|
|
'BadChars' => badchars,
|
|
|
|
'Encoder' => encoder_name,
|
|
|
|
'Format' => type,
|
|
|
|
'NopSledSize' => sled_size,
|
|
|
|
'OptionStr' => option_str)
|
2005-07-10 10:08:10 +00:00
|
|
|
rescue
|
2005-07-10 19:35:46 +00:00
|
|
|
print_error("Payload generation failed: #{$!}")
|
2005-07-10 10:08:10 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Display generated payload
|
2005-07-10 10:41:11 +00:00
|
|
|
print(buf)
|
2005-07-10 10:08:10 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end end end end
|