2005-07-10 07:15:20 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Ui
|
|
|
|
module Console
|
|
|
|
module CommandDispatcher
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# NOP module command dispatcher.
|
|
|
|
#
|
|
|
|
###
|
2005-07-10 07:15:20 +00:00
|
|
|
class Nop
|
|
|
|
|
2005-07-14 20:36:34 +00:00
|
|
|
include Msf::Ui::Console::ModuleCommandDispatcher
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
@@generate_opts = Rex::Parser::Arguments.new(
|
2005-07-18 14:39:00 +00:00
|
|
|
"-b" => [ true, "The list of characters to avoid: '\\x00\\xff'" ],
|
|
|
|
"-h" => [ false, "Help banner." ],
|
|
|
|
"-s" => [ true, "The comma separated list of registers to save." ],
|
|
|
|
"-t" => [ true, "The output type: ruby, perl, c, or raw." ])
|
2005-07-10 07:15:20 +00:00
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns the hash of supported commands.
|
|
|
|
#
|
2005-07-10 07:15:20 +00:00
|
|
|
def commands
|
2011-01-28 03:29:20 +00:00
|
|
|
super.update({
|
2005-07-14 06:34:58 +00:00
|
|
|
"generate" => "Generates a NOP sled",
|
2011-01-28 03:29:20 +00:00
|
|
|
})
|
2005-07-10 07:15:20 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns the name of the command dispatcher.
|
|
|
|
#
|
2005-07-14 20:18:36 +00:00
|
|
|
def name
|
|
|
|
"Nop"
|
|
|
|
end
|
|
|
|
|
2005-07-10 07:15:20 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Generates a NOP sled.
|
2005-07-10 07:15:20 +00:00
|
|
|
#
|
2005-07-18 14:39:00 +00:00
|
|
|
def cmd_generate(*args)
|
2005-07-10 07:15:20 +00:00
|
|
|
|
|
|
|
# No arguments? Tell them how to use it.
|
|
|
|
if (args.length == 0)
|
2005-07-10 23:19:59 +00:00
|
|
|
args << "-h"
|
2005-07-10 07:15:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the arguments
|
|
|
|
badchars = nil
|
2005-07-18 14:39:00 +00:00
|
|
|
saveregs = nil
|
2005-07-10 07:15:20 +00:00
|
|
|
type = "ruby"
|
|
|
|
length = 200
|
|
|
|
|
|
|
|
@@generate_opts.parse(args) { |opt, idx, val|
|
|
|
|
case opt
|
|
|
|
when nil
|
|
|
|
length = val.to_i
|
|
|
|
when '-b'
|
2005-07-14 06:34:58 +00:00
|
|
|
badchars = Rex::Text.hex_to_raw(val)
|
2005-07-18 14:39:00 +00:00
|
|
|
when "-c"
|
|
|
|
saveregs = val.split(/,\s?/)
|
2005-07-10 07:15:20 +00:00
|
|
|
when '-t'
|
|
|
|
type = val
|
2005-07-10 23:19:59 +00:00
|
|
|
when '-h'
|
|
|
|
print(
|
|
|
|
"Usage: generate [options] length\n\n" +
|
|
|
|
"Generates a NOP sled of a given length.\n" +
|
|
|
|
@@generate_opts.usage)
|
|
|
|
return false
|
2005-07-10 07:15:20 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate the sled
|
|
|
|
begin
|
2005-07-14 06:34:58 +00:00
|
|
|
sled = mod.generate_simple(
|
2005-07-10 09:42:49 +00:00
|
|
|
length,
|
2005-07-18 14:39:00 +00:00
|
|
|
'BadChars' => badchars,
|
|
|
|
'SaveRegisters' => saveregs,
|
|
|
|
'Format' => type)
|
2005-07-10 07:15:20 +00:00
|
|
|
rescue
|
2005-07-14 07:32:11 +00:00
|
|
|
log_error("Sled generation failed: #{$!}.")
|
2005-07-10 07:15:20 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
# Display generated sled
|
|
|
|
print(sled)
|
2005-07-10 07:15:20 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-01-28 03:29:20 +00:00
|
|
|
end end end end
|