Skip to content

Commit

Permalink
This commit adds support for C# byte arrays for the assembly payloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonprry committed Jun 12, 2013
1 parent fe32a74 commit d0e1e4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/msf/base/simple/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def self.transform(buf, fmt = "ruby")
buf = Rex::Text.to_bash(buf)
when 'c'
buf = Rex::Text.to_c(buf)
when 'csharp'
buf = Rex::Text.to_csharp(buf)
when 'js_be'
buf = Rex::Text.to_unescape(buf, ENDIAN_BIG)
when 'js_le'
Expand Down Expand Up @@ -59,6 +61,8 @@ def self.comment(buf, fmt = "ruby")
buf = Rex::Text.to_bash_comment(buf)
when 'c'
buf = Rex::Text.to_c_comment(buf)
when 'csharp'
buf = Rex::Text.to_c_comment(buf)
when 'js_be', 'js_le'
buf = Rex::Text.to_js_comment(buf)
when 'java'
Expand All @@ -74,7 +78,7 @@ def self.comment(buf, fmt = "ruby")
# Returns the list of supported formats
#
def self.transform_formats
['raw','ruby','rb','perl','pl','bash','sh','c','js_be','js_le','java','python','py']
['raw','ruby','rb','perl','pl','bash','sh','c','csharp','js_be','js_le','java','python','py']
end

end
Expand Down
11 changes: 11 additions & 0 deletions lib/rex/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ def self.to_c(str, wrap = DefaultWrap, name = "buf")
return hexify(str, wrap, '"', '"', "unsigned char #{name}[] = \n", '";')
end

def self.to_csharp(str, wrap = DefaultWrap, name = "buf")
ret = "byte[] #{name} = new byte[#{str.length}] {"
i = -1;
while (i += 1) < str.length
ret << "\n" if i%(wrap/4) == 0
ret << "0x" << str[i].unpack("H*")[0] << ","
end
ret = ret[0..ret.length-2] #cut off last comma
ret << " };\n"
end

#
# Creates a c-style comment
#
Expand Down
1 change: 1 addition & 0 deletions msfpayload
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ if (cmd =~ /^(p|y|r|d|c|j|x|b|v|w|n)/)
fmt = 'raw' if (cmd =~ /^(r|x|d)/)
fmt = 'raw' if (cmd =~ /^v/)
fmt = 'c' if (cmd == 'c')
fmt = 'csharp' if (cmd == 'csharp')
fmt = 'js_be' if (cmd =~ /^j/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
fmt = 'js_le' if (cmd =~ /^j/ and ! fmt)
fmt = 'java' if (cmd =~ /^b/)
Expand Down

0 comments on commit d0e1e4d

Please sign in to comment.