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(
|
|
|
|
"-b" => [ true, "The list of characters to avoid '\\x00\\xff'" ],
|
|
|
|
"-t" => [ true, "The output type: ruby, perl, c, or raw." ],
|
|
|
|
"-e" => [ true, "The name of the encoder module to use." ],
|
|
|
|
"-h" => [ false, "Help banner." ])
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
include Msf::Ui::Console::ModuleCommandDispatcher
|
|
|
|
|
2005-07-10 10:08:10 +00:00
|
|
|
def commands
|
|
|
|
return {
|
|
|
|
"generate" => "Generates a payload",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generates a payload
|
|
|
|
#
|
|
|
|
def cmd_generate(args)
|
|
|
|
|
|
|
|
# Parse the arguments
|
|
|
|
encoder_name = nil
|
|
|
|
badchars = nil
|
|
|
|
encoder = nil
|
|
|
|
type = "ruby"
|
|
|
|
|
|
|
|
@@generate_opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when '-b'
|
|
|
|
badchars = [ val.downcase.gsub(/\\x([a-f0-9][a-f0-9])/, '\1') ].pack("H*")
|
|
|
|
when '-t'
|
|
|
|
type = val
|
|
|
|
when '-e'
|
|
|
|
encoder_name = val
|
|
|
|
when '-h'
|
|
|
|
print(@@generate_opts.usage)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# If an encoder name was specified, try to instantiate it
|
|
|
|
if ((encoder_name) and
|
|
|
|
(encoder = framework.modules.create(encoder_name)) == nil)
|
|
|
|
print_error("Invalid encoder specified: #{encoder_name}")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generate the sled
|
|
|
|
begin
|
|
|
|
sled = Msf::Simple::Payload.generate(
|
|
|
|
mod,
|
|
|
|
'Badchars' => badchars,
|
|
|
|
'Encoder' => encoder,
|
|
|
|
'Format' => type)
|
|
|
|
rescue
|
|
|
|
print_error("Payload generation failed: #{$!}.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Display generated payload
|
|
|
|
print(sled)
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end end end end
|