Skip to content

Commit 8a4bb72

Browse files
committed
Added compression via zlib. Can be turned on in the config file.
1 parent 2774289 commit 8a4bb72

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

config-sample.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
"max_time_sleep": 10,
4343
"min_time_sleep": 1,
4444
"max_bytes_read": 400,
45-
"min_bytes_read": 300
46-
}
45+
"min_bytes_read": 300,
46+
"compression": 1
47+
}

det.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
from os import listdir
1515
from os.path import isfile, join
1616
from Crypto.Cipher import AES
17+
from zlib import compress, decompress
1718

1819
KEY = ""
1920
MIN_TIME_SLEEP = 1
2021
MAX_TIME_SLEEP = 30
2122
MIN_BYTES_READ = 1
2223
MAX_BYTES_READ = 500
24+
COMPRESSION = True
2325
files = {}
2426
threads = []
2527
config = None
@@ -189,6 +191,8 @@ def retrieve_file(self, jobid):
189191
os.path.pathsep, ''), time.strftime("%Y-%m-%d.%H:%M:%S", time.gmtime()))
190192
content = ''.join(str(v) for v in files[jobid]['data']).decode('hex')
191193
content = aes_decrypt(content, self.KEY)
194+
if COMPRESSION:
195+
content = decompress(content)
192196
f = open(filename, 'w')
193197
f.write(content)
194198
f.close()
@@ -252,7 +256,10 @@ def run(self):
252256
# sending the data
253257
f = tempfile.SpooledTemporaryFile()
254258
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))
256263
f.seek(0)
257264
e.close()
258265

@@ -289,7 +296,7 @@ def signal_handler(bla, frame):
289296

290297

291298
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
293300
global threads, config
294301

295302
parser = argparse.ArgumentParser(
@@ -324,6 +331,7 @@ def main():
324331
MAX_TIME_SLEEP = int(config['max_time_sleep'])
325332
MIN_BYTES_READ = int(config['min_bytes_read'])
326333
MAX_BYTES_READ = int(config['max_bytes_read'])
334+
COMPRESSION = bool(config['compression'])
327335
KEY = config['AES_KEY']
328336
app = Exfiltration(results, KEY)
329337

@@ -365,4 +373,4 @@ def main():
365373
break
366374

367375
if __name__ == '__main__':
368-
main()
376+
main()

0 commit comments

Comments
 (0)