Home > Articles > Cisco Network Technology > Security > Attacking the Spanning Tree Protocol

Attacking the Spanning Tree Protocol


  1. Introducing Spanning Tree Protocol
  2. Let the Games Begin!
  3. Summary

Chapter Description

Conducting STP attacks is now within the reach of a wide population, thanks to the availability of point-and-shoot attacks tools. Fortunately, simple features widely available on a range of switches, such as BPDU-guard, provide effective measures against spanning-tree–based exploits.

Let the Games Begin!

Unfortunately, you are likely to come across LAN hackers that are intimately familiar with STP's inner workings. They also know that little or no attention is paid to STP security. They realize how gullible—for lack of a better term—the protocol actually is. STP attacks moved from the theoretical field to reality fairly recently. Black Hat Europe 2005 proposed a session that discussed various ways to exploit STP3. Packet-building libraries, such as libnet4, have been shipping C-source code to help craft homemade BPDUs for some time now, but putting together an attack tool required some programming skills—a fact that probably deterred most script kiddies. It was only a matter of time before someone built a frontend to a libnet-based LAN protocol's packet-building machine. Probably the most successful result of that effort is a tool called Yersinia. Example 3-1 shows Yersinia's manual page.

Example 3-1. Yersinia Manual Page


        Yersinia - A FrameWork for layer 2 attacks

        yersinia [-hVID] [-l logfile] [-c conffile] protocol [-M]

        yersinia is a framework for performing layer 2 attacks. The following
 protocols have been implemented in Yersinia current version: Spanning Tree
 Protocol (STP), Virtual Trunking Protocol (VTP), Hot Standby Router Protocol
 (HSRP), Dynamic Trunking Protocol (DTP), IEEE 802.1Q, Cisco Discovery Protocol
 (CDP) and finally, the Dynamic Host Configuration Protocol (DHCP).
        Some of the attacks implemented will cause a DoS in a network, other will
 help to perform any other more advanced attack, or both. In addition, some of
 them will be first released to the public since there isn't any public

The tool basically covers all the most common LAN protocols deployed in today's networks: STP, VLAN Trunk Protocol (VTP), Hot Standby Router Protocol(HSRP), Dynamic Trunking Protocol (DTP), Cisco Discovery Protocol (CDP), DHCP—they are all in there. Even worse, it comes with a GUI! According to Yersinia's home page,5 it proposes these STP attacks:

  • Sending RAW Configuration BPDU
  • Sending RAW TCN BPDU
  • Denial of Service (DoS) sending RAW Configuration BPDU
  • DoS Sending RAW TCN BPDU
  • Claiming Root Role
  • Claiming Other Role
  • Claiming Root Role Dual-Home (MITM)

Basically, Yersinia has everything that anyone interested in messing around with STP would ever need. The GUI is based on the ncurses library (for character-cell terminals, such as VT100). Figure 3-5 shows Yersinia's protocols.

Figure 3-5

Figure 3-5 Yersinia's Protocols

Yersinia continuously listens for STP BPDUs and provides instant decoded information, including current root bridge and timers it is propagating—all this for 802.1D, 802.1w, and Cisco BPDUs. The following sections review the major STP attacks and offer appropriate countermeasures.

Attack 1: Taking Over the Root Bridge

Taking over a root bridge is probably one of the most disruptive attacks. By default, a LAN switch takes any BPDU sent from Yersinia at face value. Keep in mind that STP is trustful, stateless, and does not provide a solid authentication mechanism. The default STP bridge priority is 32768. Once in root attack mode, Yersinia sends a BPDU every 2 sec with the same priority as the current root bridge, but with a slightly numerically lower MAC address, which ensures it a victory in the root-bridge election process. Figure 3-6 shows Yersinia's STP attack screen, followed by a show command capture on the LAN switch under attack.

Figure 3-6

Figure 3-6 Yersinia's STP Attacks

Example 3-2 shows the result of the attack on the switch. (The hacker running Yersinia is connected to port F8/1.)

Example 3-2. Cisco IOS Command to Display Port-Level STP Details

 6K-2-S2#show spanning-tree vlan 123 interface f8/1 detail
  Port 897 (FastEthernet8/1) of VLAN0123 is root forwarding                 
    Port path cost 19, Port priority 240, Port Identifier 240.897.
    Designated root has priority 32891, address 0050.3e04.9c00
    Designated bridge has priority 32891, address 0050.3e04.9c00
    Designated port id is 240.897, designated path cost 0
    Timers: message age 15, forward delay 0, hold 0
    Number of transitions to forwarding state: 2
    Link type is point-to-point by default
    Loop guard is enabled by default on the port
    BPDU: sent 29, received 219
 ! The previous command show the status of the port for a given VLAN, and
 ! the number of BPDU received on the port. Here, something abnormal is
 ! happening: a root port should typically be sending many more BPDUs than
 ! it is receiving. The opposite is taking place here, indicating suspicious
 ! activity.
 6K-2-S2#sh spanning-tree bridge address | inc VLAN0123
 VLAN0123         0050.3e05.9c00
 6K-2-S2#sh spanning-tree vlan 123 root

                                         Root    Hello Max Fwd
 Vlan                   Root ID          Cost    Time  Age Dly  Root Port
 ---------------- -------------------- --------- ----- --- ---  ------------
 VLAN0123         32891 0050.3e04.9c00        19    2   20  15  Fa8/1

Notice this bridge's MAC address versus the MAC generated by Yersinia (0050.3e05.9c00 vs 0050.3e04.9c00). Yersinia wins (04 < 05), and the switch is convinced that the root bridge is located off port 8/1.

Example 3-3. Cisco IOS Command to Verify Root Bridge Status

 6K-2-S2#show spanning-tree vlan 123 root

                                         Root    Hello Max Fwd
 Vlan                   Root ID          Cost    Time  Age Dly  Root Port
 ---------------- -------------------- --------- ----- --- ---  ------------
 VLAN0123             0 0000.0000.0000        19    2   20  15  Fa8/1

Such a BPDU is absolutely impossible to beat, because no switch would ever generate an all-0 bridge ID.

Two other minor variations of the taking root ownership theme exist:

  • Root ownership attack: alternative 1. Another disruptive attack alternative could consist in first taking over the root bridge, and then never setting the TC-ACK bit in BPDUs when receiving a TCN BPDU. The result is a constant premature aging of the entries in the switches' forwarding tables, possibly resulting in unnecessary flooding.
  • Root ownership attack: alternative 2. For an even more negative effect, a sequence where the attack tool generates a superior BPDU claiming to be the root followed by a retraction of that information seconds later (see Yersinia's "claiming other role" function) could be used. This is guaranteed to cause lots of process churn because of constant state machine transitions, with high CPU utilization as a result and a potential DoS.

Fortunately, the countermeasure to a root takeover attack is simple and straightforward. Two features help thwart a root takeover attack:

  • Root guard
  • BPDU-guard

Root Guard

The root guard feature ensures that the port on which root guard is enabled is the designated port. Normally, root bridge ports are all designated ports, unless two or more ports of the root bridge are connected. If the bridge receives superior BPDUs on a root guard–enabled port, root guard moves this port to a root-inconsistent state. This root-inconsistent state is effectively equal to a listening state. No traffic is forwarded across this port. In this way, root guard enforces the position of the root bridge. See the first entry in the section, "References," for more details.


The BPDU-guard feature allows network designers to enforce the STP domain borders and keep the active topology predictable. Devices behind ports with BPDU-guard enabled are unable to influence the STP topology. Such devices include hosts running Yersinia, for example. At the reception of a BPDU, BPDU-guard disables the port. BPDU-guard transitions the port into the errdisable state, and a message is generated. See the second entry in the section, "References," for more details.

Example 3-4 shows root guard blocking a port receiving a superior BPDU.

Example 3-4. Root Guard in Action

 6K-2-S2# configure terminal
 Enter configuration commands, one per line. End with CNTL/Z.
 6K-2-S2(config)# interface fastethernet 8/1
 6K-2-S2(config-if)# spanning-tree rootguard
 6K-2-S2(config-if)# ^Z
 *Dec 30 18:25:16: %SPANTREE-2-ROOTGUARD_CONFIG_CHANGE: Rootguard enabled on
 port FastEthernet8/1 VLAN 123.

 Dec 30 18:33:41.677: %SPANTREE-SP-2-ROOTGUARD_BLOCK: Root guard blocking port Fa
 stEthernet8/1 on VLAN0123.
 6K-2-S2#sh spanning-tree vlan 123 ac
   Spanning tree enabled protocol rstp
   Root ID    Priority    32891
              Address     0050.3e05.9c00
              This bridge is the root
              Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec

   Bridge ID  Priority    32891  (priority 32768 sys-id-ext 123)
              Address     0050.3e05.9c00
              Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
              Aging Time 300

 Interface        Role Sts Cost      Prio.Nbr Type
 ---------------- ---- --- --------- -------- --------------------------------
 Fa8/1            Desg BKN*19        240.897  P2p *ROOT_Inc                     
 Fa8/45           Desg FWD 19        128.941  P2p
 Gi9/14           Desg FWD 4         128.1038 P2p
 Gi9/15           Desg FWD 4         128.1039 Edge P2p

 ! "Desg" means designated port role; BKN means status blocking;
 ! FWD means forwarding. Notice the "ROOT Inc" status for port Fa8/1.

If the attack stops, or if it was fortuitous, the port swiftly moves back to forwarding. This can take as little as three times the hello interval (6 sec, by default) if only a single superior BPDU was received.

Unless explicitly configured to bridge—which is a rare occurrence—end stations, such as PCs running any sort of operating system (OS), IP phones, printers, and so on, should never generate BPDUs, let alone superior BPDUs. Therefore, BPDU-guard is, and should be, usually preferred to root guard on access ports. BPDU-guard is much less forgiving than root guard: It instructs STP to error-disable a port in case any BPDU arrives on it. After a port is placed in the error-disabled state, there are two ways to recover from the action: either through a manual intervention (do/do not shut down the port) or through an automatic recovery timer whose minimum value is 30 sec. Example 3-5 shows how to configure this using Cisco IOS on a Catalyst 6500. (As usual, consult your switch's documentation for the exact syntax and availability of the feature.)

Example 3-5. How to Configure BPDU-Guard

 6K-2-S2#conf t
 Enter configuration commands, one per line. End with CNTL/Z.
 6K-2-S2(config)#int f8/1
 6K-2-S2(config-if)#spanning-tree bpduguard enable
 6K-2-S2(config)#errdisable recovery cause bpduguard
 6K-2-S2(config)#errdisable recovery ?
   cause     Enable error disable recovery for application
   interval  Error disable recovery timer value

 6K-2-S2(config)#errdisable recovery inter
 6K-2-S2(config)#errdisable recovery interval ?
   <30-86400> timer-interval(sec)

 6K-2-S2(config)#errdisable recovery interval 30


Immediately after a BPDU is received on the port, these messages are printed:

Dec 30 18:23:58.685: %LINEPROTO-5-UPDOWN: Line protocol on Interface
  FastEthernet8/1, changed state to down
Dec 30 18:23:58.683: %SPANTREE-SP-2-BLOCK_BPDUGUARD: Received BPDU on port
  FastEthernet8/1 with BPDU Guard enabled. Disabling port.
Dec 30 18:23:58.683: %PM-SP-4-ERR_DISABLE: bpduguard error detected on Fa8/1,
  putting Fa8/1 in err-disable state

If this BPDU was the result of an accident, the port is restored 30 sec later:

Dec 30 18:24:28.535: %PM-SP-4-ERR_RECOVER: Attempting to recover from bpduguard
  err-disable state on Fa8/1

By using the following command, it is possible to globally enable BPDU-guard on all portfast-enabled ports:

6K-2-S2(config)#spanning-tree portfast bpduguard ?
  default  Enable bdpu guard by default on all portfast ports

Unlike root guard, BPDU-guard is not limited only to root takeover attempts. Any incoming BPDU disables the port—period. On many Cisco IOS versions, BPDU-guard no longer requires a port to be portfast-enabled.

Attack 2: DoS Using a Flood of Config BPDUs

Attack number 2 in Yersinia (sending conf BPDUs) is extremely potent. With the cursors GUI enabled, Yersinia generated roughly 25,000 BPDUs per second on our test machine (Intel Pentium 4 machine running Linux 2.4–20.8). This seemingly low number is more than sufficient to bring a Catalyst 6500 Supervisor Engine 720 running 12.2(18)SXF down to its knees, with 99 percent CPU utilization on the switch processor:

6K-3-S720#remote command switch show proc cpu | incl second
CPU utilization for five seconds: 99%/86%; one minute: 99%; five minutes: 76%

At that point, serious side effects start to happen. HSRP suffered from continuous flapping during the attack:

Dec 30 18:59:21.820: %STANDBY-6-STATECHANGE: Vlan448 Group 48 state Standby ->

The attack's purpose is fulfilled: The switch is quickly DoS'd. Unless BPDU-guard is enabled, detecting this attack is not easy. Although it could, as the 802.1w specification suggests,6 the STP does not complain about handling thousands of incoming BPDUs. It just tries to process as many as it can until its processing power is exhausted. High CPU utilization and an extremely high and quickly increasing count of received BPDUs off a given port indicate a BPDU flooding attack, as Example 3-6 shows.

Example 3-6. Port Receiving Too Many BPDUs Too Quickly

 6K-3-S720#show spanning-tree vlan 123 interface f8/1 detail
  Port 897 (FastEthernet8/1) of VLAN0123 is root forwarding
    Port path cost 19, Port priority 240, Port Identifier 240.897.
    Designated root has priority 0, address 9838.9a38.3cf0
    Designated bridge has priority 52067, address 9838.9a38.3cf0
    Designated port id is 0.0, designated path cost 0
    Timers: message age 20, forward delay 0, hold 0
    Number of transitions to forwarding state: 4
    Link type is point-to-point by default, Peer is STP
    BPDU: sent 1191, received 7227590

Frequent transitions of a port from blocking to forwarding in a short interval confirm suspicions (use the Cisco IOS command logging-event spanning-tree status under the interface, if available):

5w2d: %SPANTREE-SP-6-PORT_STATE: Port Fa5/14 instance 1448 moving from blocking
  to blocking
5w2d: %SPANTREE-SP-6-PORT_STATE: Port Fa5/14 instance 1448 moving from blocking
  to forwarding

Three countermeasures exist for this attack. Two are available to most switches, and one has hardware dependencies:

  • BPDU-guard
  • BPDU filtering
  • Layer 2 PDU rate limiter


BPDU-guard was introduced in the previous section. Because it completely prevents BPDUs from entering the switch on the port on which it is enabled, the setting can help fend off this type of attack.

BPDU Filtering

There is actually another method to discard incoming and outgoing BPDUs on a given port: BPDU filtering. This feature silently discards both incoming and outgoing BPDUs. Although extremely efficient against a brute-force DoS attack, BPDU filtering offers an immense potential to shoot yourself in the foot. Enable this feature on the incorrect port, and any loop condition goes undetected forever, which causes instantaneous network downtime. On the other hand, not sending out BPDUs is actually a good thing when faced with a hacker using Yersinia. Yersinia listens for BPDUs in order to craft its own packets based on information contained in genuine BPDUs. If the tool isn't fed any data to start with, it slightly complicates the hacker's job; I say it only "slightly complicates" because Yersinia is a powerful tool when it comes to exploiting STP: It comes with a prefabricated BPDU ready to be sent on the wire! Because of its danger potential, use BPDU filtering with extreme caution and only after you clearly understand its potential negative effects. Suppose, for example, that a user accidentally connects two ports of the same switch. STP would normally take care of this loop condition. With BPDU filtering enabled, it is not taken care of, and packets loop forever! Only enable it toward end-station ports. It is enabled on a port basis using the spanning-tree bpdufilter enable command, as Example 3-7 shows.

Example 3-7. How to Enable BPDU Filtering on a Port

 6K-3-S720(config)#interface f5/14
 6K-3-S720(config-if)#spanning-tree bpdufilter enable
 *Dec 30 19:26:37.066: %SYS-5-CONFIG_I: Configured from console by vty0
 6K-3-S720#sh spanning-tree vlan 1448 int f5/14 detail | include filter
    Bpdu filter is enabled

As soon as either BPDU-guard or BPDU filtering is enabled, the CPU utilization returns to normal.

Layer 2 PDU Rate Limiter

Available only on certain switches, such as the Supervisor Engineer 720 for the Catalyst 6500, a third option to stop the DoS from causing damage exists. It takes the form of a hardware-based Layer 2 PDU rate limiter. It limits the number of Layer 2 PDUs (BPDUs, DTP, Port Aggregation Protocol [PAgP], CDP, VTP frames) destined for the supervisor engine's processor. The feature works only on Catalyst 6500/7600 that are not operating in truncated mode. The switch uses truncated mode for traffic between fabric-enabled modules when both fabric-enabled and nonfabric-enabled modules are installed. In this mode, the router sends a truncated version of the traffic (the first 64 bytes of the frame) over the switching fabric. (For more information about the various modes of operation of the Catalyst 6500 switch, see the third entry in the section, "References.") The Layer 2 PDU rate limiter is configured as follows:

Router(config)# mls rate-limit layer2 pdu 200 20 → 200 L2 PDUs per second, burst of
20 packets

Fine-tuning the rate limiter can be time consuming and error prone, because it is global to the switch and applicable to traffic received across all VLANs for various Layer 2 protocols. However, it can be safely enabled with a fairly high threshold. As a rough guideline, 2000 PDUs per second is a high watermark figure for an enterprise class switch. (The rate limiter prevents only a DoS attack. It does not stop the other attacks described in this chapter [root hostile takeover, and so on].)

Attack 3: DoS Using a Flood of Config BPDUs

Closely resembling the previous attack, this attack continuously generates TCN BPDUs, forcing the root bridge to acknowledge them. What's more, all bridges down the tree see the TC-ACK bit set and accordingly adjust their forwarding table's timers; this results in a wider impact to the switched network. When the TC bit is set in BPDUs, switches adjust their bridging table's aging timer to forward_delay seconds. The protection is the same as before: BPDU-guard or filtering.

Attack 4: Simulating a Dual-Homed Switch

Yersinia can take advantage of computers equipped with two Ethernet cards to masquerade as a dual-homed switch. This capability introduces an interesting traffic-redirection attack, as Figure 3-7 shows.

Figure 3-7

Figure 3-7 Simulating a Dual-Homed Switch

In Figure 3-7, a hacker connects to switches 1 and 4. It then takes root ownership, creating a new topology that forces all traffic to cross it. The intruder could even force switches 1 and 4 to negotiate the creation of a trunk port and intercept traffic for more than one VLAN.

Again, BPDU-guard stands out as the most advantageous solution to deter the attack.