2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2010-09-21 00:13:30 +00:00
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
module Simple
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Wraps interaction with a generated buffer from the framework.
|
|
|
|
# Its primary use is to transform a raw buffer into another
|
|
|
|
# format.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Buffer
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:29:56 +00:00
|
|
|
# Serializes a buffer to a provided format. The formats supported are raw,
|
2011-11-11 08:13:17 +00:00
|
|
|
# ruby, perl, bash, c, js_be, js_le and java
|
2005-07-10 09:42:49 +00:00
|
|
|
#
|
2005-07-10 19:21:40 +00:00
|
|
|
def self.transform(buf, fmt = "ruby")
|
2005-07-10 09:42:49 +00:00
|
|
|
case fmt
|
|
|
|
when 'raw'
|
2013-05-14 01:44:51 +00:00
|
|
|
when 'python', 'py'
|
|
|
|
buf = Rex::Text.to_python(buf)
|
2010-09-21 00:13:30 +00:00
|
|
|
when 'ruby', 'rb'
|
2005-07-10 09:42:49 +00:00
|
|
|
buf = Rex::Text.to_ruby(buf)
|
2010-09-21 00:13:30 +00:00
|
|
|
when 'perl', 'pl'
|
2005-07-10 09:42:49 +00:00
|
|
|
buf = Rex::Text.to_perl(buf)
|
2011-11-11 08:13:17 +00:00
|
|
|
when 'bash', 'sh'
|
|
|
|
buf = Rex::Text.to_bash(buf)
|
2005-07-10 09:42:49 +00:00
|
|
|
when 'c'
|
|
|
|
buf = Rex::Text.to_c(buf)
|
2006-07-31 04:05:20 +00:00
|
|
|
when 'js_be'
|
|
|
|
buf = Rex::Text.to_unescape(buf, ENDIAN_BIG)
|
|
|
|
when 'js_le'
|
|
|
|
buf = Rex::Text.to_unescape(buf, ENDIAN_LITTLE)
|
2007-05-07 04:42:11 +00:00
|
|
|
when 'java'
|
|
|
|
buf = Rex::Text.to_java(buf)
|
2005-07-10 09:42:49 +00:00
|
|
|
else
|
|
|
|
raise ArgumentError, "Unsupported buffer format: #{fmt}", caller
|
|
|
|
end
|
|
|
|
|
|
|
|
return buf
|
|
|
|
end
|
|
|
|
|
2005-07-10 19:21:40 +00:00
|
|
|
#
|
2005-11-15 15:29:56 +00:00
|
|
|
# Creates a comment using the supplied format. The formats supported are
|
2011-11-11 08:13:17 +00:00
|
|
|
# raw, ruby, perl, bash, js_be, js_le, c, and java.
|
2005-07-10 19:21:40 +00:00
|
|
|
#
|
|
|
|
def self.comment(buf, fmt = "ruby")
|
|
|
|
case fmt
|
|
|
|
when 'raw'
|
2013-05-14 01:41:15 +00:00
|
|
|
when 'ruby', 'rb', 'python', 'py'
|
2005-07-10 19:21:40 +00:00
|
|
|
buf = Rex::Text.to_ruby_comment(buf)
|
2010-09-21 00:13:30 +00:00
|
|
|
when 'perl', 'pl'
|
2005-07-10 19:21:40 +00:00
|
|
|
buf = Rex::Text.to_perl_comment(buf)
|
2011-11-11 08:13:17 +00:00
|
|
|
when 'bash', 'sh'
|
|
|
|
buf = Rex::Text.to_bash_comment(buf)
|
2005-07-10 19:21:40 +00:00
|
|
|
when 'c'
|
|
|
|
buf = Rex::Text.to_c_comment(buf)
|
2006-07-31 04:05:20 +00:00
|
|
|
when 'js_be', 'js_le'
|
|
|
|
buf = Rex::Text.to_js_comment(buf)
|
2007-05-07 04:42:11 +00:00
|
|
|
when 'java'
|
|
|
|
buf = Rex::Text.to_c_comment(buf)
|
2005-07-10 19:21:40 +00:00
|
|
|
else
|
|
|
|
raise ArgumentError, "Unsupported buffer format: #{fmt}", caller
|
|
|
|
end
|
|
|
|
|
|
|
|
return buf
|
|
|
|
end
|
|
|
|
|
2010-09-21 00:13:30 +00:00
|
|
|
#
|
|
|
|
# Returns the list of supported formats
|
|
|
|
#
|
|
|
|
def self.transform_formats
|
2013-05-14 01:41:15 +00:00
|
|
|
['raw','ruby','rb','perl','pl','bash','sh','c','js_be','js_le','java','python','py']
|
2010-09-21 00:13:30 +00:00
|
|
|
end
|
|
|
|
|
2005-07-10 09:42:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-01-09 02:16:02 +00:00
|
|
|
end
|