Ethernet Frames and MAC Addresses
Every packet on a wired LAN travels inside an Ethernet frame, and the first thing any switch, sniffer or intrusion sensor looks at is the frame's 14-byte header: who it is for, who it claims to be from, and what is inside. "Claims" is the important word. Nothing in Ethernet proves that a frame really came from the MAC address in its source field. Several attacks in this course (ARP spoofing, MAC flooding, VLAN hopping) start from that single fact.
The basics of frames and addresses are in Ethernet Frames and MAC Addresses. This lesson reads them as an analyst does: from bytes, with the bits that matter for security.
The header in bytes
| Offset | Size | Field | Example from the ARP capture |
|---|---|---|---|
| 0 | 6 | destination MAC | ff:ff:ff:ff:ff:ff (broadcast) |
| 6 | 6 | source MAC | 02:00:00:0a:0a:05 |
| 12 | 2 | EtherType (what the payload is) | 0x0806 = ARP |
| 14 | 46–1500 | payload | the ARP message |
| end | 4 | frame check sequence (CRC-32) | stripped by most capture drivers |
Common EtherTypes: 0x0800 IPv4, 0x86dd IPv6, 0x0806 ARP, 0x8100 an 802.1Q VLAN tag, 0x88cc LLDP, 0x888e 802.1X (EAPOL). A value of 1500 or less is not a type at all but a length (old IEEE 802.3 framing, still used by spanning tree).
Two bits inside the first byte
A MAC address is 48 bits. The first three bytes are normally the vendor's OUI (organisationally unique identifier), and the lowest two bits of the very first byte carry meaning:
- bit 0, I/G: 1 = group address (multicast or broadcast), 0 = one station. A source address must never have it set.
- bit 1, U/L: 1 = locally administered (set by software, not burned in by the vendor), 0 = universally administered.
All the lab machines in this track use addresses like 02:00:00:0a:0a:05: 0x02 has the U/L bit set, so they are locally administered and belong to no vendor. Phones and laptops also use random locally administered addresses for Wi-Fi privacy, which is why "unknown vendor" is not by itself suspicious any more.
Parsing a frame with struct
The program below holds the first frame of the sample ARP capture as hex (the browser can't read the sandbox's files, so the bytes are copied in) and decodes the header. !6s6sH means network byte order (big-endian), two 6-byte strings and one unsigned 16-bit integer.
import struct
# Frame 1 of $SAMPLES/pcap/arp.pcap (42 bytes, copied from the capture)
frame = bytes.fromhex(
"ffffffffffff0200000a0a0508060001"
"080006040001" "0200000a0a050a0a0005" "0000000000000a0a0001")
ETHERTYPES = {0x0800: "IPv4", 0x86DD: "IPv6", 0x0806: "ARP", 0x8100: "802.1Q VLAN"}
def mac(b):
return ":".join(f"{x:02x}" for x in b)
def describe(b):
if b == b"\xff" * 6:
return f"{mac(b)} broadcast"
first = b[0]
kind = "group" if first & 1 else "unicast"
admin = "locally administered" if first & 2 else "universal, OUI " + mac(b[:3])
return f"{mac(b)} {kind}, {admin}"
dst, src, etype = struct.unpack("!6s6sH", frame[:14])
print("dst ", describe(dst))
print("src ", describe(src))
print("type ", f"0x{etype:04x}", ETHERTYPES.get(etype, "?"))
print("payload", len(frame) - 14, "bytes")
if src[0] & 1:
print("ALERT: group bit set in a source address (malformed or forged frame)")dst ff:ff:ff:ff:ff:ff broadcast
src 02:00:00:0a:0a:05 unicast, locally administered
type 0x0806 ARP
payload 28 bytes
The destination is the broadcast address, so every station on the segment receives this frame; the source is a locally administered unicast address; the EtherType says an ARP message of 28 bytes follows.
The same fields with the real tools
In the sandbox, tcpdump -e prints the link-layer header and tshark -T fields extracts named fields; eth.src, eth.dst and eth.type are the Wireshark field names you will also use in display filters.
tcpdump -nn -e -r $SAMPLES/pcap/arp.pcap 2>/dev/null
echo "---"
tshark -r $SAMPLES/pcap/arp.pcap -T fields -e frame.number -e eth.src -e eth.dst -e eth.type10:00:00.000000 02:00:00:0a:0a:05 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.10.0.1 tell 10.10.0.5, length 28
10:00:00.000400 02:00:00:0a:0a:01 > 02:00:00:0a:0a:05, ethertype ARP (0x0806), length 42: Reply 10.10.0.1 is-at 02:00:00:0a:0a:01, length 28
10:00:05.000000 02:00:00:0a:0a:66 > 02:00:00:0a:0a:05, ethertype ARP (0x0806), length 42: Reply 10.10.0.1 is-at 02:00:00:0a:0a:66, length 28
---
1 02:00:00:0a:0a:05 ff:ff:ff:ff:ff:ff 0x0806
2 02:00:00:0a:0a:01 02:00:00:0a:0a:05 0x0806
3 02:00:00:0a:0a:66 02:00:00:0a:0a:05 0x0806
Notice frame 3: a different source MAC (…:66) replying about the same IP address as frame 2. You will take that apart in ARP Spoofing.
An attack on the switch: MAC flooding
A switch learns which port each source MAC lives behind and keeps the result in its CAM table (content-addressable memory), so it can forward unicast frames to one port only. The table has a fixed size. MAC flooding sends frames with thousands of random source addresses until the table is full; frames for addresses the switch no longer knows are then flooded out of every port, so a sniffer on any port sees traffic meant for others.
The simulation below models a 16-entry CAM table (real switches hold thousands, the behaviour is the same) with oldest-first eviction.
import random
from collections import OrderedDict
random.seed(7)
CAM_SIZE = 16
def run(flood, port_security=False):
cam = OrderedDict() # mac -> port, oldest first
blocked = 0
def learn(m, port):
nonlocal blocked
if port_security and port == 9 and sum(1 for p in cam.values() if p == 9) >= 2:
if m not in cam:
blocked += 1
return
cam.pop(m, None)
cam[m] = port
if len(cam) > CAM_SIZE:
cam.popitem(last=False)
hosts = {f"02:00:00:0a:0a:{i:02x}": i for i in range(1, 9)} # 8 real hosts on ports 1-8
for m, p in hosts.items():
learn(m, p)
for _ in range(flood): # attacker on port 9
learn("02:%02x:%02x:%02x:%02x:%02x" % tuple(random.randrange(256) for _ in range(5)), 9)
flooded = sum(1 for m in hosts if m not in cam) # unknown -> sent to every port
return len(cam), flooded, blocked
for flood, ps in [(0, False), (500, False), (500, True)]:
size, flooded, blocked = run(flood, ps)
print(f"flood={flood:<4} port-security={ps!s:<5} table={size:>2} "
f"hosts now flooded to all ports={flooded} frames blocked={blocked}")flood=0 port-security=False table= 8 hosts now flooded to all ports=0 frames blocked=0
flood=500 port-security=False table=16 hosts now flooded to all ports=8 frames blocked=0
flood=500 port-security=True table=10 hosts now flooded to all ports=0 frames blocked=498
How it is detected
- Many source MACs behind one access port. A desk port normally shows one or two addresses (a PC and a phone); hundreds per second is flooding. Switches log "MAC address table full" or port-security violations;
show mac address-table countstyle commands give the numbers. - Unicast flooding: a sensor suddenly sees unicast frames addressed to other hosts.
- Group bit set in a source MAC, or impossible OUIs, are signs of crafted frames.
- The same MAC on two ports (MAC flapping) can mean spoofing of one station's address.
How it is fixed or prevented
- Port security: limit each access port to a few learned MACs and shut down or drop on violation (the second "flood=500" line above).
- 802.1X port authentication, so a port only forwards after the device authenticates.
- Segmentation: a flood only reaches its own VLAN. Keep untrusted devices on their own.
- Encryption above the link layer (TLS, SSH, IPsec, MACsec on the link itself): a sniffer that receives frames still can't read them.
Pitfalls
- Treating a MAC address as an identity. It is a claim, trivially changed in software; MAC-based allow lists stop accidents, not attackers.
- Forgetting byte order:
structneeds!(network order).Hwithout it on a little-endian machine reads0x0806as0x0608. - Expecting the 4-byte FCS in a capture. Most drivers strip it; the 42-byte frame above is 14 + 28 with no FCS and no padding.
Practice
1. Decode by hand: is 33:33:00:00:00:01 a valid source address? What is it?
0x33 = 0011 0011: bit 0 (I/G) is 1, so it is a group address and can't be a source. 33:33:… is the Ethernet mapping of IPv6 multicast (here ff02::1, all nodes).
2. In the simulation, why are exactly 8 hosts flooded after 500 random frames?
The table holds 16 entries and evicts the oldest. After 500 new addresses the 16 newest are all attacker addresses, so all 8 real hosts have been evicted; frames to them are flooded until they send again and are re-learned (and evicted again a moment later).
3. Change CAM_SIZE to 4096 and the flood to 500. What happens and what does it teach?
Nothing is evicted (8 + 500 < 4096), so no host is flooded. Real attacks therefore send tens of thousands of frames per second, which makes them loud: the per-port MAC count is the detection.
Test yourself
What does the EtherType value 0x0806 mean?
- IPv4
- IPv6
- ARP
- 802.1Q VLAN tag
The lab MAC 02:00:00:0a:0a:05 starts with 0x02. What does that tell you?
- It is a broadcast address
- It is locally administered (set by software), unicast
- It belongs to vendor 02:00:00
- It is an IPv6 multicast address
Why does MAC flooding let an attacker see other hosts' traffic?
- It decrypts frames
- A full CAM table makes the switch flood frames for unknown addresses to every port
- It changes the hosts' IP addresses
- It disables the FCS check
Which control directly limits MAC flooding on an access port?
- DNSSEC
- Port security (maximum learned MACs per port)
- SYN cookies
- HSTS