Domain Generation Algorithm (DGA)

Domain Generation Algorithm (DGA)

One-liner: An algorithm that dynamically generates large numbers of domain names for C2 communication, making it difficult to block or take down attacker infrastructure.

🎯 What Is It?

A Domain Generation Algorithm (DGA) is a technique used by malware to evade domain blocking and C2 takedowns. Instead of hardcoding a single C2 domain, the malware generates thousands of pseudo-random domain names using a shared algorithm. The attacker only needs to register a few of these domains to maintain communication.

πŸ”¬ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Malware       β”‚                    β”‚    Attacker      β”‚
β”‚                  β”‚                    β”‚                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚    DGA     β”‚  β”‚     Same           β”‚  β”‚    DGA     β”‚  β”‚
β”‚  β”‚ Algorithm  β”‚  β”‚   Algorithm        β”‚  β”‚ Algorithm  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚                    β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚        β”‚         β”‚                    β”‚        β”‚         β”‚
β”‚        β–Ό         β”‚                    β”‚        β–Ό         β”‚
β”‚  abc123.com      β”‚                    β”‚  abc123.com ◄──Register 1-2%
β”‚  xyz789.net      β”‚                    β”‚  xyz789.net      β”‚
β”‚  qwe456.org      β”‚    Matches!        β”‚  qwe456.org      β”‚
β”‚  ...             β”‚                    β”‚  ...             β”‚
β”‚  (50,000/day)    β”‚                    β”‚  (50,000/day)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                                       β”‚
         └───────────Connects to registeredβ”€β”€β”€β”€β”€β”€β”˜
                     domains for C2

DGA Types

Type Description Example
Time-based Uses current date/time as seed Conficker
Dictionary-based Combines real words Suppobox
Hash-based Cryptographic hash of seed Necurs
Arithmetic Mathematical operations CryptoLocker

Simple DGA Example (Python)

import datetime
import hashlib

def generate_domains(date, count=10):
    domains = []
    for i in range(count):
        seed = f"{date.year}{date.month}{date.day}{i}"
        domain = hashlib.md5(seed.encode()).hexdigest()[:12]
        domains.append(f"{domain}.com")
    return domains

# Both malware and attacker generate same domains for today
today = datetime.date.today()
print(generate_domains(today))

πŸ“Š Notable DGA Malware

Malware Domains/Day Algorithm Type
Conficker 50,000 Time-based
CryptoLocker 1,000 Time-based
Necurs 2,048 Hash-based
Dyre 1,000 Dictionary-based
Emotet Variable Multiple seeds

πŸ›‘οΈ Detection & Prevention

How to Detect

Detection Indicators

Legitimate domain: google.com (low entropy, known)
DGA domain: a3f8k2m9p1q4.com (high entropy, unknown)

Red flags:
- Long, random-looking domain names
- High NXDOMAIN rate from single host
- Queries to many TLDs (.com, .net, .org, .info)
- Regular timing patterns in DNS queries

How to Prevent / Mitigate

🎀 Interview Angles

Common Questions

Key Talking Points

βœ… Best Practices

πŸ“š References