Welcome to my second blog. Today I will be demonstrating how we are going to be able to change our MAC address with only a python script lets kick off.
In this blog, we will try to change our MAC address on the Parrot machine.Let’s start our terminator which i personally use. To change the MAC address we need to install few things such as the net-tools package.In most Linux distribution, these tools have been installed and also available.However, if not we should install it you can install it using this commands
normally, it will prompt you for a password but i am already a root user thus we do not have to type “sudo” once the tool has been installed you can view it with the following command
if everything goes well you will immediately see this one:)
There are couple of thing which we need to cover such as “eth0” and “lo”, “eth0” is actually the name of NIC, whereas “lo” is the loopback adapter. For now we can just ignore loop-back adapter for now however i shall explain it later. We also have “inet” field which represents the private IP address of the Parrot machine as you can see is “inet6" the ipv6 of the Parrot machine and of course we also have “ether” is the MAC address obvious and this the field we are going to change.
If you want to change your MAC address we need to firstly shut down the network interface in order to shut down the interface u can just type;
This command will be able to shut down the NIC named as eth0. If you do not see any error which is good you can step forward with your steps.
Now we are going to type in the ifconfig command again, you will see the following command take a look:)
what you are seeing is only the loopback adapter and that eth0 has been turned off or gone.To change our MAC address, you can run the following command.For instance let’s say you are willing your MAC address to be 00:22:44:66:88:99 you can do as follow
this command shall change the MAC address as well as the ether parameter of this NIC
Now if there is no error, this means that the command ran successfully and that is great is it not? at this point we can turn on the interface again by running the following command
Now let’s run the ifconfig command again and see what happens
Here you can see that the MAC address has been changed thus that means we understood what happened and if we want to scan something in a network, this MAC address will be shown as fake MAC address instead of our real MAC.
CREATİNG A PYTHON SCRİPT
So far, we have typed and understood how we could change the MAC address with some useful commands and now we are going to create our script manually and that will help us to change it.To do this, we need to find a way to run bash commands with the help of Python.Fortunately, Python has some standard library that uses to run system command called “subprocess” and this library allows us to interact with the underlying Operating System.
We could import this library so as to run our script properly because without this it won’t be working thus keep in you mind add this in you script:) let’s say you want to know some information about eth0 you can run this following command
This function requires a couple of commands of course that makes programming enjoyable and now we have to combine it with import and this command lets see
and in order to run this script we have to add python and then the file like so
So far so good, you know how to run and add library and system commands as well you can of course add more functionality and repeat the preceding commands using python. Let’s make one which will be represented as follow
After this script u can switch to your current terminal and type “python3 mac_changer.py” u will be able to see the result
Of course didn’t very well but you got me point:)
In this blog we have learnt a lot don’t you as a pentester you ought to understand and read the syntax of these scripts especially in CTF challenges you might be able to handle a lot so we also learnt how we can protect ourselves on a local network by spoofing our MAC address for scanning purposes and as well how we could use Python language for this purposes
Thanks for reading this and good luck:)
please stay sharp for more CTF challenges on my channel