-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
337 lines (279 loc) · 10.7 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import subprocess
from base64 import urlsafe_b64encode
from datetime import datetime
from cryptography.fernet import Fernet
import hashlib
import requests
import math
import os
from time import time
import dill
import sys
keyba = None
ver = sys.version_info
out = sys.stdout.flush
import base64
from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad, unpad
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import rsa, padding
def encrypt_with_public_key(message, public_key):
public_key = serialization.load_pem_public_key(public_key)
ciphertext = public_key.encrypt(
message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None,
),
)
ciphertext = base64.encodebytes(ciphertext)
return ciphertext
def decrypt_with_private_key(message, private_key):
private_key = serialization.load_pem_private_key(private_key, password=None)
plaintext = private_key.decrypt(
base64.decodebytes(message),
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None,
),
)
return plaintext.decode()
def hex_to_str(x):
return "".join([chr(int(x[i : i + 2], 16)) for i in range(0, len(x), 2)])
def str_to_hex(s):
return "".join([("0" + hex(ord(c)).split("x")[1])[-2:] for c in s])
def create_license(message):
key = base64.decodebytes(keyba)
cipher = AES.new(key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(message.encode("utf-8"))
encrypted_key = base64.b64encode(ciphertext + tag).decode("utf-8")
decoded_key = base64.b64decode(encrypted_key)
ciphertext = decoded_key[:-16]
tag = decoded_key[-16:]
cipher = AES.new(key, AES.MODE_EAX, nonce=cipher.nonce)
original_message = cipher.decrypt(ciphertext).decode("utf-8")
return ciphertext, tag, original_message, encrypted_key, key, cipher
def check(encrypted_key, cipher, ciphertext):
key = base64.decodebytes(keyba)
decoded_key = base64.b64decode(encrypted_key)
ciphertext = decoded_key[:-16]
cipher = AES.new(key, AES.MODE_EAX, nonce=cipher.nonce)
original_message = cipher.decrypt(ciphertext).decode("utf-8")
return original_message
def get_k(myprod):
ciphertext, tag, original_message, encrypted_key, key, cipher = create_license(
myprod
)
a = (
dill.dumps(
[
ciphertext,
tag,
original_message,
encrypted_key,
key,
]
),
cipher,
)
serialnumber, b = a
baaa = base64.b64encode(serialnumber).decode("utf-8")
return str_to_hex(baaa)
def get_infos_from_serial(serialnumberk):
serialnumber = base64.b64decode(hex_to_str(serialnumberk).encode())
myprod = dill.loads(serialnumber)[2]
ciphertext, tag, original_message, encrypted_key, key, cipher = create_license(
myprod
)
orgmessage = check(encrypted_key, cipher, ciphertext)
p, d, ts, otherinformation = original_message.split("####")
d = int(d)
ts = int(ts)
duid = {}
duid["ciphertext"] = ciphertext
duid["tag"] = tag
duid["original_message"] = original_message
duid["encrypted_key"] = encrypted_key
duid["key"] = key
duid["cipher"] = cipher
duid["orgmessage"] = orgmessage
duid["days"] = d
duid["timestamp"] = ts
duid["daysleft"] = math.ceil(((duid["timestamp"] + d * 86400) - time()) / 86400)
duid["product"] = p
duid["otherinformation"] = otherinformation
duid["cipher"] = duid["cipher"].__dict__["nonce"]
return duid
def get_key_from_uuid(rev=False):
uuid = get_machine_id()
if rev:
uuid = uuid[::-1]
key = hashlib.sha256(uuid).digest()
key = urlsafe_b64encode(key)
padding = b"=" * (32 - len(key))
key += padding
cipher = Fernet(key)
return cipher
def encrypt(cipher, message):
encrypted_message = cipher.encrypt(message)
return encrypted_message
def decrypt(cipher, encrypted_message):
decrypted_message = cipher.decrypt(encrypted_message)
return decrypted_message
def download_message_and_decrypt(link, password=None):
# if password:
# headers2 = {
# "X-Decrypt-Password": password,
# }
# response2 = requests.get(link, headers=headers2)
# else:
response2 = requests.get(link)
return response2
def get_machine_id():
return sorted(
subprocess.run(
[
os.path.normpath(
os.path.join(
os.path.dirname(os.environ.get("comspec")), "wbem", "wmic.exe"
)
),
"csproduct",
"get",
"UUID",
],
capture_output=True,
).stdout.splitlines(),
key=lambda x: len(x),
)[-1].strip()
def open_serial_number_file(filepath, decy):
with open(filepath, mode="rb") as f:
data = f.read()
data = decrypt(decy, data)
return data.strip()
class Cryptor:
# https://stackoverflow.com/a/75713952/15096247
def __init__(self, key):
self.SECRET_KEY = str(key).encode("utf-8")
self.BLOCK_SIZE = 32
self.CIPHER = AES.new(self.SECRET_KEY, AES.MODE_ECB)
def encrypt(self, text):
text = str(text).encode("utf-8")
return base64.b64encode(self.CIPHER.encrypt(pad(text, self.BLOCK_SIZE))).decode(
"utf-8"
)
def decrypt(self, encoded_text):
self.CIPHER = AES.new(self.SECRET_KEY, AES.MODE_ECB)
return unpad(
self.CIPHER.decrypt(base64.b64decode(encoded_text)), self.BLOCK_SIZE
).decode("utf-8")
def get_internet_datetime(time_zone: str = "etc/utc"):
timeapi_url = "https://www.timeapi.io/api/Time/current/zone"
headers = {
"Accept": "application/json",
}
params = {"timeZone": time_zone}
try:
request = requests.get(timeapi_url, headers=headers, params=params)
r_dict = request.json()
dt = datetime(
year=r_dict["year"],
month=r_dict["month"],
day=r_dict["day"],
hour=r_dict["hour"],
minute=r_dict["minute"],
second=r_dict["seconds"],
microsecond=r_dict["milliSeconds"] * 1000,
).timestamp()
except Exception:
try:
t = requests.get("http://just-the-time.appspot.com/").content
dt = int(datetime.fromisoformat(t.decode("utf-8").strip()).timestamp())
except Exception as fe:
return 0
return dt
def check_serial(
hardcodedpasswort_transfer,
hardcodedpasswort_url,
serialnumber,
notvalidanymore=f"The license you're using is not valid anymore. It expired %s day[s] ago",
stillvalid=f"The license you're using is valid for %s more day[s].",
serialusedanotherpc="The license has been used on another PC",
):
global keyba
signature_hex = serialnumber[-32:]
serialnumber = serialnumber[:-32]
byx = bytes.fromhex(signature_hex)
keyba = base64.encodebytes(byx)
cipher2 = get_key_from_uuid()
cipher2rev = get_key_from_uuid(rev=True)
serialnumber = hex_to_str(serialnumber)
cryptor = Cryptor(hardcodedpasswort_url)
decryptedurl = cryptor.decrypt(serialnumber)
serialfile = os.path.normpath(os.path.join(os.path.dirname(__file__), "reglic.bin"))
try:
with requests.get(url=decryptedurl, timeout=30) as response:
cont = response.content
if response.status_code == 200:
with open(serialfile, mode="wb") as f:
f.write(encrypt(cipher2rev, cont))
except Exception as fe:
pass
serialnumberk = open_serial_number_file(filepath=serialfile, decy=cipher2rev)
duid = get_infos_from_serial(serialnumberk)
link, filehash, privkeyent, *_ = duid["otherinformation"].split("ÇÇÇ")
licensefileonhdd = os.path.normpath(
os.path.join(os.path.dirname(__file__), "mylicense_reglic.bin")
)
try:
res = download_message_and_decrypt(link, password=hardcodedpasswort_transfer)
if res.status_code == 200:
with open(licensefileonhdd, mode="wb") as f:
cryptkey = res.content
randomcode = os.urandom(16).decode("utf-8", "ignore")
enc = encrypt_with_public_key(randomcode.encode(), privkeyent.encode())
dec = decrypt_with_private_key(enc, cryptkey)
if randomcode == dec:
maid = get_machine_id()
duid["hardwareid"] = encrypt(cipher2rev, maid)
duid["sno"] = serialnumberk
mess2 = dill.dumps(duid)
emcry = encrypt(cipher2, mess2)
f.write(emcry)
except Exception:
pass
with open(licensefileonhdd, mode="rb") as f:
datax = f.read()
duid2 = dill.loads(decrypt(cipher2, datax))
isonrightmachine = get_machine_id() == decrypt(cipher2rev, duid2["hardwareid"])
if isonrightmachine:
if duid2["timestamp"] - duid["timestamp"] == 0:
for k in set(duid.keys()) & set(duid2.keys()):
if k not in ["sno"]:
continue
if duid[k] != duid2[k]:
return False, None, None, None, None
else:
timen = get_internet_datetime(time_zone="etc/utc")
durationoflic = duid["days"]
product = duid["product"]
otherinfos = duid["otherinformation"].split("ÇÇÇ")[3:]
dli = duid["timestamp"] + (duid["days"] * 86400) - timen
daysleft = math.ceil(dli / 86400)
if daysleft < 0:
if "%d" in notvalidanymore:
print(notvalidanymore % abs(daysleft))
else:
print(notvalidanymore)
return False, daysleft, durationoflic, product, otherinfos
else:
if "%d" in stillvalid:
print(stillvalid % abs(daysleft))
else:
print(stillvalid)
return True, daysleft, durationoflic, product, otherinfos
else:
print(serialusedanotherpc)
return False, None, None, None, None