Learn about MAC Spoofing using Practical Example

CompTIA PenTest PT0-002

What is MAC Spoofing?

MAC Spoofing is the process of changing the Media Access Control (MAC) address of a network interface on a device that’s connected to a network. The MAC address is unique and it’s assigned to every network interface for data sending and receiving at the data link layer of the networking segment. In other words, it makes sure every network is uniquely identifiable from others.
These addresses are 48-bit (6-byte) numbers usually written in hexadecimal format and divided into pairs using hyphens or colons (e.g., 00:1A:2B:3C:4D:5E). When you buy a networking interface card (NIC), each NIC has its own MAC address embedded into it by manufacturers.

But thanks to software tools and techniques, this address can be modified. This alteration is known as MAC spoofing and can be done for many legitimate reasons such as privacy concerns, testing or troubleshooting within networks. But obviously, like everything in tech, there are bad ways this can get exploited too!

Modifying your MAC allows your device to pretend to be another by assuming its MAC address instead. Systems on networks will think they’re dealing with another device when they receive packets with that updated MAC address. So clearly you see how this process can cause some serious security issues! If you want your cybersecurity efforts to be top-notch then you need to learn about this hacking technique.


Demonstrate impacts of MAC Spoofing

In this lab, we’ll explore MAC spoofing by performing it on a Kali Linux which we created under Setup Lab Environment for CompTIA PenTest+ Exam (PT0-002). Now we have created our Kali Linux on VirtualBox and there is a known limitation on changing MAC address on VMs in VirtualBox i.e. the interface will loose connectivity.

Due to this issue we will not be able to perform any test across the VMs, so we will use some hack to demonstrate how an attacker can use MAC Spoofing to manipulate the MAC Address and pretend to be someone else in the network. But if you intend to work at network layer then you would need information of all network devices and their MAC Addresses which you can get by using tools such as arp-scan and netdiscover:

Use arp-scan to discover network hosts along with their MAC Address:

Learn about MAC Spoofing using Practical Example

Similarly using netdiscover to scan remote hosts along with their MAC Address:

Learn about MAC Spoofing using Practical Example

While MAC address filtering is generally applied at the network layer and not typically used for controlling access to web servers, but for demonstration we will simulate a scenario where a script checks the MAC address before allowing access to content.


Step 1. Setup Web Server

Install Apache and PHP packages if not already installed using apt package manager. You need either root access or sudo access to be able to execute these commands:

sudo apt update
sudo apt install apache2 php libapache2-mod-php

Start the Apache Service:

sudo systemctl start apache2

Check the status of the Apache service:

sudo systemctl status apache2
Learn about MAC Spoofing using Practical Example

Verify Apache is Running by accessing http://localhost in a web browser or using curl

curl http://localhost

This should give you a big HTML output which basically is the default Apache2 web page.


Step 2: Create a Simple MAC Address Checker Script

Create a Script to check the MAC address and serve content based on the MAC address match. Navigate to the web server's root directory (e.g., /var/www/html) and create a new PHP file:

cd /var/www/html
sudo touch check_mac.php
sudo nano check_mac.php

Enter the following PHP code into check_mac.php. Replace "00:11:22:33:44:55" with the allowed MAC address.

// Allowed MAC address
$allowed_mac = "00:11:22:33:44:55";

// Command to get the MAC address of the server's primary network interface
$mac = shell_exec("ip link show eth0 | grep link/ether | awk '{print $2}'");
$mac = trim($mac);

// Check if the current MAC matches the allowed MAC
if ($mac == $allowed_mac) {
    echo "Access granted to MAC address: $mac";
    // Serve your content here
} else {
    echo "Access denied for MAC address: $mac";

This script is a basic example. In a real environment, MAC address filtering would be handled at a lower network level, not within a web application.


Step 3: Change the MAC Address and Test Access

Use ifconfig to check the current MAC address of Kali Linux’s network interface. In my case I intend to change MAC of eth0 so I will directly check eth0 MAC Address but you can adjust the command based on your interface:

└─# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::570:f0af:411c:e577  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:1e:36:4b  txqueuelen 1000  (Ethernet)
        RX packets 41  bytes 8020 (7.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 7828 (7.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Update check_mac.php to use your interface's MAC Address to verify the access:

$allowed_mac = "08:00:27:1e:36:4a";

Verify the access to web server:

Learn about MAC Spoofing using Practical Example

As expected the current MAC Address has access to the web server.

Now use macchanger to change the MAC address, to set a specific MAC address. You can also read Change MAC Address in Linux [Temporary & Persistent] for more examples.

sudo macchanger --mac=XX:XX:XX:XX:XX:XX eth0

OR To use a random MAC address:

sudo macchanger -r eth0

In our case I will just change the last digit of the MAC from 4a to 4b:

└─# macchanger --mac=08:00:27:1e:36:4b eth0
Current MAC:   08:00:27:1e:36:4a (CADMUS COMPUTER SYSTEMS)
Permanent MAC: 08:00:27:1e:36:4a (CADMUS COMPUTER SYSTEMS)
New MAC:       08:00:27:1e:36:4b (CADMUS COMPUTER SYSTEMS)
Learn about MAC Spoofing using Practical Example

Confirm the MAC address has been changed successfully using ifconfig eth0.

Learn about MAC Spoofing using Practical Example

Let's retry to access the web server:

Learn about MAC Spoofing using Practical Example

As expected this time the access was denied.

Now you can revert the whole situation and imagine we could bypass security if we were to find out that confidential data was only accessible by a device with a specific MAC address and then change our MAC address to that of our machine. This situation exemplifies how essential it is for effective safeguard of sensitive material must go beyond mere MAC filtering.


How to Mitigate MAC Spoofing

  1. Dynamic ARP Inspection (DAI): DAI prevents any possible MAC spoofing attack through restricting transmission of only the legitimate Address Resolution Protocol requests and replies. It verifies the association between IP addresses and their corresponding MAC addresses, discarding those which are incorrect hence minimizing chances of ARP poisoning used in mac-spoofing tactics.
  2. Use IP-MAC Binding: To prevent unauthorized people from connecting their devices onto your network, every IP address on your network should be tied to its own unique MAC address stored in an encrypted database. The latter can be facilitated by DHCP snooping functionality that checks attempts to use fake IP or MAC addresses.
  3. Employ 802.1X Authentication: 802.1X describes a system where networks can authenticate and limit user access to those who have been authenticated using proper means. It is made up of three parts; namely supplicant (client device), authenticator (network device), as well as authentication server e.g., RADIUS). Even when someone has spoofed his/her MAC, it is not possible for unknown devices to connect themselves with the system due to 802.1X.
  4. Network Traffic Monitoring: Frequent scrutiny over the network like checking on any irregularities taking place within should enable one detect as well as mitigate against suspicious activities such as MAC spoofing in good time. It can also be automized using Intrusion Detection Systems (IDS) or Intrusion Prevention Systems (IPS) for better results during detection phase this allows extracting patterns indicative of possible spoofing attempts.
  5. Use VPNs For Secure Communication: Virtual Private Networks(VPNs) encrypt all communications made through them which means that even if a device is used to spoof the MAC address it will not be able to intercept or alter the data transmission. Encouraging people to use VPNs especially in sensitive transactions increases security at an extra layer.



In conclusion, MAC spoofing is a major threat. Attackers can bypass network access controls, assume the identity of authorized devices, and gain unauthorized access to sensitive data. They exploit the inherent trust in physical hardware addresses to do this and show that security measures have got to be stronger than just filtering MAC addresses.
We’ve experimented in controlled environments with practical demonstrations of how MAC spoofing works and its potential impact on network security. The point here is that cybersecurity professionals need hands-on experience to spot these threats and stop them.

To combat the risks of MAC spoofing organizations should layer their security approach. This means deploying Dynamic ARP Inspection, IP-MAC binding, 802.1X authentication, keeping a regular eye on your network, using VPNs for encrypted communications and educating your employees about safe network practices. Also stay up-to-date with patches because they protect you from MAC spoofing and other dangers.

By getting what makes MAC spoofing tick and putting mitigation strategies into action organizations can seriously improve their network security posture – protecting their most critical assets from breaches or unauthorized parties.


Views: 288
Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment