Sub topic 13
VLAN hopping: switch spoofing and double tagging
This chapter assumes you can configure access and trunk ports, you know what the native VLAN is, and you know that DTP (Dynamic Trunking Protocol) is Cisco's trunk negotiation protocol. You should also be comfortable reading a Cisco IOS configuration. The chapter covers two attacks that let a host reach a VLAN it was never assigned to, and the configuration that stops each one.
What VLAN hopping means
VLAN hopping is any technique that lets a device inject traffic into, or receive traffic from, a VLAN other than the one its switch port is assigned to. VLANs are a segmentation feature, not a security boundary on their own. Both attacks below exploit default or careless trunk behavior. Neither exploits a flaw in the 802.1Q standard.
| Attack | What the attacker needs | Traffic direction | Root cause |
|---|---|---|---|
| Switch spoofing | A port that is willing to negotiate a trunk | Two-way | DTP enabled on a user-facing port |
| Double tagging | A port in the trunk's native VLAN | One-way (attacker to victim) | Native VLAN is used by users and sent untagged |
Attack 1: switch spoofing
How it works
A switch port that runs DTP can become a trunk if the device on the other end asks for it. The default administrative mode on many Cisco switches is dynamic auto, which accepts a trunk request from the neighbor. The mode dynamic desirable actively sends requests.
An attacker's computer can pretend to be a switch. Tools such as Yersinia send DTP frames that request a trunk. If the port accepts, it becomes a trunk, and the attacker receives traffic for all VLANs allowed on it. The attacker can then send frames with any 802.1Q tag, and the switch will deliver them into that VLAN. The attacker can also run a VLAN subinterface for each VLAN, as in the Linux example from the earlier chapters.
Why it works
- The port is in a dynamic mode, so it will form a trunk without any administrator decision.
- The trunk's allowed VLAN list defaults to all VLANs (1-4094), so the attacker gets every VLAN the switch knows.
Mitigation
Hard-code every port's mode. User-facing ports become static access ports. Trunk ports become static trunks with negotiation off.
interface GigabitEthernet0/5
switchport mode access
switchport access vlan 10
switchport nonegotiate
!
interface GigabitEthernet0/24
switchport mode trunk
switchport nonegotiate
switchport trunk allowed vlan 10,20switchport mode access already stops DTP on that port. Adding nonegotiate to an access port is harmless and makes the intent explicit. On a trunk, nonegotiate is essential, because a port set to switchport mode trunk still sends DTP frames unless you disable them.
Attack 2: double tagging
How it works
Double tagging uses the native VLAN. Recall that a trunk sends native VLAN frames without a tag. The attacker builds a frame with two 802.1Q tags:
- The outer tag carries the native VLAN ID of the trunk (for example, VLAN 1).
- The inner tag carries the victim's VLAN ID (for example, VLAN 20).
The attacker's port must be in the native VLAN. The sequence is:
- The first switch receives the frame on the attacker's port, which is in the native VLAN. It sees the outer tag matches the native VLAN.
- The switch forwards the frame onto the trunk. Because the frame belongs to the native VLAN, the switch strips the outer tag and sends the frame untagged, leaving the inner tag intact.
- The second switch receives the frame on the trunk. It sees one tag, VLAN 20, and treats the frame as VLAN 20 traffic.
- The second switch delivers the frame to the victim's VLAN.
Limits of the attack
- It is one-way. The victim's reply carries a normal VLAN 20 tag and goes back toward VLAN 20, not to the attacker. The attack suits one-shot packets such as a UDP datagram or a TCP SYN, but not a full conversation.
- It needs the attacker's port to be in the native VLAN of the trunk, or on a trunk itself.
- It needs at least two switches. With a single switch there is no trunk to strip the tag.
- Platform behavior varies. Some switches drop tagged frames that arrive on an access port, which defeats the attack from a true access port. Do not rely on that behavior unless the vendor documents it.
- A router or Layer 3 switch in the path may block the traffic with an ACL, but the injected frame stays at Layer 2 and never crosses a router.
Building the frame in a lab
You can craft the frame with Scapy to see the two tags. Run this only on a lab network you own.
from scapy.all import Ether, Dot1Q, IP, ICMP
frame = (
Ether(dst="ff:ff:ff:ff:ff:ff")
/ Dot1Q(vlan=1) # outer tag: the trunk's native VLAN
/ Dot1Q(vlan=20) # inner tag: the target VLAN
/ IP(dst="192.168.20.255")
/ ICMP()
)
frame.show()When you send this frame from a port in the native VLAN on a trunked lab network, a capture on the far side of the trunk should show a single tag for VLAN 20.
Mitigation
The defenses all remove one of the conditions the attack needs.
- Never put user devices in the native VLAN. Move all hosts out of VLAN 1 and into purpose-built VLANs.
- Set the native VLAN on every trunk to a VLAN that nothing else uses, such as VLAN 999. Use the same value on both ends.
- Do not assign any access port to the native VLAN.
- Optionally, tell the switch to tag native VLAN frames. On many Cisco platforms the global command is
vlan dot1q tag native. The outer tag then stays on the trunk and the second switch cannot misread it. Check that every device on the link supports tagged native traffic first, or the link will break. - Restrict the allowed VLAN list on each trunk so the native VLAN is not carried when it does not need to be.
vlan 999
name NATIVE_UNUSED
!
interface GigabitEthernet0/24
switchport mode trunk
switchport trunk native vlan 999
switchport trunk allowed vlan 10,20
switchport nonegotiate
!
vlan dot1q tag nativeSecuring unused ports
An unused port left in the default VLAN, with default negotiation settings, is an open door. A hardened baseline for unused ports is:
vlan 998
name BLACKHOLE
!
interface range GigabitEthernet0/10 - 23
switchport mode access
switchport access vlan 998
switchport nonegotiate
shutdownPutting unused ports in a VLAN with no Layer 3 interface and no uplink means that even if someone enables a port, the traffic goes nowhere. Keep VLAN 998 off every trunk's allowed list.
Verifying the hardening
Check that no user port is trunking and that each trunk shows the right native and allowed VLANs.
show interfaces trunk
show interfaces GigabitEthernet0/5 switchport
show vlan briefIn the switchport output, look for these lines on a user port:
Administrative Mode: static accessOperational Mode: static accessNegotiation of Trunking: Off
If a user port shows dynamic auto or Negotiation of Trunking: On, it is exposed to switch spoofing. In show interfaces trunk, confirm that the native VLAN column shows your unused VLAN, and that the "VLANs allowed" list is as short as possible. Also run show vlan brief and check that no access port is listed under VLAN 1 or under the native VLAN.
Common mistakes
- Setting
switchport mode trunkbut forgettingswitchport nonegotiate. The port still sends DTP frames to whatever is attached. - Moving the native VLAN to 999 but leaving hosts in VLAN 1, so the default VLAN stays a risk on other trunks that still use it as native.
- Pruning VLANs from the allowed list but leaving the native VLAN allowed, so it still crosses the trunk.
- Assuming that a port-level hardening step on one switch protects the whole network. Both attacks depend on the configuration of each switch along the path, so audit every switch.
- Treating VLANs as a replacement for firewalls. VLAN separation controls Layer 2 reachability. Policy between VLANs still belongs on the router, Layer 3 switch or firewall.
Exercise
A host on access port Gi0/3, which is in VLAN 1 (the native VLAN of the trunk to the next switch), sends a frame with outer tag 1 and inner tag 30. VLAN 30 is allowed on the trunk. Which two configuration changes together would stop this frame from reaching VLAN 30, and why does the victim's reply never reach the attacker even when the attack succeeds?
Show answer
Move the trunk's native VLAN to an unused VLAN such as 999 and move the host out of VLAN 1 (or enable native VLAN tagging with vlan dot1q tag native). With these changes, the first switch no longer strips the outer tag as a native VLAN frame, so the second switch never sees a lone VLAN 30 tag. The reply fails because the victim answers with a normal frame tagged for VLAN 30 (or routed into the attacker's own subnet), and nothing carries it back to the attacker's native VLAN port. Double tagging is one-way.
Exercise
You find Administrative Mode: dynamic auto on a user-facing port. Which attack does this allow, and which two commands on the port fix it?
Show answer
It allows switch spoofing, where the attacker sends DTP frames and turns the port into a trunk. Fix it with switchport mode access and switchport nonegotiate, and assign the port to a user VLAN with switchport access vlan <id>.