2005-07-10 09:42:49 +00:00
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Simple
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Payload
|
|
|
|
# -------
|
|
|
|
#
|
|
|
|
# Simple payload wrapper class for performing generation.
|
|
|
|
#
|
|
|
|
###
|
2005-07-14 06:34:58 +00:00
|
|
|
module Payload
|
|
|
|
|
|
|
|
include Module
|
2005-07-10 09:42:49 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Generate a payload with the mad skillz. The payload can be generated in
|
|
|
|
# a number of ways.
|
|
|
|
#
|
|
|
|
# opts can have:
|
|
|
|
#
|
2005-07-13 21:09:07 +00:00
|
|
|
# Encoder => A encoder module instance.
|
2005-07-14 06:34:58 +00:00
|
|
|
# BadChars => A string of bad characters.
|
2005-07-13 21:09:07 +00:00
|
|
|
# Format => The format to represent the data as: ruby, perl, c, raw
|
|
|
|
# Options => A hash of options to set.
|
|
|
|
# OptionStr => A string of options in VAR=VAL form separated by
|
|
|
|
# whitespace.
|
|
|
|
# NoComment => Disables prepention of a comment
|
|
|
|
# NopSledSize => The number of NOPs to use
|
2005-07-10 09:42:49 +00:00
|
|
|
#
|
2005-07-10 19:35:46 +00:00
|
|
|
# raises:
|
|
|
|
#
|
|
|
|
# BadcharError => If the supplied encoder fails to encode the payload
|
|
|
|
# NoKeyError => No valid encoder key could be found
|
|
|
|
# ArgumentParseError => Options were supplied improperly
|
|
|
|
#
|
2005-07-14 06:34:58 +00:00
|
|
|
def self.generate_simple(payload, opts)
|
|
|
|
|
|
|
|
# Import any options we may need
|
|
|
|
payload._import_extra_options(opts)
|
2005-07-10 19:21:40 +00:00
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
# Generate the payload
|
2005-07-13 21:09:07 +00:00
|
|
|
e = EncodedPayload.create(payload,
|
|
|
|
'BadChars' => opts['BadChars'],
|
|
|
|
'MinNops' => opts['NopSledSize'],
|
|
|
|
'Encoder' => opts['Encoder'])
|
2005-07-10 09:42:49 +00:00
|
|
|
|
2005-07-10 19:21:40 +00:00
|
|
|
fmt = opts['Format'] || 'raw'
|
|
|
|
|
2005-07-11 05:25:50 +00:00
|
|
|
# Save off the original payload length
|
2005-07-13 21:09:07 +00:00
|
|
|
len = e.encoded.length
|
2005-07-11 05:25:50 +00:00
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
# Serialize the generated payload to some sort of format
|
2005-07-13 21:09:07 +00:00
|
|
|
buf = Buffer.transform(e.encoded, fmt)
|
2005-07-10 19:21:40 +00:00
|
|
|
|
|
|
|
# Prepend a comment
|
|
|
|
if (fmt != 'raw' and opts['NoComment'] != true)
|
2005-07-14 06:34:58 +00:00
|
|
|
((ou = payload.options.options_used_to_s(payload.datastore)) and ou.length > 0) ? ou += "\n" : ou = ''
|
2005-07-10 19:21:40 +00:00
|
|
|
buf = Buffer.comment(
|
2005-07-13 18:06:12 +00:00
|
|
|
"#{payload.refname} - #{len} bytes\n" +
|
|
|
|
"http://www.metasploit.com\n" +
|
2005-07-13 21:09:07 +00:00
|
|
|
((e.encoder) ? "Encoder: #{e.encoder.refname}\n" : '') +
|
2005-07-14 06:34:58 +00:00
|
|
|
((e.nop) ? "NOP gen: #{e.nop.refname}\n" : '') +
|
|
|
|
"#{ou}",
|
|
|
|
fmt) + buf
|
2005-07-10 19:21:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return buf
|
2005-07-10 09:42:49 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
|
|
|
# Calls the class method
|
|
|
|
#
|
|
|
|
def generate_simple(opts)
|
|
|
|
Msf::Simple::Payload.generate_simple(self, opts)
|
|
|
|
end
|
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|