TExcelTAD
Home › Networking for Security: Packets, Protocols & Traffic Analysis › ARP Spoofing: Mechanism, Detection and Fix

ARP Spoofing: Mechanism, Detection and Fix

The previous lesson ended with a host overwriting its ARP entry for the gateway because an unsolicited reply told it to. That is the whole trick of ARP spoofing (also called ARP cache poisoning): a machine on the LAN sends forged ARP messages so that other hosts map someone else's IP address to the attacker's MAC. Their frames then go to the attacker, who can read them, change them, forward them on (a man-in-the-middle) or drop them (a denial of service). The attack needs a foothold on the same broadcast domain, which is why it matters most on shared office floors, guest Wi-Fi and flat networks. The overview is in Security Foundations' Man-in-the-Middle and Replay Attacks and DNS and ARP Spoofing; here you see the mechanism on a simulated LAN, find it in a capture, and fix it.

This lesson runs nothing against a real network: the "LAN" is a Python dictionary and the capture is the synthetic arp.pcap.

The mechanism

victim10.10.0.5 gateway10.10.0.1 :01 before: direct victim cache:10.10.0.1 = :66 gateway cache:10.10.0.5 = :66 attackerMAC :66 after poisoning both caches: every frame passes the attacker
  1. The attacker sends the victim a reply "10.10.0.1 is-at :66" and the gateway a reply "10.10.0.5 is-at :66".
  2. Both hosts overwrite their caches (ARP has no authentication; see ARP on the Wire).
  3. The attacker turns on IP forwarding, so traffic still flows and nobody notices an outage.
  4. Entries expire, so the attacker repeats the replies every few seconds.

A simulated LAN

The program models three hosts on one switch. Each has an ARP cache that, like a naive stack, accepts every reply. It then sends a few frames and prints the path they take, first on a clean LAN, then after poisoning, then on a switch that does dynamic ARP inspection (DAI): the switch checks every ARP message on untrusted ports against a binding table (built by DHCP snooping) and drops those that don't match.

python · try it yourself
MAC = {"victim": "02:00:00:0a:0a:05", "gateway": "02:00:00:0a:0a:01", "attacker": "02:00:00:0a:0a:66"}
IP = {"victim": "10.10.0.5", "gateway": "10.10.0.1", "attacker": "10.10.0.102"}
OWNER = {m: n for n, m in MAC.items()}

def lan(poison, dai):
    caches = {"victim": {IP["gateway"]: MAC["gateway"]}, "gateway": {IP["victim"]: MAC["victim"]}}
    bindings = {MAC[n]: IP[n] for n in MAC}          # DHCP-snooping table: MAC -> leased IP
    dropped = 0
    def arp_reply(to, sender_ip, sender_mac):
        nonlocal dropped
        if dai and bindings.get(sender_mac) != sender_ip:
            dropped += 1                              # switch drops the forged reply
            return
        caches[to][sender_ip] = sender_mac
    if poison:
        for _ in range(3):                            # repeated, as real attacks are
            arp_reply("victim", IP["gateway"], MAC["attacker"])
            arp_reply("gateway", IP["victim"], MAC["attacker"])
    def path(src, dst):
        hop = OWNER[caches[src][IP[dst]]]
        return f"{src} -> {dst}: " + (f"via {hop}" if hop != dst else "direct")
    return path("victim", "gateway"), path("gateway", "victim"), dropped

for title, poison, dai in [("clean LAN", False, False), ("poisoned", True, False), ("poisoned, DAI on", True, True)]:
    a, b, d = lan(poison, dai)
    print(f"{title:<17} {a:<32} {b:<32} forged replies dropped: {d}")
clean LAN         victim -> gateway: direct        gateway -> victim: direct        forged replies dropped: 0
poisoned          victim -> gateway: via attacker  gateway -> victim: via attacker  forged replies dropped: 0
poisoned, DAI on  victim -> gateway: direct        gateway -> victim: direct        forged replies dropped: 6

How it is detected

On the wire. The signs are an IP whose MAC changes, unsolicited replies, and one MAC claiming the IPs of other hosts. The sample capture arp.pcap has the classic pattern: a normal exchange, then five seconds later an unsolicited reply for the gateway from a new MAC. A detector in the style of arpwatch keeps the first MAC seen for each IP and alerts on changes. The session below does it with tshark and awk, entirely on the sample file:

bash · try it yourself
tshark -r $SAMPLES/pcap/arp.pcap -Y 'arp.opcode == 2' -T fields \
    -e frame.time_relative -e arp.src.proto_ipv4 -e arp.src.hw_mac |
awk -F'\t' '{ if (($2 in seen) && seen[$2] != $3)
                 printf "t=%ss ALERT %s changed %s -> %s\n", $1, $2, seen[$2], $3;
              else if (!($2 in seen)) { seen[$2] = $3; printf "t=%ss learn %s = %s\n", $1, $2, $3 } }'
t=0.000400000s learn 10.10.0.1 = 02:00:00:0a:0a:01
t=5.000000000s ALERT 10.10.0.1 changed 02:00:00:0a:0a:01 -> 02:00:00:0a:0a:66

On the hosts. A changed gateway MAC in ip neigh (Linux) or arp -a (Windows) compared with a known value; endpoint agents can alert on it. On the switch. DAI and port-security logs, and the same MAC appearing for many IPs in the switch's ARP or MAC tables.

False positives come from failover pairs (VRRP, HSRP and cluster IPs move between MACs on purpose), replaced network cards and VMs that migrate. Record those as expected.

How it is fixed or prevented

  • Dynamic ARP inspection with DHCP snooping on the access switches: ARP on untrusted ports must match a DHCP lease (or a static binding); uplinks to routers are marked trusted. This is the main fix on managed networks. A typical configuration, shown as a lab transcript for a switch in the 10.10.0.0/24 lab VLAN 10 (Cisco IOS-style syntax, where uplink-1 stands for the real interface name such as GigabitEthernet1/0/48; check your vendor's guide):
console
lab-switch(config)# ip dhcp snooping
lab-switch(config)# ip dhcp snooping vlan 10
lab-switch(config)# ip arp inspection vlan 10
lab-switch(config)# interface uplink-1
lab-switch(config-if)# ip dhcp snooping trust
lab-switch(config-if)# ip arp inspection trust
lab-switch(config-if)# end
lab-switch# show ip arp inspection statistics vlan 10
 Vlan   Forwarded   Dropped   DHCP Drops   ACL Drops
 ----   ---------   -------   ----------   ---------
   10        1842         6            6           0
  • Static ARP entries for a few critical mappings (the gateway on a server, for example). On Linux: ip neigh replace 10.10.0.1 lladdr 02:00:00:0a:0a:01 dev eth0 nud permanent (needs root, so not runnable in the sandbox). They don't scale and must be updated when hardware changes.
  • Smaller broadcast domains: VLANs per group, private VLANs or client isolation on Wi-Fi, so an attacker can reach fewer victims.
  • Encrypt above the link: TLS, SSH, IPsec or WireGuard make a successful man-in-the-middle see only ciphertext, and certificate checks make it fail loudly. This doesn't stop the redirection or a denial of service, so it complements DAI.
  • 802.1X port authentication keeps unknown machines off the LAN in the first place.

Pitfalls

  • Turning on DAI without DHCP snooping or static bindings: every ARP message from statically addressed hosts is then dropped and the network breaks.
  • Forgetting to mark uplinks trusted, with the same result.
  • Assuming TLS makes ARP spoofing harmless. It protects confidentiality and integrity, but plaintext protocols on the same LAN (DNS, HTTP, SMB without signing) are still exposed.
  • Ignoring IPv6. Neighbor Discovery has the same weakness (see IPv6 Basics).

Practice

1. In the "poisoned" line, why does the attacker need to poison both caches?

Poisoning only the victim captures victim → gateway traffic; replies from the gateway still go straight to the victim. For a full man-in-the-middle (both directions, e.g. to read responses or modify them) both mappings must point to the attacker.

2. Change the simulation so the attacker forges replies with its own true IP but the gateway's MAC. Does DAI drop them?

Yes. Those messages would say "10.10.0.102 is-at 02:00:00:0a:0a:01", which doesn't match the binding either (the binding maps :01 to 10.10.0.1), so DAI drops them too: it checks the (MAC, IP) pair, not just one field.

3. The awk detector alerts on the first change only. What would you add for a production detector?

Alert on every change and on flip-flops back to an old MAC, rate-limit repeats, add an allow list for failover pairs, and also flag one MAC claiming several IPs and gratuitous ARP for the gateway.

Test yourself

What does an attacker need for ARP spoofing?

  1. Only the victim's public IP address
  2. A machine on the same broadcast domain (LAN or VLAN)
  3. Root access on the gateway
  4. A valid TLS certificate

Which switch feature drops ARP messages whose sender MAC and IP don't match the DHCP snooping bindings?

  1. Port mirroring
  2. Dynamic ARP inspection
  3. Spanning tree
  4. LLDP

In the awk detection on arp.pcap, when is the alert raised?

  1. At t = 0, for the request
  2. At t = 0.0004, for the first reply
  3. At t = 5, when 10.10.0.1 appears with a new MAC
  4. Never

Which of these is a common false positive for an ARP-change detector?

  1. A failover pair moving a virtual IP between MACs
  2. A DNS query
  3. A TLS handshake
  4. An HTTP redirect