TExcelTAD

ARP on the Wire

A host that wants to send an IPv4 packet to 10.10.0.1 on its own LAN needs that machine's MAC address, because the Ethernet frame needs a destination. The Address Resolution Protocol (ARP, RFC 826) asks the whole segment "who has 10.10.0.1?" and believes the first answer. It has no authentication, no session and no memory of having asked. That is a sensible design for a 1982 network of trusted machines, and the reason ARP is still one of the easiest protocols to abuse on a LAN.

The mechanics (request, reply, cache) are explained in ARP. Here you read ARP messages byte by byte and learn which fields a defender checks.

The 28-byte message

HTYPE 1 (2) PTYPE 0x0800 (2) HLEN 6 PLEN 4 OPER 1 or 2 (2) sender MAC (6) sender IP (4) target MAC (6) target IP (4) sizes in bytes; receivers cache the sender pair
  • Operation 1 = request ("who has target IP? tell sender IP"), 2 = reply ("sender IP is at sender MAC").
  • In a request the target MAC is all zeros: that is the unknown being asked for.
  • The sender pair (MAC, IP) is what receivers write into their ARP cache. RFC 826 even lets a host update an existing cache entry from any ARP packet whose sender IP it already knows, request or reply.
  • A gratuitous ARP is a message where sender IP = target IP, announcing one's own mapping (after boot, after failover, or to detect duplicate addresses).

Parsing the three messages of the sample capture

The program decodes all three ARP messages from $SAMPLES/pcap/arp.pcap (the 28 bytes after each 14-byte Ethernet header, copied into the code) and keeps an ARP cache the way a naive host would.

python · try it yourself
import struct, ipaddress

msgs = [  # (time in s, ARP payload) from $SAMPLES/pcap/arp.pcap
    (0.0000, "0001080006040001" "0200000a0a05" "0a0a0005" "000000000000" "0a0a0001"),
    (0.0004, "0001080006040002" "0200000a0a01" "0a0a0001" "0200000a0a05" "0a0a0005"),
    (5.0000, "0001080006040002" "0200000a0a66" "0a0a0001" "0200000a0a05" "0a0a0005"),
]

def mac(b): return ":".join(f"{x:02x}" for x in b)

cache = {}
for t, hx in msgs:
    htype, ptype, hlen, plen, op, sha, spa, tha, tpa = struct.unpack("!HHBBH6s4s6s4s", bytes.fromhex(hx))
    sip, tip = ipaddress.IPv4Address(spa), ipaddress.IPv4Address(tpa)
    if op == 1:
        print(f"{t:6.4f} request  who-has {tip} tell {sip} ({mac(sha)})")
    else:
        print(f"{t:6.4f} reply    {sip} is-at {mac(sha)}")
    old = cache.get(sip)
    cache[sip] = mac(sha)            # a naive host believes every sender pair
    if old and old != mac(sha):
        print(f"       cache entry for {sip} CHANGED {old} -> {mac(sha)}")
print("final cache:", {str(k): v for k, v in cache.items()})
0.0000 request  who-has 10.10.0.1 tell 10.10.0.5 (02:00:00:0a:0a:05)
0.0004 reply    10.10.0.1 is-at 02:00:00:0a:0a:01
5.0000 reply    10.10.0.1 is-at 02:00:00:0a:0a:66
       cache entry for 10.10.0.1 CHANGED 02:00:00:0a:0a:01 -> 02:00:00:0a:0a:66
final cache: {'10.10.0.5': '02:00:00:0a:0a:05', '10.10.0.1': '02:00:00:0a:0a:66'}

The first two messages are a normal exchange (the cache also learns the asker, 10.10.0.5, from the request's sender pair). The third is a reply nobody asked for, five seconds later, from a different MAC, and a naive host simply overwrites its entry for the gateway 10.10.0.1. From now on its traffic to the gateway goes to …:66.

The same analysis with tshark

Wireshark's ARP dissector already remembers which MAC answered for which IP. In the sandbox, tshark prints the ARP fields, and the display filter arp.duplicate-address-detected (set by the dissector when an IP shows up with a second MAC) selects exactly the suspicious frames:

bash · try it yourself
cd $SAMPLES/pcap
tshark -r arp.pcap -T fields -e frame.time_relative -e arp.opcode -e arp.src.hw_mac -e arp.src.proto_ipv4 -e arp.dst.proto_ipv4
echo "--- frames Wireshark flags:"
tshark -r arp.pcap -Y 'arp.duplicate-address-detected'
0.000000000	1	02:00:00:0a:0a:05	10.10.0.5	10.10.0.1
0.000400000	2	02:00:00:0a:0a:01	10.10.0.1	10.10.0.5
5.000000000	2	02:00:00:0a:0a:66	10.10.0.1	10.10.0.5
--- frames Wireshark flags:
    3   5.000000 02:00:00:0a:0a:66 → 02:00:00:0a:0a:05 ARP 42 10.10.0.1 is at 02:00:00:0a:0a:66

Security properties

Property ARP Consequence
Authentication none any host can claim any IP
Request/response matching none unsolicited replies are accepted
Scope one broadcast domain attacks need a foothold on the same LAN or VLAN
Replacement in IPv6 NDP (Neighbor Discovery) same weakness, addressed by RA guard and SEND (rarely deployed)

What defenders watch

  • IP-to-MAC changes for important addresses (gateway, DNS, domain controllers). Tools such as arpwatch keep a table and report "changed ethernet address" or "flip flop".
  • Unsolicited replies and gratuitous ARP bursts, especially for the gateway.
  • One MAC claiming many IPs, a common sign of a machine positioning itself in the middle.
  • Switch features (DHCP snooping, dynamic ARP inspection) that check ARP against a trusted binding table. They are the fix, covered in the next lesson.

Pitfalls

  • Reading only replies. Requests also carry a sender pair and also update caches.
  • Treating every IP-to-MAC change as an attack. A replaced network card, a VM migration or a high-availability failover (which sends gratuitous ARP on purpose) all change mappings. Keep a list of expected changes.
  • Forgetting that ARP is per VLAN. A sensor on one VLAN sees nothing of another VLAN's ARP traffic.

Practice

1. Write the 28 bytes of a gratuitous ARP request in which 10.10.0.10 (MAC 02:00:00:0a:0a:0a) announces itself.

0001 0800 06 04 0001 0200000a0a0a 0a0a000a 000000000000 0a0a000a: operation 1, sender and target IP both 10.10.0.10, target MAC zero. It goes to the broadcast MAC.

2. Change the program so it prints "unsolicited" for a reply that doesn't answer an earlier request from this host.

Keep a set asked of target IPs from requests whose sender IP is our own (10.10.0.5); on a reply, if sip not in asked, print "unsolicited". Remove the IP from asked after the first answer so a second reply also counts as unsolicited. In the sample, message 3 is flagged.

3. Why does an attacker need to send the forged reply again and again?

Cache entries expire (tens of seconds to minutes) and the real gateway answers the next request. Repeated poisoning keeps the forged entry alive, which is also why ARP spoofing is visible as a steady stream of replies.

Test yourself

In an ARP request, what does the target MAC field contain?

  1. The broadcast address
  2. All zeros, because it is the unknown
  3. The sender's MAC
  4. The gateway's MAC

What is a gratuitous ARP?

  1. An unsolicited ARP message (usually a request) whose sender and target IP are the same
  2. An ARP request to a router
  3. An encrypted ARP message
  4. An ARP message with opcode 3

In the sample capture, which frame does Wireshark's duplicate-address check flag?

  1. Frame 1, the request
  2. Frame 2, the first reply
  3. Frame 3, the second reply from a different MAC
  4. None