Beispiel #1
0
        private KMSResponse CreateKMSResponse(KMSRequest kmsRequest, IKMSServerSettings serverSettings, ILogger logger)
        {
            KMSResponse response = new KMSResponse {
                Version = kmsRequest.Version
            };
            string kmsPID;

            if (serverSettings.GenerateRandomKMSPID)
            {
                KMSPIDGenerator generator = new KMSPIDGenerator();
                kmsPID = generator.CreateKMSPID(kmsRequest);
                logger.LogMessage("KMS PID: " + kmsPID);
                logger.LogMessage("Application ID: " + kmsRequest.ApplicationId);
                logger.LogMessage("Client Machine ID: " + kmsRequest.ClientMachineId);
                logger.LogMessage("KMS Counted ID: " + kmsRequest.KmsCountedId);
                logger.LogMessage("SKUID ID: " + kmsRequest.SkuId);
                logger.LogMessage("KMS Activation Response (KMS V" + kmsRequest.MajorVersion + "." + kmsRequest.MinorVersion + ") sent." + Environment.NewLine);
            }
            else
            {
                kmsPID = serverSettings.DefaultKMSPID;
            }
            response.KMSPID               = kmsPID;
            response.ClientMachineId      = kmsRequest.ClientMachineId;
            response.RequestTime          = kmsRequest.RequestTime;
            response.CurrentClientCount   = serverSettings.CurrentClientCount;
            response.VLActivationInterval = serverSettings.VLActivationInterval;
            response.VLRenewalInterval    = serverSettings.VLRenewalInterval;
            return(response);
        }
Beispiel #2
0
        public byte[] ExecuteKMSServerLogic(byte[] kmsRequestBytes, ILogger logger)
        {
            KMSRequest kmsRequest = CreateKmsRequest(kmsRequestBytes);

            KMSResponse response = CreateKMSResponse(kmsRequest, _serverSettings, logger);

            byte[] responseBytes = CreateKMSResponseBytes(response);
            return(responseBytes);
        }
Beispiel #3
0
        private static KMSRequest CreateKmsRequest(byte[] decrypted)
        {
            using MemoryStream stream       = new MemoryStream(decrypted);
            using BinaryReader binaryReader = new BinaryReader(stream);
            KMSRequest kmsRequest = new KMSRequest {
                Version = binaryReader.ReadUInt32(), IsClientVM = binaryReader.ReadUInt32(), LicenseStatus = binaryReader.ReadUInt32(), GraceTime = binaryReader.ReadUInt32(), ApplicationId = new Guid(binaryReader.ReadBytes(16)), SkuId = new Guid(binaryReader.ReadBytes(16)), KmsCountedId = new Guid(binaryReader.ReadBytes(16)), ClientMachineId = new Guid(binaryReader.ReadBytes(16)), RequiredClientCount = binaryReader.ReadUInt32(), RequestTime = binaryReader.ReadUInt64(), PreviousClientMachineId = binaryReader.ReadBytes(16), MachineName = binaryReader.ReadBytes(64)
            };

            return(kmsRequest);
        }
Beispiel #4
0
        // Create Random KMS PID
        public string CreateKMSPID(KMSRequest request)
        {
            // KMS Host OS Type
            List <HostOS> hostOSList = new List <HostOS>
            {
                new HostOS {
                    Type = 55041, OSBuild = 6002, MinimumDay = 146, MinimumYear = 2009
                },                                                                                 // Windows Server 2008 SP2:    05/26/2009 SP2 GA
                new HostOS {
                    Type = 55041, OSBuild = 7601, MinimumDay = 53, MinimumYear = 2011
                },                                                                                 // Windows Server 2008 R2 SP1: 02/22/2011 SP1 GA
                new HostOS {
                    Type = 5426, OSBuild = 9200, MinimumDay = 248, MinimumYear = 2012
                },                                                                                 // Windows Server 2012 RTM:    09/04/2012 RTM GA
                new HostOS {
                    Type = 6401, OSBuild = 9600, MinimumDay = 291, MinimumYear = 2013
                },                                                                                 // Windows Server 2012 R2 RTM: 10/18/2013 RTM GA
                new HostOS {
                    Type = 3612, OSBuild = 14393, MinimumDay = 286, MinimumYear = 2016
                },                                                                                 // Windows Server 2016 RTM:    10/12/2016 RTM GA
                new HostOS {
                    Type = 3612, OSBuild = 17763, MinimumDay = 275, MinimumYear = 2018
                }                                                                                  // Windows Server 2019 RTM:    10/02/2018 RTM GA
            };

            // Product Specific KeyConfig
            List <PkeyConfig> pkeyConfigList = new List <PkeyConfig>
            {
                new PkeyConfig {
                    GroupID = 3858, PIDRangeMin = 0, PIDRangeMax = 14999999
                },                                                                                  // Windows 10 China Government
                new PkeyConfig {
                    GroupID = 152, PIDRangeMin = 381000000, PIDRangeMax = 392999999
                },                                                                                  // Windows Server 2008 C
                new PkeyConfig {
                    GroupID = 168, PIDRangeMin = 305000000, PIDRangeMax = 312119999
                },                                                                                  // Windows Server 2008 R2 C
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 152000000, PIDRangeMax = 191999999
                },                                                                                  // Windows Server 2012
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 271000000, PIDRangeMax = 310999999
                },                                                                                  // Windows Server 2012 R2
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 491000000, PIDRangeMax = 530999999
                },                                                                                  // Windows Server 2016
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 551000000, PIDRangeMax = 570999999
                },                                                                                  // Windows Server 2019
                new PkeyConfig {
                    GroupID = 96, PIDRangeMin = 199000000, PIDRangeMax = 217999999
                },                                                                                  // Office 2010
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 234000000, PIDRangeMax = 255999999
                },                                                                                  // Office 2013
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 437000000, PIDRangeMax = 458999999
                },                                                                                  // Office 2016
                new PkeyConfig {
                    GroupID = 206, PIDRangeMin = 666000000, PIDRangeMax = 685999999
                }                                                                                   // Office 2019
            };

            // Product Specific Detection
            int osTypeIndex    = HostServer2019;
            int keyConfigIndex = PkeyConfigWindowsServer2019;

            if (request.ApplicationId == _appIDOffice2010 || request.ApplicationId == _appIDOffice2013 || request.ApplicationId == _appIDOffice2016 || request.ApplicationId == _appIDOffice2019)
            {
                if (request.KmsCountedId == _kmsCountedIDOffice2010)
                {
                    keyConfigIndex = PkeyConfigOffice14;
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDOffice2013)
                {
                    keyConfigIndex = PkeyConfigOffice15;
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDOffice2016)
                {
                    keyConfigIndex = PkeyConfigOffice16;
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDOffice2019)
                {
                    keyConfigIndex = PkeyConfigOffice19;
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
            }
            else if (request.ApplicationId == _appIDWindows)
            {
                if (request.KmsCountedId == _kmsCountedIDWindowsVista || request.KmsCountedId == _kmsCountedIDWindowsServer2008A || request.KmsCountedId == _kmsCountedIDWindowsServer2008B || request.KmsCountedId == _kmsCountedIDWindowsServer2008C)
                {
                    keyConfigIndex = Random.Next(PkeyConfigWindowsServer2012, PkeyConfigWindowsServer2019 + 1);
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows7 || request.KmsCountedId == _kmsCountedIDWindowsServer2008R2A || request.KmsCountedId == _kmsCountedIDWindowsServer2008R2B || request.KmsCountedId == _kmsCountedIDWindowsServer2008R2C)
                {
                    keyConfigIndex = Random.Next(PkeyConfigWindowsServer2012, PkeyConfigWindowsServer2019 + 1);
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows8Retail || request.KmsCountedId == _kmsCountedIDWindows8Volume || request.KmsCountedId == _kmsCountedIDWindowsServer2012)
                {
                    keyConfigIndex = Random.Next(PkeyConfigWindowsServer2012, PkeyConfigWindowsServer2019 + 1);
                    osTypeIndex    = Random.Next(HostServer2012, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows81Retail || request.KmsCountedId == _kmsCountedIDWindows81Volume || request.KmsCountedId == _kmsCountedIDWindowsServer2012R2)
                {
                    keyConfigIndex = Random.Next(PkeyConfigWindowsServer2012R2, PkeyConfigWindowsServer2019 + 1);
                    osTypeIndex    = Random.Next(HostServer2012R2, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows10Retail || request.KmsCountedId == _kmsCountedIDWindows10Volume || request.KmsCountedId == _kmsCountedIDWindows10LTSB2015 || request.KmsCountedId == _kmsCountedIDWindows10LTSB2016 || request.KmsCountedId == _kmsCountedIDWindowsServer2016)
                {
                    keyConfigIndex = Random.Next(PkeyConfigWindowsServer2016, PkeyConfigWindowsServer2019 + 1);
                    osTypeIndex    = Random.Next(HostServer2016, HostServer2019 + 1);
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows10LTSC2019 || request.KmsCountedId == _kmsCountedIDWindowsServer2019)
                {
                    keyConfigIndex = PkeyConfigWindowsServer2019;
                    osTypeIndex    = HostServer2019;
                }
                else if (request.KmsCountedId == _kmsCountedIDWindows10ChinaGov)
                {
                    keyConfigIndex = PkeyConfigWindows10ChinaGov;
                    osTypeIndex    = HostServer2019;
                }
            }

            // Generate Part 1 & 7: Host Type and KMS Server OS Build
            HostOS osType = hostOSList[osTypeIndex];

            // Generate Part 2: Group ID and Product Key ID Range
            PkeyConfig keyConfig = pkeyConfigList[keyConfigIndex];

            // Generate Part 3 and Part 4: Product Key ID
            long productKeyID = Random.Next(0, int.MaxValue) % (keyConfig.PIDRangeMax - keyConfig.PIDRangeMin) + keyConfig.PIDRangeMin;

            // Generate Part 5: License Channel (00=Retail, 01=Retail, 02=OEM, 03=Volume(GVLK,MAK)) - always 03
            const int licenseChannel = 3;

            // Generate Part 6: Language - use system default language
            int languageCode = CultureInfo.InstalledUICulture.LCID; // GetSystemDefaultLCID();

            /* Generate Part 8: KMS Host Activation Date */
            int minimumDay, minimumYear;

            // Get Minimum Possible Date
            minimumDay  = osType.MinimumDay;
            minimumYear = osType.MinimumYear;

            // Get Current Time Information
            int currentYear = DateTime.Now.Year;           // Year (current year minus 1900).
            int currentDay  = DateTime.Now.DayOfYear;      // Day of Year (0-365; January 1 = 0)

            // Use 2018 for Current Year if time is screwed up.
            if (minimumYear > currentYear)
            {
                currentYear = 2018;
            }

            // Generate Year (Minimum Year to Current Year)
            int year = Random.Next() % (currentYear - (minimumYear - 1)) + minimumYear;

            // Generate Day
            int randomDay = Random.Next() % 365 + 1;

            // Check for future days and limits the random up to current day.
            if ((randomDay > currentDay) && (year == currentYear))
            {
                randomDay = Random.Next() % currentDay + 1;
            }
            // Check for product minimum build year and day and adjust the random accordingly.
            else if ((randomDay < minimumDay) && (year == minimumYear))
            {
                randomDay = minimumDay + (Random.Next() % (365 - minimumDay) + 1);
            }

            // Apply Setting
            string result = string.Format("{0:D5}-{1:D5}-{2:D3}-{3:D6}-{4:D2}-{5}-{6:D4}.0000-{7:D3}{8:D4}",
                                          osType.Type, keyConfig.GroupID, productKeyID / 1000000, productKeyID % 1000000, licenseChannel,
                                          languageCode, osType.OSBuild, randomDay, year);

            return(result);
        }