Introduction:
In the world of ethical hacking and cybersecurity, anonymity and privacy are paramount. One way to enhance your online security is by changing your device’s Media Access Control (MAC) address. In this blog post, we’ll embark on an exciting journey to create a MAC Changer Tool using Python specifically designed for Kali Linux. By the end of this tutorial, you’ll have your own custom tool to change your MAC address effortlessly, empowering you with greater control over your digital footprint. Let’s dive into the world of Python and MAC address manipulation!
Understanding the MAC Changer Project:
A Media Access Control (MAC) address is a unique identifier assigned to network interfaces on devices. By changing your MAC address, you can obscure your device’s identity and enhance your online anonymity, making it challenging for others to track or identify you.
I named this MAC Changer tool as “Mika” that modifies the MAC address of a network interface to mask its identity. This tool have all the useful options that you need, you can use this tool to set random or specific mac address.
Requirements:
Before we proceed, ensure you have Python installed on your Kali Linux system. Kali Linux usually comes with Python pre-installed. If not, you can install it using the package manager.
This project will utilize Python3’s subprocess module to interact with Kali Linux terminal commands, random module to generate random character for mac. re module also known as RegEX or Regular Expression, to search specific pattern in a string and argparse module to parse command line arguments.
Python Code:
Create two python file named “mika.py” and “logo.py” in the same folder, copy and paste the code which is given below respectively. You can also download the gitHub repositiory zip file of this project.
#!/usr/bin/python
# importing modules
import subprocess
import re
import random as r
from argparse import ArgumentParser # install it using "pip install argparse"
from logo import logo
# creating a function to capture the arguments and options entered by the user in the terminal. And also checking whether the user entered arguments are right or not.
def get_argument():
parser = ArgumentParser(description="----- A simple and powerful MAC changer tool -----", prog="python3 mika.py")
parser.add_argument("-i", dest="interface", help="Specify the name of interface")
parser.add_argument("-m", dest="new_mac", help="Specify a new mac or type 'r' to set random MAC Address insted of new mac")
args = parser.parse_args()
if not args.interface:
parser.error("[-] Please specify an interface, use --help for more info.")
elif not args.new_mac:
parser.error("[-] Please specify a new mac, use --help for more info.")
return args
# Creating a function for capturing current mac address.
def get_mac(interface):
interface_info = str(subprocess.run(["sudo", "ifconfig", interface], capture_output=True))
interface_mac = re.search("\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", interface_info)
return interface_mac.group(0)
# printing the logo
print(logo)
# capturing the option entered with arguments in terminal.
arg = get_argument()
interface = arg.interface
new_mac = arg.new_mac
# generating a random mac address.
if new_mac == "r":
x = r.randint(0, 9)
y = r.randint(0, 9)
z = r.randint(0, 9)
new_mac = f"00:{x}{y}:{y}{z}:{z}{x}:{y}{x}:{z}{y}"
# capturing the current mac address.
current_mac = get_mac(interface)
# executing the kali linux terminal commands for changing the mac address.
subprocess.run(["sudo", "ifconfig", interface, "down"])
subprocess.run(["sudo", "ifconfig", interface, "hw", "ether", new_mac])
subprocess.run(["sudo", "ifconfig", interface, "up"])
# capturing the changed mac address.
changed_mac = get_mac(interface)
# Showing whether your mac address has changed or not.
if current_mac != changed_mac:
print(f'Now, Your MAC for "{interface}" is successfully change from "{current_mac}" to "{changed_mac}"\n')
else:
print("Try Again!!!\n")
logo = '''
▄▄▄▄███▄▄▄▄ ▄█ ▄█ ▄█▄ ▄████████
▄██▀▀▀███▀▀▀██▄ ███ ███ ▄███▀ ███ ███
███ ███ ███ ███▌ ███▐██▀ ███ ███
███ ███ ███ ███▌ ▄█████▀ ███ ███
███ ███ ███ ███▌ ▀▀█████▄ ▀███████████
███ ███ ███ ███ ███▐██▄ ███ ███
███ ███ ███ ███ ███ ▀███▄ ███ ███
▀█ ███ █▀ █▀ ███ ▀█▀ ███ █▀
▀
Aman Aadi | www.amanaadi.com
'''
Commands and Output:
These are the commands which is used for the Mika tool:
To show the help menu of the tool.
python3 mika.py -h
To set a specific mac address for a specific network interface.
python3 mika.py -i [interface] -m [new mac]
To automatically set random mac address for a specific network interface.
python3 mika.py -i [interface] -m r
Conclusion:
Congratulations! You’ve successfully created a MAC Changer Tool using Python for Kali Linux. With this custom tool at your disposal, you can change your device’s MAC address, enhancing your privacy and security during penetration testing or any other ethical hacking activities. Always use this tool responsibly and ensure you have the necessary permissions before altering your MAC address. Python continues to be a powerful ally in the world of ethical hacking, allowing you to customize tools and take control of your digital identity. Happy coding, and may your journey in cybersecurity be filled with discovery and empowerment!