The officially official Devuan Forum!

You are not logged in.

#1 2017-07-02 18:37:16

GNUser
Member
Registered: 2017-03-16
Posts: 570  

automatic mac address spoofer

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

#2 2017-07-05 02:57:14

PeteGozz
Member
From: Woodside South Australia
Registered: 2017-06-21
Posts: 72  

Re: automatic mac address spoofer

Thank you.
There is _much_ here that is useful and good smile

Offline

#3 2018-01-25 20:42:15

siva
Member
Registered: 2018-01-25
Posts: 282  

Re: automatic mac address spoofer

Thank you for sharing this.  My only question is, how does this differ from macchanger?

Offline

#4 2019-03-08 18:44:39

freenet_bro
Member
Registered: 2018-12-23
Posts: 16  

Re: automatic mac address spoofer

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

#5 2019-03-08 20:39:03

GNUser
Member
Registered: 2017-03-16
Posts: 570  

Re: automatic mac address spoofer

@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

#6 2019-03-09 16:27:29

freenet_bro
Member
Registered: 2018-12-23
Posts: 16  

Re: automatic mac address spoofer

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

#7 2019-03-10 13:09:53

GNUser
Member
Registered: 2017-03-16
Posts: 570  

Re: automatic mac address spoofer

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

#8 2019-03-11 01:01:46

GNUser
Member
Registered: 2017-03-16
Posts: 570  

Re: automatic mac address spoofer

@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

#9 2019-03-11 10:21:08

freenet_bro
Member
Registered: 2018-12-23
Posts: 16  

Re: automatic mac address spoofer

@GNUser: Thank you very much for the script and the explanation. I really appreciate it.

Offline

#10 2019-03-11 11:42:33

GNUser
Member
Registered: 2017-03-16
Posts: 570  

Re: automatic mac address spoofer

@freenet_bro: You're welcome, glad I could help. It was also good to make the script more general and less complicated.

Offline

#11 2019-06-12 04:43:16

czeekaj
Member
Registered: 2019-06-12
Posts: 154  

Re: automatic mac address spoofer

thanks man this is awesome, I'll make a fresh install at some point and pack this into a live iso. wink

Offline

Board footer