mirror of
https://github.com/Py-KMS-Organization/py-kms.git
synced 2025-05-17 16:45:15 -04:00
uploaded version 2018_11_15 for python2
This commit is contained in:
parent
73f66ea40f
commit
b0a8ff21fb
18 changed files with 1574 additions and 791 deletions
|
@ -1,16 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import argparse
|
||||
import binascii
|
||||
import datetime
|
||||
import random
|
||||
import socket
|
||||
import string
|
||||
import struct
|
||||
import sys
|
||||
import uuid
|
||||
import logging
|
||||
import os
|
||||
import errno
|
||||
|
||||
import filetimes, rpcBind, rpcRequest
|
||||
from dcerpc import MSRPCHeader, MSRPCBindNak, MSRPCRequestHeader, MSRPCRespHeader
|
||||
|
@ -19,6 +20,7 @@ from kmsRequestV4 import kmsRequestV4
|
|||
from kmsRequestV5 import kmsRequestV5
|
||||
from kmsRequestV6 import kmsRequestV6
|
||||
from rpcBase import rpcBase
|
||||
from kmsDB2Dict import kmsDB2Dict
|
||||
from formatText import shell_message, justify
|
||||
|
||||
config = {}
|
||||
|
@ -29,7 +31,8 @@ def main():
|
|||
parser.add_argument("port", nargs="?", action="store", default=1688,
|
||||
help='The port the KMS service is listening on. The default is \"1688\".', type=int)
|
||||
parser.add_argument("-m", "--mode", dest="mode",
|
||||
choices=["WindowsVista","Windows7","Windows8","Windows81","Windows10","Office2010","Office2013","Office2016"], default="Windows81",
|
||||
choices=["WindowsVista","Windows7","Windows8","Windows8.1","Windows10",
|
||||
"Office2010","Office2013","Office2016","Office2019"], default="Windows8.1",
|
||||
help='Use this flag to manually specify a Microsoft product for testing the server. The default is \"Windows81\".', type=str)
|
||||
parser.add_argument("-c", "--cmid", dest="cmid", default=None,
|
||||
help='Use this flag to manually specify a CMID to use. If no CMID is specified, a random CMID will be generated.', type=str)
|
||||
|
@ -62,7 +65,7 @@ a random machineName will be generated.', type=str)
|
|||
shell_message(nshell = [-4, 7])
|
||||
bindResponse = s.recv(1024)
|
||||
except socket.error, e:
|
||||
if e[0] == 104:
|
||||
if e.errno == errno.ECONNRESET:
|
||||
logging.error("Connection reset by peer. Exiting...")
|
||||
sys.exit()
|
||||
else:
|
||||
|
@ -84,15 +87,13 @@ a random machineName will be generated.', type=str)
|
|||
parsed = MSRPCRespHeader(response)
|
||||
kmsData = readKmsResponse(parsed['pduData'], kmsRequest, config)
|
||||
kmsResp = kmsData['response']
|
||||
|
||||
|
||||
try:
|
||||
hwid = kmsData['hwid']
|
||||
except:
|
||||
hwid = None
|
||||
logging.info("KMS Host ePID: %s" % kmsResp['kmsEpid'].decode('utf-16le').encode('utf-8'))
|
||||
if hwid is not None:
|
||||
logging.info("KMS Host HWID: %s" % binascii.b2a_hex(hwid).upper())
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
logging.info("KMS Host ePID: %s" % kmsResp['kmsEpid'].decode('utf-16le').encode('utf-8'))
|
||||
logging.info("KMS Host Current Client Count: %s" % kmsResp['currentClientCount'])
|
||||
logging.info("KMS VL Activation Interval: %s" % kmsResp['vLActivationInterval'])
|
||||
logging.info("KMS VL Renewal Interval: %s" % kmsResp['vLRenewalInterval'])
|
||||
|
@ -110,79 +111,45 @@ def checkConfig():
|
|||
if config['cmid'] is not None:
|
||||
try:
|
||||
uuid.UUID(config['cmid'])
|
||||
except:
|
||||
except ValueError:
|
||||
logging.error("Bad CMID. Exiting...")
|
||||
sys.exit()
|
||||
if config['machineName'] is not None:
|
||||
if len(config['machineName']) < 2 or len(config['machineName']) > 63:
|
||||
logging.error("machineName must be between 2 and 63 characters in length.")
|
||||
logging.error("Error: machineName must be between 2 and 63 characters in length.")
|
||||
sys.exit()
|
||||
|
||||
def updateConfig():
|
||||
if config['mode'] == 'WindowsVista':
|
||||
config['RequiredClientCount'] = 25
|
||||
config['KMSProtocolMajorVersion'] = 4
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "55c92734-d682-4d71-983e-d6ec3f16059f"
|
||||
config['KMSClientSkuID'] = "cfd8ff08-c0d7-452b-9f60-ef5c70c32094"
|
||||
config['KMSClientKMSCountedID'] = "212a64dc-43b1-4d3d-a30c-2fc69d2095c6"
|
||||
elif config['mode'] == 'Windows7':
|
||||
config['RequiredClientCount'] = 25
|
||||
config['KMSProtocolMajorVersion'] = 4
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "55c92734-d682-4d71-983e-d6ec3f16059f"
|
||||
config['KMSClientSkuID'] = "ae2ee509-1b34-41c0-acb7-6d4650168915"
|
||||
config['KMSClientKMSCountedID'] = "7fde5219-fbfa-484a-82c9-34d1ad53e856"
|
||||
elif config['mode'] == 'Windows8':
|
||||
config['RequiredClientCount'] = 25
|
||||
config['KMSProtocolMajorVersion'] = 5
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "55c92734-d682-4d71-983e-d6ec3f16059f"
|
||||
config['KMSClientSkuID'] = "458e1bec-837a-45f6-b9d5-925ed5d299de"
|
||||
config['KMSClientKMSCountedID'] = "3c40b358-5948-45af-923b-53d21fcc7e79"
|
||||
elif config['mode'] == 'Windows81':
|
||||
config['RequiredClientCount'] = 25
|
||||
config['KMSProtocolMajorVersion'] = 6
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "55c92734-d682-4d71-983e-d6ec3f16059f"
|
||||
config['KMSClientSkuID'] = "81671aaf-79d1-4eb1-b004-8cbbe173afea"
|
||||
config['KMSClientKMSCountedID'] = "cb8fc780-2c05-495a-9710-85afffc904d7"
|
||||
elif config['mode'] == 'Windows10':
|
||||
config['RequiredClientCount'] = 25
|
||||
config['KMSProtocolMajorVersion'] = 6
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "55c92734-d682-4d71-983e-d6ec3f16059f"
|
||||
config['KMSClientSkuID'] = "73111121-5638-40f6-bc11-f1d7b0d64300"
|
||||
config['KMSClientKMSCountedID'] = "58e2134f-8e11-4d17-9cb2-91069c151148"
|
||||
elif config['mode'] == 'Office2010':
|
||||
config['RequiredClientCount'] = 5
|
||||
config['KMSProtocolMajorVersion'] = 4
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "59a52881-a989-479d-af46-f275c6370663"
|
||||
config['KMSClientSkuID'] = "6f327760-8c5c-417c-9b61-836a98287e0c"
|
||||
config['KMSClientKMSCountedID'] = "e85af946-2e25-47b7-83e1-bebcebeac611"
|
||||
elif config['mode'] == 'Office2013':
|
||||
config['RequiredClientCount'] = 5
|
||||
config['KMSProtocolMajorVersion'] = 5
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "0ff1ce15-a989-479d-af46-f275c6370663"
|
||||
config['KMSClientSkuID'] = "b322da9c-a2e2-4058-9e4e-f59a6970bd69"
|
||||
config['KMSClientKMSCountedID'] = "e6a6f1bf-9d40-40c3-aa9f-c77ba21578c0"
|
||||
elif config['mode'] == 'Office2016':
|
||||
config['RequiredClientCount'] = 5
|
||||
config['KMSProtocolMajorVersion'] = 6
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = "0ff1ce15-a989-479d-af46-f275c6370663"
|
||||
config['KMSClientSkuID'] = "d450596f-894d-49e0-966a-fd39ed4c4c64"
|
||||
config['KMSClientKMSCountedID'] = "85b5f61b-320b-4be3-814a-b76b2bfafc82"
|
||||
kmsdb = kmsDB2Dict()
|
||||
|
||||
appitems = kmsdb[2]
|
||||
for appitem in appitems:
|
||||
kmsitems = appitem['KmsItems']
|
||||
for kmsitem in kmsitems:
|
||||
# Threshold.
|
||||
try:
|
||||
count = int(kmsitem['NCountPolicy'])
|
||||
except KeyError:
|
||||
count = 25
|
||||
|
||||
name = re.sub('\(.*\)', '', kmsitem['DisplayName']).replace('2015', '').replace(' ', '')
|
||||
if name == config['mode']:
|
||||
skuitems = kmsitem['SkuItems']
|
||||
# Select 'Enterprise' for Windows or 'Professional Plus' for Office.
|
||||
# (improvement: choice could be also random: skuitem = random.choice(skuitems))
|
||||
for skuitem in skuitems:
|
||||
if skuitem['DisplayName'].replace(' ','') == name + 'Enterprise' or \
|
||||
skuitem['DisplayName'].replace(' ','') == name[:6] + 'ProfessionalPlus' + name[6:]:
|
||||
|
||||
config['KMSClientSkuID'] = skuitem['Id']
|
||||
config['RequiredClientCount'] = count
|
||||
config['KMSProtocolMajorVersion'] = int(float(kmsitem['DefaultKmsProtocol']))
|
||||
config['KMSProtocolMinorVersion'] = 0
|
||||
config['KMSClientLicenseStatus'] = 2
|
||||
config['KMSClientAppID'] = appitem['Id']
|
||||
config['KMSClientKMSCountedID'] = kmsitem['Id']
|
||||
break
|
||||
|
||||
|
||||
def createKmsRequestBase():
|
||||
requestDict = kmsBase.kmsRequestStruct()
|
||||
|
@ -198,7 +165,8 @@ def createKmsRequestBase():
|
|||
requestDict['previousClientMachineId'] = '\0' * 16 #requestDict['clientMachineId'] # I'm pretty sure this is supposed to be a null UUID.
|
||||
requestDict['requiredClientCount'] = config['RequiredClientCount']
|
||||
requestDict['requestTime'] = filetimes.dt_to_filetime(datetime.datetime.utcnow())
|
||||
requestDict['machineName'] = (config['machineName'] if (config['machineName'] is not None) else ''.join(random.choice(string.letters + string.digits) for i in range(random.randint(2,63)))).encode('utf-16le')
|
||||
requestDict['machineName'] = (config['machineName'] if (config['machineName'] is not None) else
|
||||
''.join(random.choice(string.letters + string.digits) for i in range(random.randint(2,63)))).encode('utf-16le')
|
||||
requestDict['mnPad'] = '\0'.encode('utf-16le') * (63 - len(requestDict['machineName'].decode('utf-16le')))
|
||||
|
||||
# Debug Stuff
|
||||
|
@ -242,7 +210,8 @@ def readKmsResponse(data, request, config):
|
|||
def readKmsResponseV4(data, request):
|
||||
response = kmsRequestV4.ResponseV4(data)
|
||||
hashed = kmsRequestV4(data, config).generateHash(bytearray(str(response['response'])))
|
||||
logging.info("Response Hash has expected value: ", hashed == response['hash'])
|
||||
if hashed == response['hash']:
|
||||
logging.info("Response Hash has expected value !")
|
||||
return response
|
||||
|
||||
def readKmsResponseV5(data):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue