Land #2667 - Add num and dword output format

bug/bundler_fix
sinn3r 2013-12-02 13:52:17 -06:00
commit 4d3d02ae01
No known key found for this signature in database
GPG Key ID: 2384DB4EF06F730B
4 changed files with 96 additions and 18 deletions

View File

@ -16,11 +16,15 @@ module Buffer
#
# Serializes a buffer to a provided format. The formats supported are raw,
# ruby, perl, bash, c, js_be, js_le, java and psh
# num, dword, ruby, python, perl, bash, c, js_be, js_le, java and psh
#
def self.transform(buf, fmt = "ruby")
case fmt
when 'raw'
when 'num'
buf = Rex::Text.to_num(buf)
when 'dword', 'dw'
buf = Rex::Text.to_dword(buf)
when 'python', 'py'
buf = Rex::Text.to_python(buf)
when 'ruby', 'rb'
@ -54,11 +58,13 @@ module Buffer
#
# Creates a comment using the supplied format. The formats supported are
# raw, ruby, perl, bash, js_be, js_le, c, and java.
# raw, ruby, python, perl, bash, js_be, js_le, c, and java.
#
def self.comment(buf, fmt = "ruby")
case fmt
when 'raw'
when 'num', 'dword', 'dw'
buf = Rex::Text.to_js_comment(buf)
when 'ruby', 'rb', 'python', 'py'
buf = Rex::Text.to_ruby_comment(buf)
when 'perl', 'pl'
@ -84,19 +90,28 @@ module Buffer
# Returns the list of supported formats
#
def self.transform_formats
['raw',
'ruby','rb',
'perl','pl',
'bash','sh',
'c',
'csharp',
'js_be',
'js_le',
'java',
'python','py',
'powershell','ps1',
'vbscript',
'vbapplication'
[
'bash',
'c',
'csharp',
'dw',
'dword',
'java',
'js_be',
'js_le',
'num',
'perl',
'pl',
'powershell',
'ps1',
'py',
'python',
'raw',
'rb',
'ruby',
'sh',
'vbapplication',
'vbscript'
]
end

View File

@ -1729,8 +1729,25 @@ def self.to_vba(framework,code,opts={})
def self.to_executable_fmt_formats
[
'dll','exe','exe-service','exe-small','exe-only','elf','macho','vba','vba-exe',
'vbs','loop-vbs','asp','aspx', 'aspx-exe','war','psh','psh-net', 'msi', 'msi-nouac'
"asp",
"aspx",
"aspx-exe",
"dll",
"elf",
"exe",
"exe-only",
"exe-service",
"exe-small",
"loop-vbs",
"macho",
"msi",
"msi-nouac",
"psh",
"psh-net",
"vba",
"vba-exe",
"vbs",
"war"
]
end

View File

@ -115,6 +115,52 @@ module Text
return hexify(str, wrap, '"', '" +', "#{name} = \n", '"')
end
#
# Creates a comma separated list of numbers
#
def self.to_num(str, wrap = DefaultWrap)
code = str.unpack('C*')
buff = ""
0.upto(code.length-1) do |byte|
if(byte % 15 == 0) and (buff.length > 0)
buff << "\r\n"
end
buff << sprintf('0x%.2x, ', code[byte])
end
# strip , at the end
buff = buff.chomp(', ')
buff << "\r\n"
return buff
end
#
# Creates a comma separated list of dwords
#
def self.to_dword(str, wrap = DefaultWrap)
code = str
alignnr = str.length % 4
if (alignnr > 0)
code << "\x00" * (4 - alignnr)
end
codevalues = Array.new
code.split("").each_slice(4) do |chars4|
chars4 = chars4.join("")
dwordvalue = chars4.unpack('*V')
codevalues.push(dwordvalue[0])
end
buff = ""
0.upto(codevalues.length-1) do |byte|
if(byte % 8 == 0) and (buff.length > 0)
buff << "\r\n"
end
buff << sprintf('0x%.8x, ', codevalues[byte])
end
# strip , at the end
buff = buff.chomp(', ')
buff << "\r\n"
return buff
end
#
# Creates a ruby-style comment
#