You are not logged in.
Pages: 1
If you are paranoid about privacy like me, you will like this little creation of mine.
EDIT: Final version of script is in post #7. Options for running it automatically at appropriate time are in post #8.
Last edited by GNUser (2019-03-25 17:03:58)
Offline
Thank you.
There is _much_ here that is useful and good
Offline
Thank you for sharing this. My only question is, how does this differ from macchanger?
Offline
This script doesn't seem to work for computers connected via ethernet.
Is there a similar script for that or how would I need to modify the script you posted?
Last edited by freenet_bro (2019-03-08 18:44:51)
Offline
@siva: Simplicity and total customizability. Why install a package when a simple shell script will do?
@freenet_bro: See posts #7 and #8.
Last edited by GNUser (2019-03-25 17:16:25)
Offline
cool, the script works.
But I don't know how to run it at boot time.
I've used `chmod +x mac-spoofer' to make it executable and copied it to `/etc/init.d/'.
Have I missed something?
Offline
I revised the scripts so that they have no special dependencies--all the utilities the scripts need are part of a standard *nix installation.
Use this version of the script to generate a random MAC address at each boot:
#!/bin/sh
iface=wlan0
# create fake mac, preserving vendor bits:
real_mac=$(ifconfig $iface | grep ether | awk '{print $2}')
vendor_bits=$(echo $real_mac | cut -d ':' -f 1-3)
random_dec1=$(shuf --input-range=0-255 -n 1); random_hex1=$(printf "%02x" $random_dec1)
random_dec2=$(shuf --input-range=0-255 -n 1); random_hex2=$(printf "%02x" $random_dec2)
random_dec3=$(shuf --input-range=0-255 -n 1); random_hex3=$(printf "%02x" $random_dec3)
fakemac=$(printf "%s:%s:%s:%s" $vendor_bits $random_hex1 $random_hex2 $random_hex3)
# apply fake mac
ip link set $iface address $fakemac
Use this version of the script if you want to keep a fake MAC address for a whole day, regardless of how many times you reboot:
#!/bin/sh
iface=wlan0
fakemac_file=/etc/fakemac-$(date +%j)
if [ -e "$fakemac_file" ]; then # we already have a fakemac file for today
true
else # remove old fakemac file and create a new one
rm -f /etc/fakemac*
real_mac=$(ifconfig $iface | grep ether | awk '{print $2}')
vendor_bits=$(echo $real_mac | cut -d ':' -f 1-3)
random_dec1=$(shuf --input-range=0-255 -n 1); random_hex1=$(printf "%02x" $random_dec1)
random_dec2=$(shuf --input-range=0-255 -n 1); random_hex2=$(printf "%02x" $random_dec2)
random_dec3=$(shuf --input-range=0-255 -n 1); random_hex3=$(printf "%02x" $random_dec3)
fakemac=$(printf "%s:%s:%s:%s" $vendor_bits $random_hex1 $random_hex2 $random_hex3)
printf "$fakemac" >$fakemac_file
fi
# apply fake mac
ip link set $iface address $(cat $fakemac_file)
BTW, notice that the scripts preserve the first 3 bytes of the MAC address, fake only the last 3 bytes. The point of this is that the first 3 bytes identify the network device's vendor/manufacturer. You don't want the vendor bytes to be random: Doing so would make your MAC address obviously fake and you would stand out. Not what we want.
Last edited by GNUser (2019-06-12 13:49:19)
Offline
@freenet_bro: There are several ways to run the mac-spoofer script (either version) at boot, as root, before connecting to the internet. The two most obvious ones are via cron or via init.
Option 1: Via cron
Open up a terminal and run this command as root: EDITOR=nano crontab -e then add these two lines to the bottom of the file:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot /path/to/mac-spoofer
Reboot and enjoy.
Option 2: Via init
There are four steps required, freenet_bro: Put the script in the /etc/init.d directory, make it executable, add LSB headers to top of script, install script links in the /etc/rc?.d directories. You missed the last two steps.
Here is what the script looks like with LSB headers (if you use a network manager other than network-manager, adjust the X-Start-Before line accordingly):
#!/bin/sh
### BEGIN INIT INFO
# Provides: mac-spoofer
# Required-Start: $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# X-Start-Before: network-manager
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: simple mac-spoofer
# Description: spoof mac address before connecting to internet
### END INIT INFO
iface=wlan0
fakemac_file=/etc/fakemac-$(date +%j)
if [ -e "$fakemac_file" ]; then # we already have a fakemac file for today
true
else # remove old fakemac file and create a new one
rm -f /etc/fakemac*
real_mac=$(ifconfig $iface | grep ether | awk '{print $2}')
vendor_bits=$(echo $real_mac | cut -d ':' -f 1-3)
random_dec1=$(shuf --input-range=0-255 -n 1); random_hex1=$(printf "%02x" $random_dec1)
random_dec2=$(shuf --input-range=0-255 -n 1); random_hex2=$(printf "%02x" $random_dec2)
random_dec3=$(shuf --input-range=0-255 -n 1); random_hex3=$(printf "%02x" $random_dec3)
fakemac=$(printf "%s:%s:%s:%s" $vendor_bits $random_hex1 $random_hex2 $random_hex3)
printf "$fakemac" >$fakemac_file
fi
# apply fake mac
ip link set $iface address $(cat $fakemac_file)
To install the script links, open up a terminal and type this as root (assuming you named the script mac-spoofer):
update-rc.d mac-spoofer defaults
Reboot and enjoy.
Last edited by GNUser (2019-06-12 13:44:07)
Offline
@GNUser: Thank you very much for the script and the explanation. I really appreciate it.
Offline
@freenet_bro: You're welcome, glad I could help. It was also good to make the script more general and less complicated.
Offline
thanks man this is awesome, I'll make a fresh install at some point and pack this into a live iso.
Offline
Pages: 1