PDA

View Full Version : RNMacchange - A script that changes your MAC Address to a random one automatically



spicewolf
2016-08-06, 13:10
Randomnetmacchange (RNMacchange for short) is my first simple tiny bash script
The Features are

Spoof the host's MAC Address at set intervals
Stops changing the MAC Address when connected to an Ethernet or WiFi connection
Stops/starts switching function based on whether you are connected to a network, not an Internet connection which allows compatibility to networks that do not have Internet

In other words the program changes your MAC Address when its not connected to a network but stops when it is while still having a spoofed MAC Address. I created this script because i found that i couldn't find any built in easy to setup features in Kali Linux that does this so i thought i could make and share this to people (mostly newbies) that may be interested in finding something that does that.
And yes, i know the features are small but this was written up in a day that being said it is also my first script I've attempted in creating. I am going to provide some small updates in the future to make this script more powerful.

This helps with anonymity as it changes and doesn't reveal your actual MAC Address so you can't be physically tracked and also helps people not spy on what your doing based on your MAC Address, please note that this is script will not COMPLETELY make you anonymous it only stops people from taking advantage of your MAC Address meaning that there is still other methods available of tracking you but this just eliminates a big one.

I am going to point out 1 issue with the script, there isn't a function for the user to stop it changing the MAC Address when you not connected to a network this is an issue because this makes it not viable for situations were you need to specifically change your MAC Address to another in-order to connect to a network that has MAC Address Filtering enabled, there will be an update to fix this.

I am accepting feedback on the script and suggestions to changes.


Installing the script

#! /bin/bash -x
while [ 1 ]
do
sleep 10
if ifconfig wlan0 | grep "inet" >> /dev/null; then
##just some filler to not get the unexpected 'else' token message
echo "connected"
else
if ifconfig eth0 \ grep "inet" >> /dev/null; then
##just some filler to not get the unexpected 'else' token message
echo "connected"
else
## The echos could perhaps be used injunction with other applications (grep)
echo "not connected, macchange in effect"
#Turns off the interfaces so we can do some macchange magic
ifconfig eth0 down
ifconfig wlan0 down
#Changes the mac address on eth0 to a random one
macchanger -r eth0
ifconfig eth0 up
macchanger -r wlan0
ifconfig wlan0 up
## waits 50 seconds before changing the mac address, you could change this to something less or more depending on your preference
sleep 50
##closes the if loops and done also closes the do statement
fi
fi
done


IMPORTANT NOTES: Change wlan0 and eth0 to your interfaces names, wlan0 being wifi and eth0 being ethernet cable, you can check the names by running this in terminal 'ifconfig' without quotes (Ignore the interface name called 'lo' its not needed for MAC Address changing.

This requires an program called 'macchanger' to download do in terminal 'apt-get install macchanger' or 'pacman -S macchanger' Or 'yum install macchanger' depending what package manager you use

Step One, In the terminal do 'yourtexteditor /bin/randomnetmacchange' without the quotes.

Step Two, Copy and paste the code into your text editor then save.

Step Three, In the terminal do 'sudo chmod 7 /bin/randomnetmacchange', if you have an error relating to unknown command remove sudo (not the program) and try again.

Step Four, You now need to configure systemd to auto run this script at startup to do this do in terminal 'yourtexteditor /etc/systemd/system/randomnetmacchange.service''

Step Five, Now copy the code below and paste it then save it.


[Unit]
Description=Changes mac address in minute intervals if not connected to a network

[Service]
Type=oneshot
ExecStart=/bin/randomnetmacchange

[Install]
WantedBy=multi-user.target


There now we have configured it to be a service that starts at boot one last step!

Step Six, Now to enable the service and reboot your computer In terminal do 'systemctl enable randomnetmacchanger.service && reboot'.
Done now the script will run at boot and change your MACAdress

Uninstalling the script
1. Remove the files that you've created during the installing process using the rm command
2. Run the command to disable the RNMacchanger service: 'systemctl disable randomnetmacchanger.service'
3. Done!
I recommend you guys sharing and starting up threads about scripts and programs you've made thats what Linux is about after all!

mmusket33
2016-08-07, 12:49
To Spicewolf

Note that settings made thru macchanger will be overwritten by Network Manager unless the same address is loaded thru Network Manager drop down menus.

Suggest you read the thread netmanmac found in these forums.

That being said, there is a new version of Network Manager which MTeams has not seen which handles clone mac addresses differently.

Musket Teams

Mr.Robot
2016-10-09, 06:12
Is this used in rolling 2016.2 x64? My wifi cards have some random MACs when at boot. And MACs keep changing while using airodump.