DNS Firewall and Proxy Logs: Detect C2 Activity
In this article
DNS firewall and proxy logs are a powerful early-warning system for command-and-control (C2) activity. Attackers often use domain names to connect their malware to a controller, and those connections leave traces in your DNS and web proxy logs. This guide explains how to analyze those logs to spot suspicious patterns and respond before a breach worsens.
What You'll Need
- Access to DNS query logs (from your DNS server, firewall, or a cloud DNS service)
- Access to proxy logs (from your web proxy or secure web gateway)
- A log analysis tool (e.g., a SIEM, grep/awk on Linux, or even Excel for small datasets)
- Basic understanding of DNS and HTTP concepts
- Optional: a threat intelligence feed or a list of known malicious domains
Step-by-Step
- Collect and centralize logs. Ensure DNS and proxy logs are being recorded and stored in a central location. If you don't have them, enable logging on your DNS server and proxy. For DNS, log at least the timestamp, client IP, query name, and response. For proxy, log timestamp, client IP, URL, and status code.
- Look for high-frequency queries to a single domain. C2 malware often "beacons" by querying the same domain at regular intervals. Use a script or SIEM query to count queries per domain per hour. Flag domains that appear more than, say, 10 times an hour from a single client.
- Check for domains with low entropy or unusual patterns. C2 domains often use random-looking subdomains (e.g.,
a1b2c3.example.com). Calculate the entropy of the domain labels; a high entropy (above 3.5 bits per character) is suspicious. Also look for domains with many subdomains that are rarely repeated. - Identify domains that are newly registered or short-lived. If your logs include the first-seen date, flag domains that were first seen in the last 30 days. C2 domains are often short-lived. Cross-reference with WHOIS data if possible.
- Look for DNS queries for domains that don't resolve. Malware may query domains that are used only for C2 and are taken down. A high number of NXDOMAIN responses from a single client can indicate C2 attempts.
- Examine proxy logs for connections to unusual ports or protocols. C2 traffic often uses non-standard ports (e.g., 8080, 4444) or protocols like HTTPS to blend in. Flag outbound connections to ports other than 80 and 443, especially if the destination is not a known cloud provider.
- Correlate DNS and proxy logs. For each suspicious domain from DNS, check if there are corresponding proxy log entries. A match confirms the client actually connected to the domain, which is more serious than a DNS query alone.
- Check for long-lived connections. C2 sessions often stay open for hours. In proxy logs, look for connections that last longer than, say, 30 minutes, especially if the data transfer volume is low (a sign of beaconing).
- Use threat intelligence feeds. If you have a feed of known malicious domains, automatically compare your logs against it. Many free and commercial feeds are available. Even a simple list of known C2 domains can be checked with a grep command.
- Investigate and respond. When you find a suspicious match, verify by checking the client machine for other signs of compromise (e.g., unusual processes, registry entries). Then isolate the machine, block the domain at the firewall, and continue monitoring.
Common Mistakes
- Ignoring false positives. Not every unusual domain is malicious. CDNs, dynamic DNS, and legitimate software updates can look suspicious. Always verify before blocking.
- Only looking at proxy logs. Many C2 channels use DNS as a covert channel (e.g., DNS tunneling), which never appears in proxy logs. Always analyze DNS logs too.
- Not correlating logs. A DNS query alone doesn't mean the malware connected. Correlate with proxy logs to confirm.
- Overlooking outbound connections to IP addresses. Some C2 uses direct IP connections instead of domains. Check proxy logs for connections to IPs that are not in your allowlist.
- Not setting a baseline. Without knowing what normal traffic looks like, you'll be overwhelmed by alerts. Establish a baseline of typical DNS and proxy activity first.
Tips
- Automate with a SIEM. If you have a SIEM, create rules that trigger on high-frequency DNS queries or proxy connections to known-bad IPs. This reduces manual work.
- Use a domain reputation service. Many services offer free API checks for domain reputation. You can script a check for any domain that exceeds your threshold.
- Monitor for DNS tunneling. Look for DNS queries with very long subdomains (e.g., > 50 characters) or a high volume of TXT records. These are signs of DNS tunneling.
- Keep logs long enough. C2 activity may be intermittent. Keep logs for at least 90 days to allow for retrospective analysis.
- Document your thresholds. Write down what you consider suspicious (e.g., 10 queries/hour) so that you can adjust and share with your team.
Troubleshooting
- No logs available. If you don't have logs, enable logging on your DNS server and proxy. For Windows DNS, enable debug logging; for Linux, use syslog. For proxies, ensure access logs are turned on.
- Logs are too large to analyze. Use command-line tools like
grep,awk, andsortto filter and aggregate. For example, to count queries per domain:awk '{print $5}' dns.log | sort | uniq -c | sort -nr | head -20(adjust field numbers to your log format). - Too many false positives. Refine your thresholds. Instead of flagging any domain with high entropy, compare against a list of known good domains. Also, consider the context: a domain that is also used by a popular service is less suspicious.
- You find a match but can't confirm. Use a sandbox to run the suspicious file or use a network analyzer to capture traffic from the affected host. Also, check the host's running processes and scheduled tasks.
- Proxy logs don't show the connection. Some C2 traffic uses non-HTTP protocols (e.g., raw TCP, SSH). If you suspect C2, capture network traffic with a tool like Wireshark on the host or a network tap.
Frequently Asked Questions
- What is a typical C2 beacon interval? It varies, but common intervals are every 1-5 minutes, hourly, or daily. Look for regularity, not just frequency.
- Can C2 traffic be encrypted? Yes, many C2 channels use HTTPS or DNS over HTTPS to hide. In that case, you can't see the payload, but you can still see the domain and connection patterns.
- How do I know if a domain is malicious? Cross-reference with threat intelligence feeds, check the domain's age and reputation, and look for patterns like random subdomains. If in doubt, block it temporarily and monitor.
- What if the C2 uses an IP address instead of a domain? Then DNS logs won't help. Look in proxy logs for outbound connections to unusual IPs, especially on non-standard ports.
- How long should I keep logs? At least 90 days for security analysis, but check your compliance requirements. Longer is better for retrospective hunting.
- Can I use free tools to analyze logs? Yes, you can use grep, awk, and Excel. For more advanced analysis, consider open-source SIEMs like Wazuh or the ELK stack.