-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiDecrypt.py
More file actions
53 lines (40 loc) · 1.67 KB
/
MultiDecrypt.py
File metadata and controls
53 lines (40 loc) · 1.67 KB
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
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.backends import default_backend
from cryptography.fernet import Fernet, InvalidToken
import base64
def decrypt_and_run(encrypted_data: bytes, password: str):
salt_size = 16
encrypted_code_length = 140
segment_size = salt_size + encrypted_code_length
position = 0
while position < len(encrypted_data):
salt = encrypted_data[position:position + salt_size]
encrypted_code = encrypted_data[position + salt_size:position + segment_size]
position += segment_size
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=salt,
iterations=100000,
backend=default_backend()
)
key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
fernet = Fernet(key)
try:
decrypted_code = fernet.decrypt(encrypted_code).decode()
print("Decrypted code:")
print(decrypted_code)
# write the file, can be removed, file will work from memory
with open("extract.py", "w") as output_file:
output_file.write(decrypted_code)
# write the file, can be removed, file will work from memory
exec(decrypted_code)
return
except InvalidToken:
continue
print("Invalid password or no matching encrypted segment.")
with open("encrypted_code.bin", "rb") as file:
encrypted_data = file.read()
password = input("Enter the password to decrypt and run the script: ")
decrypt_and_run(encrypted_data, password)