DHCP and Rogue DHCP Servers
When a laptop joins a network, it doesn't know its address, its gateway or its DNS server. It broadcasts a question and takes the configuration from whichever DHCP server answers first. Whoever answers controls the two settings that matter most for security: the default gateway (where all off-subnet traffic goes) and the DNS server (who decides what every name means). A rogue DHCP server, malicious or just a misconfigured home router plugged into an office port, can put itself in both positions for every client that boots. DHCP itself is covered in DHCP.
The capture in this lesson is synthetic and built in the sandbox; nothing is sent on a network.
DORA, and what an offer carries
| Step | Message | From → to | Key fields |
|---|---|---|---|
| D | DISCOVER | client 0.0.0.0:68 → broadcast :67 |
client MAC (chaddr), transaction ID (xid) |
| O | OFFER | server → client | offered address (yiaddr), option 54 server identifier, option 3 router, option 6 DNS servers, option 51 lease time |
| R | REQUEST | client → broadcast | which server's offer it accepts (option 54) |
| A | ACK | that server → client | the final lease |
There is no authentication: the client has no way to tell a legitimate server from any other machine on the broadcast domain, and it usually accepts the first offer.
A rogue offer in a capture
The session builds a capture of one client booting on the lab network. The legitimate server 10.10.0.2 offers the real gateway and DNS; a second machine, 10.10.0.102, answers 2 ms faster and names itself as gateway and DNS server, with a 60-second lease (so it can keep renewing control). Then the client requests the faster offer.
python3 - <<'PY'
from scapy.all import Ether, IP, UDP, BOOTP, DHCP, wrpcap
t0, pkts = 1768471200.0, []
cli = "02:00:00:0a:0a:30"
ch = bytes.fromhex(cli.replace(":", ""))
def add(p, dt):
p.time = t0 + dt; pkts.append(p)
def offer(mac, server, addr, router, dns, lease):
return (Ether(src=mac, dst=cli)/IP(src=server, dst=addr)/UDP(sport=67, dport=68)/BOOTP(op=2, yiaddr=addr, chaddr=ch, xid=0x1001)
/DHCP(options=[("message-type", "offer"), ("server_id", server), ("router", router), ("name_server", dns), ("lease_time", lease), "end"]))
bcast = Ether(src=cli, dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0", dst="255.255.255.255")/UDP(sport=68, dport=67)
add(bcast/BOOTP(chaddr=ch, xid=0x1001)/DHCP(options=[("message-type", "discover"), "end"]), 0)
add(offer("02:00:00:0a:0a:66", "10.10.0.102", "10.10.0.131", "10.10.0.102", "10.10.0.102", 60), 0.002) # rogue
add(offer("02:00:00:0a:0a:02", "10.10.0.2", "10.10.0.130", "10.10.0.1", "10.10.0.53", 86400), 0.004) # real
add(bcast/BOOTP(chaddr=ch, xid=0x1001)/DHCP(options=[("message-type", "request"), ("server_id", "10.10.0.102"),
("requested_addr", "10.10.0.131"), "end"]), 0.010)
wrpcap("dhcp.pcap", pkts)
PY
tshark -r dhcp.pcap -T fields -E header=y -e frame.number -e dhcp.option.dhcp -e eth.src -e dhcp.option.dhcp_server_id \
-e dhcp.ip.your -e dhcp.option.router -e dhcp.option.domain_name_server -e dhcp.option.ip_address_lease_timeframe.number dhcp.option.dhcp eth.src dhcp.option.dhcp_server_id dhcp.ip.your dhcp.option.router dhcp.option.domain_name_server dhcp.option.ip_address_lease_time
1 1 02:00:00:0a:0a:30 0.0.0.0
2 2 02:00:00:0a:0a:66 10.10.0.102 10.10.0.131 10.10.0.102 10.10.0.102 60
3 2 02:00:00:0a:0a:02 10.10.0.2 10.10.0.130 10.10.0.1 10.10.0.53 86400
4 3 02:00:00:0a:0a:30 10.10.0.102 0.0.0.0
Message type 1 is DISCOVER, 2 OFFER, 3 REQUEST. Two offers for one DISCOVER is already unusual on a network with a single DHCP server, and the content is worse: the first offer names its own address as router and DNS, and the client's REQUEST (frame 4) accepts it.
The detector
A detector needs one piece of configuration, the list of authorised DHCP servers, and then checks every OFFER and ACK. It also catches the other DHCP attack, starvation: one port sending DISCOVERs with many random client MACs until the real server's pool is empty (often the first step before running a rogue server, so clients have nobody else to ask).
from collections import Counter
AUTHORISED = {"10.10.0.2": {"router": "10.10.0.1", "dns": "10.10.0.53"}}
events = [ # (time, type, switch port, src MAC, server id, router, dns): decoded from DHCP traffic
(0.000, "DISCOVER", "gi1/0/12", "02:00:00:0a:0a:30", None, None, None),
(0.002, "OFFER", "gi1/0/31", "02:00:00:0a:0a:66", "10.10.0.102", "10.10.0.102", "10.10.0.102"),
(0.004, "OFFER", "uplink-1", "02:00:00:0a:0a:02", "10.10.0.2", "10.10.0.1", "10.10.0.53"),
] + [(5 + i * 0.01, "DISCOVER", "gi1/0/40", f"02:aa:{i:02x}:00:00:01", None, None, None) for i in range(200)]
for t, kind, port, mac, server, router, dns in events:
if kind not in ("OFFER", "ACK"):
continue
good = AUTHORISED.get(server)
if not good:
print(f"t={t:.3f} ROGUE {kind} from {server} ({mac}) on port {port}: router={router} dns={dns}")
elif (router, dns) != (good["router"], good["dns"]):
print(f"t={t:.3f} authorised server {server} hands out unexpected options: router={router} dns={dns}")
macs_per_port = Counter(port for _, kind, port, *_ in events if kind == "DISCOVER")
for port, n in macs_per_port.items():
if n > 20:
print(f"port {port}: {n} DISCOVERs from {n} different MACs in 2 s: DHCP starvation")t=0.002 ROGUE OFFER from 10.10.0.102 (02:00:00:0a:0a:66) on port gi1/0/31: router=10.10.0.102 dns=10.10.0.102
port gi1/0/40: 200 DISCOVERs from 200 different MACs in 2 s: DHCP starvation
The useful details for the response are the switch port (where to unplug) and the MAC. Real detections get these from the switch's DHCP-snooping log or from a sensor on a SPAN port.
How it is detected in practice
- DHCP snooping violation logs on switches: an OFFER or ACK arriving on an untrusted port.
- Network sensors (IDS rules, Zeek's
dhcp.log) listing every server identifier seen, compared with the authorised list. - Clients with the wrong gateway or DNS in endpoint telemetry, or many clients suddenly using a DNS server you don't run.
- Pool exhaustion alarms on the real server and many leases for random MACs (starvation).
How it is prevented
- DHCP snooping on access switches: DHCP server messages are accepted only on trusted ports (uplinks towards the real server); everything else is dropped. It also builds the binding table (MAC, IP, port, VLAN) that dynamic ARP inspection and IP source guard use (ARP Spoofing).
- Rate-limit DHCP per port and port security (few MACs per port) against starvation.
- 802.1X so unknown devices don't get on the network at all.
- For IPv6, the same role is played by Router Advertisements and DHCPv6: use RA Guard and DHCPv6 Guard (IPv6).
- Applications that verify the server they talk to (TLS certificates, SSH host keys) limit the damage of a hijacked gateway or DNS server.
Pitfalls
- Enabling DHCP snooping without marking the uplink trusted: the real server's offers are dropped and nobody gets an address.
- Forgetting DHCP relay (option 82) interactions: some switches drop relayed packets with option 82 unless configured.
- Treating every unknown DHCP server as an attack. The most common rogue server is a consumer router plugged in backwards. It still breaks the network; find the port and remove it.
Practice
1. Why does the rogue server use a 60-second lease?
Clients renew at half the lease time, every 30 seconds, by talking to the server that granted the lease. A short lease keeps the clients coming back to the rogue server and lets it change their settings quickly; it also produces unusual renewal traffic, which helps detection.
2. Why is DHCP starvation often combined with a rogue server?
Once the real pool is empty, the real server can't answer, so the rogue server is the only one that offers addresses and wins every client, not just the ones it beats in the race.
3. The detector printed nothing for the legitimate offer. Extend it to warn when an authorised server offers a lease shorter than 1 hour.
Add the lease time to the event tuple and, for authorised servers, print a warning when lease < 3600. A sudden change in lease time from a known server can mean the server was reconfigured or compromised.
Test yourself
Which two DHCP options give a rogue server control over a client's traffic?
- Lease time and hostname
- Router (option 3) and DNS servers (option 6)
- Server identifier and subnet mask
- Client identifier and broadcast address
In the capture, which offer does the client accept?
- The legitimate one from 10.10.0.2
- The rogue one from 10.10.0.102, which arrived first
- Neither
- Both
What does DHCP snooping do?
- Encrypts DHCP
- Drops DHCP server messages on untrusted ports and records lease bindings
- Gives every client a static address
- Blocks DNS
What is DHCP starvation?
- A server with too few options
- Exhausting the server's address pool with DISCOVERs from many fake MACs
- A lease longer than one day
- A client that never renews