Skip to content

Commit d0e1e4d

Browse files
committed
This commit adds support for C# byte arrays for the assembly payloads.
1 parent fe32a74 commit d0e1e4d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/msf/base/simple/buffer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def self.transform(buf, fmt = "ruby")
3131
buf = Rex::Text.to_bash(buf)
3232
when 'c'
3333
buf = Rex::Text.to_c(buf)
34+
when 'csharp'
35+
buf = Rex::Text.to_csharp(buf)
3436
when 'js_be'
3537
buf = Rex::Text.to_unescape(buf, ENDIAN_BIG)
3638
when 'js_le'
@@ -59,6 +61,8 @@ def self.comment(buf, fmt = "ruby")
5961
buf = Rex::Text.to_bash_comment(buf)
6062
when 'c'
6163
buf = Rex::Text.to_c_comment(buf)
64+
when 'csharp'
65+
buf = Rex::Text.to_c_comment(buf)
6266
when 'js_be', 'js_le'
6367
buf = Rex::Text.to_js_comment(buf)
6468
when 'java'
@@ -74,7 +78,7 @@ def self.comment(buf, fmt = "ruby")
7478
# Returns the list of supported formats
7579
#
7680
def self.transform_formats
77-
['raw','ruby','rb','perl','pl','bash','sh','c','js_be','js_le','java','python','py']
81+
['raw','ruby','rb','perl','pl','bash','sh','c','csharp','js_be','js_le','java','python','py']
7882
end
7983

8084
end

lib/rex/text.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ def self.to_c(str, wrap = DefaultWrap, name = "buf")
8282
return hexify(str, wrap, '"', '"', "unsigned char #{name}[] = \n", '";')
8383
end
8484

85+
def self.to_csharp(str, wrap = DefaultWrap, name = "buf")
86+
ret = "byte[] #{name} = new byte[#{str.length}] {"
87+
i = -1;
88+
while (i += 1) < str.length
89+
ret << "\n" if i%(wrap/4) == 0
90+
ret << "0x" << str[i].unpack("H*")[0] << ","
91+
end
92+
ret = ret[0..ret.length-2] #cut off last comma
93+
ret << " };\n"
94+
end
95+
8596
#
8697
# Creates a c-style comment
8798
#

msfpayload

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ if (cmd =~ /^(p|y|r|d|c|j|x|b|v|w|n)/)
125125
fmt = 'raw' if (cmd =~ /^(r|x|d)/)
126126
fmt = 'raw' if (cmd =~ /^v/)
127127
fmt = 'c' if (cmd == 'c')
128+
fmt = 'csharp' if (cmd == 'csharp')
128129
fmt = 'js_be' if (cmd =~ /^j/ and Rex::Arch.endian(payload.arch) == ENDIAN_BIG)
129130
fmt = 'js_le' if (cmd =~ /^j/ and ! fmt)
130131
fmt = 'java' if (cmd =~ /^b/)

0 commit comments

Comments
 (0)