simple wrappers

git-svn-id: file:///home/svn/incoming/trunk@2707 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-10 09:42:49 +00:00
parent ed50e291fc
commit 1fe45cae31
5 changed files with 129 additions and 14 deletions

View File

@ -18,6 +18,11 @@
# framework-base depends on framework-core
require 'msf/core'
# Simple wrapper
require 'msf/base/simple/buffer'
require 'msf/base/simple/nop'
require 'msf/base/simple/payload'
# Sessions
require 'msf/base/session/command_shell'
require 'msf/base/session/meterpreter'

View File

@ -0,0 +1,40 @@
require 'msf/base'
module Msf
module Simple
###
#
# Buffer
# ------
#
# Wraps interaction with a generated buffer from the framework.
# Its primary use is to transform a raw buffer into another
# format.
#
###
module Buffer
#
# Serializes a buffer to a provided format
#
def self.transform(buf, fmt)
case fmt
when 'raw'
when 'ruby'
buf = Rex::Text.to_ruby(buf)
when 'perl'
buf = Rex::Text.to_perl(buf)
when 'c'
buf = Rex::Text.to_c(buf)
else
raise ArgumentError, "Unsupported buffer format: #{fmt}", caller
end
return buf
end
end
end
end

View File

@ -0,0 +1,35 @@
require 'msf/base'
module Msf
module Simple
###
#
# Nop
# ---
#
# Simple nop wrapper class for performing generation.
#
###
class Nop
#
# Generate a nop sled, optionally with a few parameters.
#
# opts can have any of the standard nop generate sled options
# as well as:
#
# Format => The format to represent the data as: ruby, perl, c, raw
#
def self.generate(nop, length, opts)
# Generate the nop sled using the options supplied
buf = nop.generate_sled(length, opts)
# Serialize the generated payload to some sort of format
return Buffer.transform(buf, opts['Format'] || 'raw')
end
end
end
end

View File

@ -0,0 +1,42 @@
require 'msf/base'
module Msf
module Simple
###
#
# Payload
# -------
#
# Simple payload wrapper class for performing generation.
#
###
class Payload
#
# Generate a payload with the mad skillz. The payload can be generated in
# a number of ways.
#
# opts can have:
#
# Encoder => A encoder module instance.
# Badchars => A string of bad characters.
# Format => The format to represent the data as: ruby, perl, c, raw
#
def self.generate(payload, opts)
# Generate the payload
buf = payload.generate
# If an encoder was specified, encode the generated payload
if (opts['Encoder'])
buf = opts['Encoder'].encode(buf, opts['Badchars'])
end
# Serialize the generated payload to some sort of format
return Buffer.transform(buf, opts['Format'] || 'raw')
end
end
end
end

View File

@ -55,26 +55,19 @@ class Nop
# Generate the sled
begin
sled = mod.generate_sled(
length,
sled = Msf::Simple::Nop.generate(
mod,
length,
'Badchars' => badchars,
'Random' => random)
'Random' => random,
'Format' => type)
rescue
print_error("Sled generation failed: #{$!}.")
return false
end
# Output the sled
case type
when "ruby"
print(Rex::Text.to_ruby(sled))
when "c"
print(Rex::Text.to_c(sled, 60, "nop_sled"))
when "perl"
print(Rex::Text.to_perl(sled))
when "raw"
print(sled)
end
# Display generated sled
print(sled)
return true
end