Sub topic 13
MAC Spoofing, ARP Spoofing, and Basic Defenses
This chapter assumes you know how ARP resolves IPv4 addresses to MAC addresses, how a switch builds its MAC table, and how to read ip neigh show output. It covers where these mechanisms can be abused and what defenses exist.
Why LAN identity is weak
A MAC address is not authenticated. The sender writes it into the frame header, and receivers accept it as given. ARP has the same weakness: any host can send a reply, and most operating systems cache replies they never asked for. Both attacks below rely on this trust.
MAC spoofing
MAC spoofing means setting an interface to use a MAC address other than its burned-in one. Operating systems allow this because the same feature supports legitimate uses, such as MAC randomization, virtual machines, and replacing a failed device.
Attackers use spoofing in three ways:
- Impersonation: copying the MAC of an authorized device to get past a MAC allow list, such as a captive portal or a hotel Wi-Fi login tied to a MAC.
- Evasion: changing identity to escape a MAC-based ban or rate limit.
- Switch table poisoning: sending frames with another host's source MAC so the switch moves that MAC to the attacker's port. The victim loses traffic until it transmits again.
Filtering by MAC is a convenience control, not a security control. Anyone who can observe the network can read an allowed MAC and copy it.
ARP spoofing
ARP spoofing (also called ARP poisoning) sends forged ARP replies that map a victim's IP address to the wrong MAC. The classic case targets the default gateway. The attacker tells the victim "the gateway's IP is at my MAC." The victim then sends its off-subnet traffic to the attacker. If the attacker forwards the traffic onward, the victim notices nothing, and the attacker sits in the middle as a man-in-the-middle (MITM).
The attack only works within one broadcast domain. ARP does not cross routers, so an attacker on another subnet cannot poison your cache.
Detecting suspicious ARP entries
A common sign of poisoning is one MAC address claimed by several IP addresses, especially when one of them is the gateway. The script below parses Linux ip neigh show output and reports MACs that appear for more than one IP.
from collections import defaultdict
def find_duplicate_macs(text: str) -> dict:
by_mac = defaultdict(set)
for line in text.splitlines():
parts = line.split()
if "lladdr" in parts:
ip = parts[0]
mac = parts[parts.index("lladdr") + 1].lower()
by_mac[mac].add(ip)
return {m: sorted(ips) for m, ips in by_mac.items() if len(ips) > 1}
sample = """192.168.1.1 dev eth0 lladdr 02:00:5e:10:00:01 REACHABLE
192.168.1.20 dev eth0 lladdr 02:00:5e:10:00:99 STALE
192.168.1.30 dev eth0 lladdr 02:00:5e:10:00:99 STALE"""
print(find_duplicate_macs(sample))This prints {'02:00:5e:10:00:99': ['192.168.1.20', '192.168.1.30']}. Duplicates are a clue, not proof. A router doing proxy ARP, or a host with several IP addresses, legitimately produces the same pattern. A better signal is the gateway's MAC changing unexpectedly.
Basic defenses
| Defense | Where it runs | What it does |
|---|---|---|
| Port security | Switch | Limits the number of MACs per port, or pins specific MACs, and blocks or shuts down the port on violation |
| DHCP snooping | Switch | Records which IP each port legitimately received from trusted DHCP servers |
| Dynamic ARP Inspection (DAI) | Switch | Drops ARP packets whose IP-to-MAC pair does not match the DHCP snooping table |
| Static ARP entries | Host | Fixes a critical mapping, such as the gateway, so replies cannot change it. This is hard to maintain at scale. |
| 802.1X | Switch and Wi-Fi | Authenticates the user or device with credentials or certificates instead of trusting a MAC |
| Encryption (TLS, SSH, VPN) | Applications | Does not stop redirection, but stops the attacker reading or altering traffic |
The layers work together. DHCP snooping builds the trusted table, DAI uses it to reject forged ARP, and 802.1X replaces MAC-based identity. Encryption limits the damage if the other layers fail.
Exercise
A host's gateway MAC in ip neigh show suddenly changes from the router's MAC to an unknown one, and the host's traffic still works. What is the likely cause, and which switch feature would have blocked it?
Show answer
Likely ARP spoofing. An attacker sent forged ARP replies, and is forwarding traffic so connectivity looks normal. Dynamic ARP Inspection, which relies on DHCP snooping, would drop the forged replies because the claimed IP-to-MAC pair does not match the snooping table.