Introduction to MAC flooding attack and its Countermeasures

Video will be uploaded soon

A MAC Flooding Attack is a type of Layer 2 network attack that targets the security and functionality of network switches. Every switch maintains a finite-sized table called the **Content Addressable Memory (CAM) table**. This table acts as the switch's brain, storing a mapping of the MAC addresses of connected devices to the physical switch port they are connected to. When a frame arrives, the switch looks up the destination MAC address in its CAM table to determine which port to send the frame out of, ensuring efficient and direct communication.

A MAC flooding attack exploits this mechanism by overwhelming the CAM table with a massive flood of Ethernet frames, each containing a different, fake source MAC address. The switch diligently tries to learn each new MAC address and add it to its CAM table. Since the table has a limited size, it quickly fills up and enters a state known as **fail-open mode**.

In this mode, the switch no longer knows which MAC addresses belong to which ports. To ensure network connectivity is not completely lost, it falls back to behaving like a simple, non-intelligent hub. It begins broadcasting all incoming network traffic out of every single port on the switch.

The Goal of a MAC Flooding Attack

The attacker's goal is to turn a smart switch into a dumb hub. Once the switch is broadcasting all traffic, the attacker, who is connected to one of the ports, can use a packet sniffer (like Wireshark or tcpdump) to intercept and capture all the traffic flowing between other devices on the network. This allows them to eavesdrop on sensitive, unencrypted data such as login credentials, emails, and file transfers that would otherwise not have been visible to them.


Countermeasures to Prevent MAC Flooding

Preventing MAC flooding attacks relies on configuring security features on the network switch itself. The primary and most effective countermeasure is **Port Security**.

1. Port Security

Port security is a feature available on most managed switches that allows an administrator to control which MAC addresses are allowed to send traffic on a specific port. It provides granular control and can be configured in several ways:

  • Limiting the Number of MAC Addresses: The most direct defense is to set a limit on the number of MAC addresses that can be learned on a single port. For a port connected to a single workstation, this limit can be set to a low number, like 1 or 2. When an attacker tries to flood the port with thousands of fake MAC addresses, the limit is quickly reached.
    ! Cisco IOS Command Example
    switchport port-security maximum 2
  • Defining a Violation Action: You can configure what the switch should do when a violation occurs (i.e., when the maximum number of MAC addresses is exceeded). The common actions are:
    • Shutdown (default): The switch port is immediately disabled and an administrator must manually re-enable it. This is the most secure option.
    • Restrict: The switch drops all frames from the violating MAC addresses but keeps the port active and sends a security notification.
    • Protect: The switch silently drops the violating frames without logging a notification.
    ! Cisco IOS Command Example
    switchport port-security violation shutdown
  • Using Sticky MAC Addresses: The switch can be configured to "stick" or dynamically learn the MAC address of the first device that connects to the port and save it to the configuration. Any subsequent device that connects with a different MAC address will trigger a security violation. This automates the process of assigning a specific device to a port.
    ! Cisco IOS Command Example
    switchport port-security mac-address sticky

2. Other Defense-in-Depth Measures

  • Implementing 802.1X Authentication: Port-based Network Access Control (PNAC) using the 802.1X standard requires devices to authenticate with a central server before gaining any access to the network, effectively preventing unauthorized devices from connecting in the first place.
  • Physical Security: Ensuring that only authorized personnel have physical access to network closets and unused network jacks in public areas helps prevent attackers from plugging in their devices.

Introduction to the `macof` Tool in Kali Linux

macof is a command-line tool that is part of the **dsniff** suite of network auditing and penetration testing tools, which comes pre-installed on Kali Linux. Its sole purpose is to execute a MAC flooding attack.

The tool is incredibly simple yet highly effective. When run, it instantly begins generating and sending a massive flood of Ethernet frames onto the local network, with each frame having a randomized, non-existent source MAC address. It can generate hundreds of thousands of these frames per minute, quickly overwhelming the CAM table of most unconfigured switches.

How to Use `macof`

Using `macof` is straightforward but should only be done on a network where you have explicit permission to perform security testing. Running it on a live, production network can cause a significant disruption.

The basic command requires specifying the network interface to send the flood from.

  1. Identify Your Network Interface: First, use a command like `ip addr` or `ifconfig` to find the name of your network interface (e.g., `eth0`).
  2. Run the Attack: To start the flood, run the following command with root privileges:
    sudo macof -i eth0

    The -i flag specifies the interface. Immediately, `macof` will begin sending frames. There is no verbose output; it simply runs until you stop it with Ctrl+C. While it's running, the switch it is connected to will likely enter its fail-open state, and you can then use a tool like Wireshark on the same machine to capture traffic from other devices on the network segment.

You can also add other options, such as specifying a destination IP address with the `-d` flag, but the basic interface flag is all that is needed for a classic MAC flooding attack.

Disclaimer

The content provided on this page is for educational purposes only. It is intended to demonstrate the vulnerabilities of computer systems and networks and to promote ethical hacking practices. Any unauthorized use of the information or tools presented here is strictly prohibited and may violate applicable laws.

By accessing and using this information, you agree to the following:

  • No Malicious Use: You will not use the information or tools to harm others, damage property, or violate any laws.
  • Ethical Use: You will use the information and tools responsibly and ethically, respecting the privacy and security of others.
  • Legal Compliance: You will comply with all applicable laws and regulations regarding hacking and cybersecurity.

It is important to note that hacking systems without proper authorization is illegal and unethical. If you have concerns about the security of your own systems, please consult with a qualified security professional.