Switch Security Best Practices for Unused and User Ports
The first three items in the list of best practices for unused and user ports are mostly covered in earlier chapters. For a brief review, Example 18-7 shows an example configuration on a Cisco 3550 switch, with each of these items configured and noted. In this example, fa0/1 is a currently unused port. CDP has been disabled on the interface, but it remains enabled globally, on the presumption that some ports still need CDP enabled. DTP has been disabled as well, and STP Root Guard and BPDU Guard are enabled.
Example 18-7 Disabling CDP and DTP and Enabling Root Guard and BPDU Guard
! The cdp run command keeps CDP enabled globally, but it has been disabled on ! fa0/1, the unused port. cdp run int fa0/0 no cdp enable
! The switchport mode access interface subcommand prevents the port from trunking, and the switchport nonegotiate command prevents any DTP messages from being sent or processed.
switchport mode access switchport nonegotiate
The last two interface commands enable Root Guard and BPDU Guard, per interface, respectively. BPDU Guard can also be enabled for all ports with PortFast enabled by configuring the spanning-tree portfast bpduguard enable global command, spanning-tree guard root spanning-tree bpduguard enable
Port Security
Switch port security monitors a port to restrict the number of MAC addresses associated with that port in the Layer 2 switching table. It can also enforce a restriction for only certain MAC addresses to be reachable out the port.
To implement port security, the switch adds more logic to its normal process of examining incoming frames. Instead of automatically adding a Layer 2 switching table entry for the source MAC and port number, the switch considers the port security configuration and whether it allows that entry. By preventing MACs from being added to the switch table, port security can prevent the switch from forwarding frames to those MACs on a port.
Port security supports the following key features:
.— ■ Limiting the number of MACs that can be associated with the port
Key Topic
■ Limiting the actual MAC addresses associated with the port, based on three methods:
— Static configuration of the allowed MAC addresses
— Dynamic learning of MAC addresses, up to the defined maximum, where dynamic entries are lost upon reload
— Dynamically learning but with the switch saving those entries in the configuration (called sticky learning)
Port security protects against a couple of types of attacks. Once a switch's forwarding table fills, the switch times out older entries. When the switch receives frames destined for those MACs that are no longer in the table, the switch floods the frames out all ports. An attacker could cause the switch to fill its switching table by sending lots of frames, each with a different source MAC, forcing the switch to time out the entries for most or all of the legitimate hosts. As a result, the switch floods legitimate frames because the destination MACs are no longer in the CAM, allowing the attacker to see all the frames.
An attacker could also claim to be the same MAC address as a legitimate user by simply sending a frame with that same MAC address. As a result, the switch would update its switching table, and send frames to the attacker, as shown in Figure 18-2.
Figure 18-2 Claiming to Use Another Host's MAC Address i Key \ Topic
PC-A
IP-A
MAC-A
Figure 18-2 Claiming to Use Another Host's MAC Address
PC-A
IP-A
MAC-A
PC-B
IP-B
MAC-B
1. Attacker sources frame using PC-B's actual MAC.
2. SW1 updates its MAC address table.
3. Another frame is sent to destination MAC-B.
4. SW1 forwards frame to attacker.
PC-B
IP-B
MAC-B
1. Attacker sources frame using PC-B's actual MAC.
2. SW1 updates its MAC address table.
3. Another frame is sent to destination MAC-B.
4. SW1 forwards frame to attacker.
Port security prevents both styles of these attacks by limiting the number of MAC addresses and by limiting MACs to particular ports. Port security configuration requires just a few configuration steps, all in interface mode. The commands are summarized in Table 18-4.
Table 18-4 Port Security Configuration Commands
Table 18-4 Port Security Configuration Commands
|
Command |
Purpose |
|
switchport mode {access 1 trunk} |
Port security requires that the port be statically set as either access or trunking |
|
switchport port-security [maximum value] |
Enables port security on an interface, and optionally defines the number of allowed MAC addresses on the port (default 1) |
|
switchport port-security mac-address mac-address [vlan {vlan-id 1 {access 1 voice}} |
Statically defines an allowed MAC address, for a particular VLAN (if trunking), and for either the access or voice VLAN |
|
Command |
Purpose |
|
switchport port-security mac- address sticky |
Tells the switch to remember the dynamically learned MAC addresses |
|
switchport port-security [aging] [violation {protect 1 restrict 1 shutdown}] |
Defines the Aging timer and actions taken when a violation occurs |
Of the commands in Table 18-4, only the first two are required for port security. With just those two commands, a port allows the first-learned MAC address to be used, but no others. If that MAC address times out of the CAM, another MAC address may be learned on that port, but only one is allowed at a time.
The next two commands in the table allow for the definition of MAC addresses. The third command statically defines the permitted MAC addresses, and the fourth command allows for sticky learning. Sticky learning tells the switch to learn the MACs dynamically, but then add the MACs to the running configuration. This allows port security to be enabled and existing MAC addresses to be learned, but then have them locked into the configuration as static entries simply by saving the running configuration. (Note that the switchport port-security maximum x command would be required to allow more than one MAC address, with x being the maximum number.)
The last command in the table tells the switch what to do when violations occur. The protect option simply tells the switch to perform port security. The restrict option tells it to also send SNMP traps and issue log messages regarding the violation. Finally, the shutdown option puts the port in a err-disabled state, and requires a shutdown/no shutdown combination on the port to recover the port's forwarding state.
Example 18-8 shows a sample configuration, based on Figure 18-3. In the figure, Server 1 and Server 2 are the only devices that should ever be connected to interfaces Fast Ethernet 0/1 and 0/2, respectively. In this case, a rogue device has attempted to connect to fa0/1.
Figure 18-3 Port Security Configuration Example
|
; |
|
|
-' 0200.1111.1111 |
|
|
Fa0/2 Server 2 |
|
|
' 0200.2222.2222 |
|
|
Fa0/3 Company - Comptroller |
|
|
Fa0/4 User1 |
Example 18-8 Using Port Security to Define Correct MAC Addresses Connected to Particular Interfaces
! FA0/1 has been configured to use a static MAC address, defaulting to allow ! only one MAC address, interface FastEthernet0/1 switchport mode access switchport port-security switchport port-security mac-address 0200.1111.1111
! FA0/2 has been configured to use a sticky-learned MAC address, defaulting to ! allow only one MAC address. interface FastEthernet0/2 switchport mode access switchport port-security switchport port-security mac-address sticky FA0/1 shows as err-disabled, as a device that was not 0200.1111.1111 tried to connect. The default violation mode is shutdown, as shown. It also lists the fact that a single MAC address is configured, that the maximum number of MAC addresses is 1, and that there are 0 sticky-learned MACs. fred# show port-security interface fastEthernet 0/1 Port Security : Enabled Port status : Err-Disabled Violation mode : Shutdown Maximum MAC Addresses : 1 Total MAC Addresses : 1 Configured MAC Addresses : 1 Sticky MAC Addresses : 0 Aging time : 0 mins Aging type : Absolute SecureStatic address aging : Disabled Security Violation count : 1
FA0/2 shows as SecureUp, meaning that port security has not seen any violations on this port. Note also at the end of the stanza that the security violations count is 0. It lists the fact that one sticky MAC address has been learned. fred# show port-security interface fastEthernet 0/2 Port Security : Enabled Port status : SecureUp Violation mode : Shutdown Maximum MAC Addresses : 1 Total MAC Addresses : 1 Configured MAC Addresses : 0 Sticky MAC Addresses : 1 Aging time : 0 mins Aging type : Absolute SecureStatic address aging : Disabled Security Violation count : 0
! Note the updated configuration in the switch. Due to the sticky option, the ! switch added the last shown configuration command.
Example 18-8 Using Port Security to Define Correct MAC Addresses Connected to Particular Interfaces (Continued)
|
Fred# show running-config |
||
|
(Lines omitted for brevity) |
||
|
interface FastEthernet0/2 |
||
|
switchport mode access |
||
|
switchport port-security |
||
|
switchport port-security mac |
address |
sticky |
|
switchport port-security mac |
address |
sticky 0200.2222.2222 |
The final part of the example shows that sticky learning updated the running configuration. The MAC address is stored in the running configuration, but it is stored in a command that also uses the sticky keyword, differentiating it from a truly statically configured MAC. Note that the switch does not automatically save the configuration in the startup-config file.
Dynamic ARP Inspection
A switch can use DAI to prevent certain types of attacks that leverage the use of IP ARP messages. To appreciate just how those attacks work, you need to keep in mind several detailed points about the contents of ARP messages. Figure 18-4 shows a simple example with the appropriate usage of ARP messages, with PC-A finding PC-B's MAC address.
Figure 18-4 Normal Use of ARP, Including Ethernet Addresses and ARP Fields
\ Topic
ARP Request Eth. Header ARP Message
ARP Reply
Eth. Header ARP Message
ARP Request Eth. Header ARP Message
ARP Reply
Eth. Header ARP Message
|
SRC |
= MAC-A |
SRC |
= MAC-A, SRC = IP-A |
SRC |
= MAC-B |
SRC |
= MAC-B, SRC |
= IP-B |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DST |
= b'cast |
TRG |
= ???, TRG = IP-B |
© |
DST |
= MAC-A |
TRG |
= MAC-A, TRG |
IP-A MAC-A PC-B IP-B MAC-B Fa0/2 PC-A IP-A MAC-A PC-B IP-B MAC-B Attacker PC-C MAC-C 1. PC-A Sends ARP Broadcast Looking for IP-B's MAC Address (Target MAC) 2. PC-B Sends LAN Unicast ARP Reply Fa0/2 Fa0/3 The ARP message itself does not include an IP header. However, it does include four important addressing fields: the source MAC and IP address of the sender of the message, and the target MAC and IP address. For an ARP request, the target IP lists the IP address whose MAC needs to be found, and the target MAC Address field is empty, as that is the missing information. Note that the ARP reply (a LAN unicast) uses the source MAC field to imply the MAC address value—for example, PC-B sets the source MAC inside the ARP message to its own MAC address, and the source IP to its own IP address. An attacker can form a man-in-the-middle attack in a LAN by creative use of gratuitous ARPs. A gratuitous ARP occurs when a host sends an ARP reply, without even seeing an ARP request, and with a broadcast destination Ethernet address. The more typical ARP reply in Figure 18-4 shows the ARP reply as a unicast, meaning that only the host that sent the request will learn an ARP entry; by broadcasting the gratuitous ARP, all hosts on the LAN will learn an ARP entry. While gratuitous ARPs can be used to good effect, they can also be used by an attacker. The attacker can send a gratuitous ARP, claiming to be an IP address of a legitimate host. All the hosts in the subnet (including routers and switches) update their ARP tables, pointing to the attacker's MAC address—and then later sending frames to the attacker instead of to the true host. Figure 18-5 depicts the process. Figure 18-5 Man-in-the-Middle Attack Using Gratuitous ARPs Topic PC-A ARP Table SW1 Forwarding Table PC-A ARP Table
SW1 Forwarding Table
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||