mirror of
				https://github.com/SystemRage/py-kms.git
				synced 2025-11-01 02:59:19 +08:00 
			
		
		
		
	uploaded version 2018_11_15 for python3
This commit is contained in:
		| @@ -1,7 +1,6 @@ | ||||
| #!/usr/bin/env python3 | ||||
|  | ||||
| import binascii | ||||
| import struct | ||||
| import time | ||||
| import logging | ||||
|  | ||||
| @@ -10,7 +9,6 @@ from structure import Structure | ||||
| from aes import AES | ||||
| from formatText import shell_message, justify, byterize | ||||
|  | ||||
|  | ||||
| # v4 AES Key | ||||
| key = bytearray([0x05, 0x3D, 0x83, 0x07, 0xF9, 0xE5, 0xF0, 0x88, 0xEB, 0x5E, 0xA6, 0x68, 0x6C, 0xF0, 0x37, 0xC7, 0xE4, 0xEF, 0xD2, 0xD6]) | ||||
|  | ||||
| @@ -33,9 +31,9 @@ class kmsRequestV4(kmsBase): | ||||
|         class ResponseV4(Structure): | ||||
|                 commonHdr = () | ||||
|                 structure = ( | ||||
|                         ('bodyLength1', '<I=len(response) + len(hash)'), | ||||
|                         ('bodyLength1', '<I'), | ||||
|                         ('unknown',     '!I=0x00000200'), | ||||
|                         ('bodyLength2', '<I=len(response) + len(hash)'), | ||||
|                         ('bodyLength2', '<I'), | ||||
|                         ('response',    ':', kmsBase.kmsResponseStruct), | ||||
|                         ('hash',        '16s'), | ||||
|                         ('padding',     ':'), | ||||
| @@ -45,12 +43,13 @@ class kmsRequestV4(kmsBase): | ||||
|                 requestData = self.RequestV4(self.data) | ||||
|  | ||||
|                 response = self.serverLogic(requestData['request']) | ||||
|                 thehash = self.generateHash(bytearray(str(response).encode('latin-1'))) | ||||
|  | ||||
|                 thehash = self.generateHash(bytearray(str(response).encode('latin-1'))) #*2to3* | ||||
|  | ||||
|                 self.responseData = self.generateResponse(response, thehash) | ||||
|                 responseData = self.generateResponse(response, thehash) | ||||
|  | ||||
|                 time.sleep(1) # request sent back too quick for Windows 2008 R2, slow it down. | ||||
|                  | ||||
|                 return responseData | ||||
|  | ||||
|         def generateHash(self, message): | ||||
|                 """ | ||||
| @@ -90,42 +89,40 @@ class kmsRequestV4(kmsBase): | ||||
|                 xorBuffer(lastBlock, 0, hashBuffer, 16) | ||||
|                 hashBuffer = bytearray(aes.encrypt(hashBuffer, key, len(key))) | ||||
|  | ||||
|                 return hashBuffer #*2to3* | ||||
|                 return hashBuffer | ||||
|  | ||||
|         def generateResponse(self, responseBuffer, thehash): | ||||
|                 bodyLength = len(responseBuffer) + len(thehash) | ||||
|                 response = self.ResponseV4() | ||||
|                 bodyLength = len(responseBuffer) + len(thehash) | ||||
|                 response['bodyLength1'] = bodyLength | ||||
|                 response['bodyLength2'] = bodyLength | ||||
|                 response['response'] = responseBuffer | ||||
|                 response['hash'] = thehash.decode('latin-1') #*2to3* | ||||
|                 response['padding'] = self.getResponsePadding(bodyLength).decode('latin-1') #*2to3* | ||||
|                 response['hash'] = thehash.decode('latin-1') | ||||
|                 response['padding'] = bytearray(self.getPadding(bodyLength)).decode('latin-1') | ||||
|                  | ||||
|                 ## Debug stuff. | ||||
|                 shell_message(nshell = 16) | ||||
|                 response = byterize(response) | ||||
|                 logging.debug("KMS V4 Response: \n%s\n" % justify(response.dump(print_to_stdout = False))) | ||||
|                 logging.debug("KMS V4 Response Bytes: \n%s\n" % justify(binascii.b2a_hex(str(response).encode('latin-1')).decode('utf-8'))) #*2to3* | ||||
|                 logging.debug("KMS V4 Response Bytes: \n%s\n" % justify(binascii.b2a_hex(str(response).encode('latin-1')).decode('utf-8'))) | ||||
|                          | ||||
|                 return str(response) | ||||
|  | ||||
|         def getResponse(self): | ||||
|                 return self.responseData | ||||
|  | ||||
|         def generateRequest(self, requestBase): | ||||
|                 thehash = self.generateHash(bytearray(str(requestBase).encode('latin-1'))) #*2to3* | ||||
|  | ||||
|                 bodyLength = len(requestBase) + len(thehash) | ||||
|                 thehash = self.generateHash(bytearray(str(requestBase).encode('latin-1'))) | ||||
|  | ||||
|                 request = kmsRequestV4.RequestV4() | ||||
|                 bodyLength = len(requestBase) + len(thehash)                | ||||
|                 request['bodyLength1'] = bodyLength | ||||
|                 request['bodyLength2'] = bodyLength | ||||
|                 request['request'] = requestBase | ||||
|                 request['hash'] = thehash.decode('latin-1') #*2to3* | ||||
|                 request['padding'] = self.getResponsePadding(bodyLength).decode('latin-1') #*2to3* | ||||
|                 request['hash'] = thehash.decode('latin-1') | ||||
|                 request['padding'] = bytearray(self.getPadding(bodyLength)).decode('latin-1') | ||||
|                  | ||||
|                 ## Debug stuff. | ||||
|                 shell_message(nshell = 10) | ||||
|                 request = byterize(request) | ||||
|                 logging.debug("Request V4 Data: \n%s\n" % justify(request.dump(print_to_stdout = False))) | ||||
|                 logging.debug("Request V4: \n%s\n" % justify(binascii.b2a_hex(str(request).encode('latin-1')).decode('utf-8'))) #*2to3* | ||||
|                 logging.debug("Request V4: \n%s\n" % justify(binascii.b2a_hex(str(request).encode('latin-1')).decode('utf-8'))) | ||||
|                                  | ||||
|                 return request | ||||
|   | ||||
		Reference in New Issue
	
	Block a user