forked from The404Hacking/EggShell-RAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathESEncryptor.py
More file actions
61 lines (48 loc) · 1.72 KB
/
Copy pathESEncryptor.py
File metadata and controls
61 lines (48 loc) · 1.72 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
54
55
56
57
58
59
#ESEncryptor
#created by lucas.py
import base64
try:
from Crypto import Random
from Crypto.Cipher import AES
except:
print "Make sure you have pycrypto installed\nTry running 'easy_install pycrypto'"
exit()
#decode bytes
class ESEncryptor:
def __init__(self, key=None, BS=None):
self.iv = "\x00" * 16
self.key = key
self.BS = (BS if BS else None)
def _pad(self, s):
return s + (self.BS - len(s) % self.BS) * chr(self.BS - len(s) % self.BS)
def _unpad(self, s):
return s[:-ord(s[len(s)-1:])]
def decrypt(self, enc):
if len(enc) == 0:
return ""
enc = base64.b64decode(enc)
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
return self._unpad(cipher.decrypt(enc).decode('utf-8'))
def encode(self, raw, BS=16):
raw = self._pad(raw)
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
return base64.b64encode(cipher.encrypt(raw))
def encryptString(self, string):
return self.encode(string)
#file handling
def decryptFile(self, fileinname, fileoutname, fileSize,password=0):
password = self.key if password == 0 else password
aes = AES.new(password, AES.MODE_CBC, self.iv)
in_file = open(fileinname,"rb")
encryptedData = in_file.read()
#trim
offset = len(encryptedData) - fileSize
encryptedData = encryptedData[offset:]
in_file.close()
#decrypt,get length
decryptedData = self._unpad(aes.decrypt(encryptedData))
#write data subtracting the offset
out_file = open(fileoutname,'a+b')
out_file.write(decryptedData)
out_file.close()
return True