5 #define CONFIG "config.h"
13 // REQUEST... types are actually fixed size
14 // RESPONSE... size may vary, defined here is max possible size
17 #define MAX_RESPONSE_SIZE 384
18 #define PID_BUFFER_SIZE 64
19 #define MAX_REQUEST_SIZE sizeof(REQUEST_V6)
20 #define WORKSTATION_NAME_BUFFER 64
22 // Constants for V6 time stamp interval
23 #define TIME_C1 0x00000022816889BDULL
24 #define TIME_C2 0x000000208CBAB5EDULL
25 #define TIME_C3 0x3156CD5AC628477AULL
27 #define VERSION_INFO union \
36 // Aliases for various KMS struct members
37 #define IsClientVM VMInfo
38 #define GraceTime BindingExpiration
39 #define MinutesRemaingInCurrentStatus BindingExpiration
41 #define ApplicationID AppID
44 #define ClientMachineId CMID
45 #define MinimumClients N_Policy
46 #define TimeStamp ClientTime
47 #define PreviousCLientMachineId CMID_prev
49 #define XorSalt XoredIVs
50 #define ActivationInterval VLActivationInterval
51 #define RenewalInterval VLRenewalInterval
56 DWORD VMInfo
; // 0 = client is bare metal / 1 = client is VM
57 DWORD LicenseStatus
; // 0 = Unlicensed, 1 = Licensed (Activated), 2 = OOB grace, 3 = OOT grace, 4 = NonGenuineGrace, 5 = Notification, 6 = extended grace
58 DWORD BindingExpiration
; // Expiration of the current status in minutes (e.g. when KMS activation or OOB grace expires).
59 GUID AppID
; // Can currently be Windows, Office2010 or Office2013 (see kms.c, table AppList).
60 GUID ActID
; // Most detailed product list. One product key per ActID (see kms.c, table ExtendedProductList). Is ignored by KMS server.
61 GUID KMSID
; // This is actually what the KMS server uses to grant or refuse activation (see kms.c, table BasicProductList).
62 GUID CMID
; // Client machine id. Used by the KMS server for counting minimum clients.
63 DWORD N_Policy
; // Minimum clients required for activation.
64 FILETIME ClientTime
; // Current client time.
65 GUID CMID_prev
; // previous client machine id. All zeros, if it never changed.
66 WCHAR WorkstationName
[64]; // Workstation name. FQDN if available, NetBIOS otherwise.
67 } /*__packed*/ REQUEST
;
71 DWORD PIDSize
; // Size of PIDData in bytes.
72 WCHAR KmsPID
[PID_BUFFER_SIZE
]; // ePID (must include terminating zero)
73 GUID CMID
; // Client machine id. Must be the same as in request.
74 FILETIME ClientTime
; // Current client time. Must be the same as in request.
75 DWORD Count
; // Current activated machines. KMS server counts up to N_Policy << 1 then stops
76 DWORD VLActivationInterval
; // Time in minutes when clients should retry activation if it was unsuccessful (default 2 hours)
77 DWORD VLRenewalInterval
; // Time in minutes when clients should renew KMS activation (default 7 days)
78 } /*__packed*/ RESPONSE
;
84 WCHAR KmsPID
[49]; // Set this to the ePID length you want to debug
88 DWORD VLActivationInterval
;
89 DWORD VLRenewalInterval
;
90 } __packed RESPONSE_DEBUG
;
95 REQUEST RequestBase
; // Base request
96 BYTE MAC
[16]; // Aes 160 bit CMAC
97 } /*__packed*/ REQUEST_V4
;
100 RESPONSE ResponseBase
; // Base response
101 BYTE MAC
[16]; // Aes 160 bit CMAC
102 } /*__packed*/ RESPONSE_V4
;
106 VERSION_INFO
; // unencrypted version info
108 REQUEST RequestBase
; // Base Request
109 BYTE Pad
[4]; // since this struct is fixed, we use fixed PKCS pad bytes
110 } /*__packed*/ REQUEST_V5
;
112 typedef REQUEST_V5 REQUEST_V6
; // v5 and v6 requests are identical
117 RESPONSE ResponseBase
;
118 BYTE RandomXoredIVs
[16]; // If RequestIV was used for decryption: Random ^ decrypted Request IV ^ ResponseIV. If NULL IV was used for decryption: Random ^ decrypted Request IV
119 BYTE Hash
[32]; // SHA256 of Random used in RandomXoredIVs
120 BYTE HwId
[8]; // HwId from the KMS server
121 BYTE XoredIVs
[16]; // If RequestIV was used for decryption: decrypted Request IV ^ ResponseIV. If NULL IV was used for decryption: decrypted Request IV.
122 BYTE HMAC
[16]; // V6 Hmac (low 16 bytes only), see kms.c CreateV6Hmac
123 //BYTE Pad[10]; // Pad is variable sized. So do not include in struct
124 } /*__packed*/ RESPONSE_V6
;
126 typedef struct { // not used except for sizeof(). Fields are the same as RESPONSE_V6
129 RESPONSE ResponseBase
;
130 BYTE RandomXoredIVs
[16];
132 } /*__packed*/ RESPONSE_V5
;
135 typedef struct { // Debug structure for direct casting of RPC data in debugger
138 RESPONSE_DEBUG ResponseBase
;
139 BYTE RandomXoredIVs
[16];
145 } __packed RESPONSE_V6_DEBUG
;
148 #define V4_PRE_EPID_SIZE ( \
149 sizeof(((RESPONSE*)0)->Version) + \
150 sizeof(((RESPONSE*)0)->PIDSize) \
153 #define V4_POST_EPID_SIZE ( \
154 sizeof(((RESPONSE*)0)->CMID) + \
155 sizeof(((RESPONSE*)0)->ClientTime) + \
156 sizeof(((RESPONSE*)0)->Count) + \
157 sizeof(((RESPONSE*)0)->VLActivationInterval) + \
158 sizeof(((RESPONSE*)0)->VLRenewalInterval) \
161 #define V6_DECRYPT_SIZE ( \
162 sizeof(((REQUEST_V6*)0)->IV) + \
163 sizeof(((REQUEST_V6*)0)->RequestBase) + \
164 sizeof(((REQUEST_V6*)0)->Pad) \
167 #define V6_UNENCRYPTED_SIZE ( \
168 sizeof(((RESPONSE_V6*)0)->Version) + \
169 sizeof(((RESPONSE_V6*)0)->IV) \
172 #define V6_PRE_EPID_SIZE ( \
173 V6_UNENCRYPTED_SIZE + \
174 sizeof(((RESPONSE*)0)->Version) + \
175 sizeof(((RESPONSE*)0)->PIDSize) \
178 #define V5_POST_EPID_SIZE ( \
179 V4_POST_EPID_SIZE + \
180 sizeof(((RESPONSE_V6*)0)->RandomXoredIVs) + \
181 sizeof(((RESPONSE_V6*)0)->Hash) \
184 #define V6_POST_EPID_SIZE ( \
185 V5_POST_EPID_SIZE + \
186 sizeof(((RESPONSE_V6*)0)->HwId) + \
187 sizeof(((RESPONSE_V6*)0)->XoredIVs) + \
188 sizeof(((RESPONSE_V6*)0)->HMAC) \
191 #define RESPONSE_RESULT_OK ((1 << 10) - 1) //(9 bits)
198 BOOL TimeStampOK
: 1;
199 BOOL ClientMachineIDOK
: 1;
202 BOOL DecryptSuccess
: 1;
203 BOOL HmacSha256OK
: 1;
204 BOOL PidLengthOK
: 1;
206 BOOL IVnotSuspicious
: 1;
211 uint32_t effectiveResponseSize
: 9;
212 uint32_t correctResponseSize
: 9;
216 typedef BYTE hwid_t
[8];
227 #define KMS_PARAM_MAJOR AppIndex
228 #define KMS_PARAM_REQUIREDCOUNT KmsIndex
230 #define APP_ID_WINDOWS 0
231 #define APP_ID_OFFICE2010 1
232 #define APP_ID_OFFICE2013 2
234 #define KMS_ID_VISTA 0
235 #define KMS_ID_WIN7 1
236 #define KMS_ID_WIN8_VL 2
237 #define KMS_ID_WIN_BETA 3
238 #define KMS_ID_WIN8_RETAIL 4
239 #define KMS_ID_WIN81_VL 5
240 #define KMS_ID_WIN81_RETAIL 6
241 #define KMS_ID_WIN2008A 7
242 #define KMS_ID_WIN2008B 8
243 #define KMS_ID_WIN2008C 9
244 #define KMS_ID_WIN2008R2A 10
245 #define KMS_ID_WIN2008R2B 11
246 #define KMS_ID_WIN2008R2C 12
247 #define KMS_ID_WIN2012 13
248 #define KMS_ID_WIN2012R2 14
249 #define KMS_ID_OFFICE2010 15
250 #define KMS_ID_OFFICE2013 16
251 #define KMS_ID_WIN_SRV_BETA 17
252 #define KMS_ID_OFFICE2016 18
253 #define KMS_ID_WIN10_VL 19
254 #define KMS_ID_WIN10_RETAIL 20
256 #define PWINGUID &AppList[APP_ID_WINDOWS].guid
257 #define POFFICE2010GUID &AppList[APP_ID_OFFICE2010].guid
258 #define POFFICE2013GUID &AppList[APP_ID_OFFICE2013].guid
260 typedef BOOL(__stdcall
*RequestCallback_t
)(const REQUEST
*const baseRequest
, RESPONSE
*const baseResponse
, BYTE
*const hwId
, const char* const ipstr
);
262 size_t CreateResponseV4(REQUEST_V4
*const Request
, BYTE
*const response_data
, const char* const ipstr
);
263 size_t CreateResponseV6(REQUEST_V6
*restrict Request
, BYTE
*const response_data
, const char* const ipstr
);
264 BYTE
*CreateRequestV4(size_t *size
, const REQUEST
* requestBase
);
265 BYTE
*CreateRequestV6(size_t *size
, const REQUEST
* requestBase
);
266 void randomPidInit();
267 void get16RandomBytes(void* ptr
);
268 RESPONSE_RESULT
DecryptResponseV6(RESPONSE_V6
* Response_v6
, int responseSize
, BYTE
* const response
, const BYTE
* const request
, BYTE
* hwid
);
269 RESPONSE_RESULT
DecryptResponseV4(RESPONSE_V4
* Response_v4
, const int responseSize
, BYTE
* const response
, const BYTE
* const request
);
270 void getUnixTimeAsFileTime(FILETIME
*const ts
);
271 __pure
int64_t fileTimeToUnixTime(const FILETIME
*const ts
);
272 const char* getProductNameHE(const GUID
*const guid
, const KmsIdList
*const List
, ProdListIndex_t
*const i
);
273 const char* getProductNameLE(const GUID
*const guid
, const KmsIdList
*const List
, ProdListIndex_t
*const i
);
274 __pure ProdListIndex_t
getExtendedProductListSize();
275 __pure ProdListIndex_t
getAppListSize(void);
277 extern const KmsIdList ProductList
[];
278 extern const KmsIdList AppList
[];
279 extern const KmsIdList ExtendedProductList
[];
281 extern RequestCallback_t CreateResponseBase
;
284 uint16_t IsValidLcid(const uint16_t Lcid
);