Jump to content

jjd's mac changing script


jjd

Recommended Posts

theres a much more elegant solution tygra came up with that I worked into my original code see post #22 it also has the download

https://forums.hak5.org/index.php?/topic/30827-jjds-mac-changing-script/?p=232158

ok so i updated my mac changer a little bit....

again keep in mind i am no programmer!

if anyone wants to build this into an infusion by all means go for it or if you want to change and improve it please do but post the output here for teh community

it does throw a few errors but everything does work.

changemac looks for a list of possible mac prefix's in the file /sd/maclist.lst if the file does not exist it uses a dell mac (00:06:5B)

you can create your own list in this format:

00:00:01 Xerox                  # XEROX CORPORATION
00:00:02 Xerox                  # XEROX CORPORATION

changemac will randomly chose a prefix from the file so make sure there is no extra garbage in there.... i made my file by using http://anonsvn.wireshark.org/wireshark/trunk/manuf and deleting all the lines at the top that start with # and a bunch of non relevant lines at the bottom that did not follow the format i needed.

the reason I did an install is so i can keep the files on my sd and not have to reconfigure everytime I reset the pineapple

its now three parts:

changemac a script to change to a random mac, set a specific mac, or clean the wireless file to default mac's

maccleaner a /etc/init.d script that cleans the wireless file to default mac addresses on boot

install an install file to install dependancies, move files to correct places, and set permissions

I will attach a zip with the files if anyone wants them

install:

#!/bin/bashclear
echo "installing bc"
echo ""
opkg update
opkg install bc
cp -f maccleaner /etc/init.d/maccleaner
chmod +x /etc/init.d/maccleaner
/etc/init.d/maccleaner enable
cp -f changemac /usr/bin/changemac
chmod +x /usr/bin/changemac
        clear
        echo "  ***menu to come***"
        echo "for now please use:"
        echo "changemac -r                              to change your mac for next boot"
        echo "changemac -r now                          to change your mac now"
        echo "changemac -c                              to change your mac back to stock now"
        echo "changemac -m [wlan0 mac] [wlan1 mac]      to change to specified mac"

changemac:

#!/bin/bash

function randommac {
RANGE=255
number=$RANDOM
numbera=$RANDOM
numberb=$RANDOM
#generate random numbers
let "number %= $RANGE"
let "numbera %= $RANGE"
let "numberb %= $RANGE"
#ensure they are less than ceiling
FILE=/sd/maclist.lst
if [ -f $FILE ];then
   getmac
else
   octets='00:06:5B' #set mac to dell
fi
#getmac
#octets='00:06:5B' #set mac to dell
octeta=`echo "obase=16;$number" | bc`
octetb=`echo "obase=16;$numbera" | bc`
octetc=`echo "obase=16;$numberb" | bc`
#hec conversion
macadd="${octets}:${octeta}:${octetb}:${octetc}"
#generate mac
echo $macadd
}


function getmac {
let "n=${RANDOM}%$(wc -l < $FILE)"
RANDMACF=$(head -n $n $FILE | tail -1)
#echo $RANDMACF
octets=${RANDMACF:0:8}
#echo $RANDMAC
}


function changemac {
sed -i '/option device '\''radio0'\''/ a \option macaddr '$mac0' #fakemac' /etc/config/wireless
sed -i '/option device '\''radio1'\''/ a \option macaddr '$mac1' #fakemac' /etc/config/wireless
sed -i '/option device   radio0/ a \option macaddr '$mac0' #fakemac' /etc/config/wireless
sed -i '/option device   radio1/ a \option macaddr '$mac1' #fakemac' /etc/config/wireless
echo "wlan0 = $mac0"
echo "wlan1 = $mac1"
}


function cleanup {
#clean up
sed -i '/fakemac/d' /etc/config/wireless
}


/etc/init.d/maccleaner enable


if [ $1 = "-r" -a $2 = "now" ]; then
clear
echo "Changes will take effect now"
cleanup
ifconfig wlan0 down
ifconfig wlan1 down
mac0=$(randommac)
mac1=$(randommac)
changemac
wifi


elif [ $1 = "-r" ]; then
        echo "Changes will take effect on next boot"
        cleanup
        mac0=$(randommac)
        mac1=$(randommac)
        changemac
/etc/init.d/maccleaner disable


elif [ $1 = "-m" ]; then
        echo "Please wait"
cleanup
ifconfig wlan0 down
ifconfig wlan1 down
mac0=$2
mac1=$3
changemac
wifi


elif [ $1 = "-c" ]; then
echo "Cleaning up"
ifconfig wlan0 down 
ifconfig wlan1 down
cleanup
wifi


else
clear
echo " ***menu to come***"
echo "for now please use:" 
echo "changemac -r to change your mac for next boot"
echo "changemac -r now to change your mac now"
echo "changemac -c to change your mac back to stock now"
echo "changemac -m [wlan0 mac] [wlan1 mac]  to change to specified mac"
fi

maccleaner:

#!/bin/sh /etc/rc.common
# resets mac address's to stock


START=11
STOP=15


start() {        
        sed -i '/fakemac/d' /etc/config/wireless
}                 


stop() {          
        sed -i '/fakemac/d' /etc/config/wireless
}
Edited by jjd
Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

I will add a feature so random uses any mac from http://anonsvn.wireshark.org/wireshark/trunk/manuf

edit:

update done

changemac now looks for a list of possible mac prefix's in the file /sd/maclist.lst if the file does not exist it uses a dell mac (00:06:5B)

you can create your own list in this format:

00:00:01 Xerox                  # XEROX CORPORATION
00:00:02 Xerox                  # XEROX CORPORATION
00:00:03 Xerox                  # XEROX CORPORATION
00:00:04 Xerox                  # XEROX CORPORATION
00:00:05 Xerox                  # XEROX CORPORATION

changemac will randomly chose a prefix from the file so make sure there is no extra garbage in there.... i made my file by using http://anonsvn.wireshark.org/wireshark/trunk/manuf and deleting all the lines at the top that start with # and a bunch of non relevant lines at the bottom that did not follow the format i needed.

my final file was just over 1mb so i decided best to keep it on the sd card (im sure i could trim it a lot more)

Edited by jjd
Link to comment
Share on other sites

Looks good, will give it a spin. perhaps try my hand at finding why it is throwing errors, no promises on that front though.

Link to comment
Share on other sites

Looks good, will give it a spin. perhaps try my hand at finding why it is throwing errors, no promises on that front though.

the wifi command seems to always throw one the other error is with my if statement at the end but that one is just lazy coding

Edited by jjd
Link to comment
Share on other sites

Thank You jjd.

I have a quick question though.

I noticed even just trying to change to a "Random Mac" inside the Mark V, after I click it I no longer get a ssid for the pineapple at all.

If I reboot, the ssid comes back, because the mac changes back to default.

This happens without your script, just stock updated pineapple firmware.

So my question is, did everyone experience this? And will your script fix that?

Link to comment
Share on other sites

Thank You jjd.

I have a quick question though.

I noticed even just trying to change to a "Random Mac" inside the Mark V, after I click it I no longer get a ssid for the pineapple at all.

If I reboot, the ssid comes back, because the mac changes back to default.

This happens without your script, just stock updated pineapple firmware.

So my question is, did everyone experience this? And will your script fix that?

yes i had the same problem thats why i wrote the script and it should fix it

Link to comment
Share on other sites

Yay,

I will try later tonight, when I have some time, and I figure out how to actually put it in the mark v.

Thanks again.

if you download the zip from the first post you can just scp it to the mk5 then unzip and chmod +x install then ./install and it should setup

Link to comment
Share on other sites

Good Day All,

JJD - Your script looks good. I'm going to give it a try next. I've been working on the same problem, but seem to be running into two problems. Right now i'm focused on only wlan1 as I'm connecting through the AP.

This is what I've come up with:

#!/bin/sh
# Assign Random MAC 
# B.A. Hansen
#
ifconfig wlan1 down
macchanger -r wlan1
ifconfig wlan1 up
wlan1_MAC=$(ifconfig wlan1|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
uci set wireless.@wifi-device[1].macaddr=$wlan1_MAC;uci commit wireless
wifi

However I have few problems

1) When I execute the wifi command it returns the following error: PHY for wifi device radio1 not found

Based on my reading this occurs becuase the MAC I assigned doesn't match the value in /sys/class/ieee80211/phy1/macaddress and shouldn't be a problem.

1) However, even though it shows that I'm connected to my wireless router with a IP, packets don't seem to be routing from the Pineapple AP to the WiFi Connection

3) When I reboot the system gets confused and creates a second wireless entry in /etc/config/wireless

Thoughts?

Edited by Tygra
Link to comment
Share on other sites

Good Day All,

JJD - Your script looks good. I'm going to give it a try next. I've been working on the same problem, but seem to be running into two problems. Right now i'm focused on only wlan1 as I'm connecting through the AP.

This is what I've come up with:

#!/bin/sh
# Assign Random MAC 
# B.A. Hansen
#
ifconfig wlan1 down
macchanger -r wlan1
ifconfig wlan1 up
wlan1_MAC=$(ifconfig wlan1|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
uci set wireless.@wifi-device[1].macaddr=$wlan1_MAC;uci commit wireless
wifi

However I have few problems

1) When I execute the wifi command it returns the following error: PHY for wifi device radio1 not found

Based on my reading this occurs becuase the MAC I assigned doesn't match the value in /sys/class/ieee80211/phy1/macaddress and shouldn't be a problem.

1) However, even though it shows that I'm connected to my wireless router with a IP, packets don't seem to be routing from the Pineapple AP to the WiFi Connection

3) When I reboot the system gets confused and creates a second wireless entry in /etc/config/wireless

Thoughts?

what mac are you trying to change it to? i had an issue like that if i tried to change to a mac thats not valid... for testing I used 00:00:00:00:00:11 this mac is a xerox mac and worked for my testing.

although in my testing I could not get macchanger to change every time i launched wifi it changed back thats when I decided editing a config file may just be easier.

Link to comment
Share on other sites

what mac are you trying to change it to? i had an issue like that if i tried to change to a mac thats not valid... for testing I used 00:00:00:00:00:11 this mac is a xerox mac and worked for my testing.

although in my testing I could not get macchanger to change every time i launched wifi it changed back thats when I decided editing a config file may just be easier.

In the above script i'm assigning a random MAC address. I just tried:

uci set wireless.@wifi-device[1].macaddr=00:00:00:00:00:11;uci commit wireless

And I have the same problems. The above method is supposed to work with OpenWRT.

I'll be trying your script next, just thought this should work.

Thank You!

Link to comment
Share on other sites

In the above script i'm assigning a random MAC address. I just tried:

uci set wireless.@wifi-device[1].macaddr=00:00:00:00:00:11;uci commit wireless

And I have the same problems. The above method is supposed to work with OpenWRT.

I'll be trying your script next, just thought this should work.

Thank You!

I bet that changes the mac for the device in /etc/config/wireless under "config wifi-device" that will work for the realtek but not the atheros

if you change to uci set wireless.@wifi-iface[1] i think it should work

since

option macaddr 00:00:00:00:00:11

under

config wifi-iface

section of the config works
thats really all my script does i just did it a bit different
Edited by jjd
Link to comment
Share on other sites

jjd -

The "uci set wireless..." essentially does the same thing. It just is a more elegant way than directly modifying the /etc/config/wireless file.

Note: I have use the "wifi detect > /etc/config/wireless" to reset the settings after each run.

I've manually modified the /etc/config/wireless to change the MAC address, when I run wifi the following error comes up

root@Pineapple:/etc/config# wifi
PHY for wifi device radio1 not found
PHY for wifi device radio1 not found

This does seem normal because it doesn't match /sys/class/ieee80211/phy1/macaddress

However, packets still don't seem to route from wlan0 through wlan1

Also, when I restart it adds another radio

Before Reboot:

(Note this does not have the information to connect to my Cable router)

config wifi-device  radio1
        option type     mac80211
        option channel  11
        option hwmode   11g
        option macaddr  00:00:00:00:00:11

        # REMOVE THIS LINE TO ENABLE WIFI:
        # option disabled 1

config wifi-iface
        option device   radio1
        option network  lan
        option mode     ap
        option ssid     Pineapple5_424A
        option encryption none

After Reboot:

config wifi-device  radio1
        option type     mac80211
        option channel  11
        option hwmode   11g
        option macaddr  00:00:00:00:00:11

        # REMOVE THIS LINE TO ENABLE WIFI:
        # option disabled 1

config wifi-iface
        option device   radio1
        option network  lan
        option mode     ap
        option ssid     Pineapple5_424A
        option encryption none

config wifi-device  radio2
        option type     mac80211
        option channel  11
        option hwmode   11g
        option macaddr  00:13:37:81:42:4a

        # REMOVE THIS LINE TO ENABLE WIFI:
        # option disabled 1

config wifi-iface
        option device   radio2
        option network  lan
        option mode     ap
        option ssid     Pineapple5_424A
        option encryption none

jjd - is this happening to you?

Link to comment
Share on other sites

ifconfig wlan1 down
macchanger -r wlan1
ifconfig wlan1 up
wlan1_MAC=$(ifconfig wlan1|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
uci set wireless.@wifi-iface[1].macaddr=$wlan1_MAC;uci commit wireless
wifi
this is currently working for me
config wifi-device 'radio0'
option type 'mac80211'
option channel '11'
option hwmode '11ng'
option macaddr '00:13:37:##:##:##'
option htmode 'HT20'
list ht_capab 'SHORT-GI-20'
list ht_capab 'SHORT-GI-40'
list ht_capab 'RX-STBC1'
list ht_capab 'DSSS_CCK-40'


config wifi-iface
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'Pineapple5'
option encryption 'none'


config wifi-device 'radio1'
option type 'mac80211'
option channel '11'
option hwmode '11g'
option macaddr '00:13:37:##:##:##'


config wifi-iface
option device 'radio1'
option mode 'sta'
option network 'wan'
option ssid 'WiFi-is-cool'
option key '[mynetwork key]'
option encryption 'psk2+ccmp'
option macaddr '00:00:00:00:00:11'

that only question is using your code how do we set the iface macaddr for radio0?

Edited by jjd
Link to comment
Share on other sites

jjd -

There we go, that was it. Thank you!! Needed to change iface not device!!

In theory:

ifconfig wlan0 down
macchanger -r wlan0
ifconfig wlan0 up
wlan0_MAC=$(ifconfig wlan0|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
uci set wireless.@wifi-iface[0].macaddr=$wlan0_MAC;uci commit wireless
wifi

The two processes could of-course be combined.

I've also been trying to work on custom power settings. I've been on this other thread https://forums.hak5.org/index.php?/topic/30748-txpower-woes/

Think I got this figured out as well:

uci set wireless.@wifi-device[1].country=BO
uci set wireless.@wifi-device[1].txpower=29
uci commit wireless
wifi

I want to increase the power of my WiFi without running at full power. I've read that it can cause serious heat problems, so I want to run at almost full power. Problem with just changing the region code to "BO" by using "iw reg set BO" is OpenWRT defaults to FULL power.

All these features could be added to the WiFi Manager...

Edited by Tygra
Link to comment
Share on other sites

great!

ifconfig wlan1 down
echo "wlan1"
macchanger -r wlan1
ifconfig wlan1 up
ifconfig wlan0 down
echo "wlan0"
macchanger -r wlan0
ifconfig wlan0 up
wlan1_MAC=$(ifconfig wlan1|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
wlan0_MAC=$(ifconfig wlan0|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
#wlan1_MAC="00:00:00:00:00:11"
#wlan0_MAC="00:00:00:00:00:22"
uci set wireless.@wifi-iface[0].macaddr=$wlan0_MAC;uci commit wireless
uci set wireless.@wifi-iface[1].macaddr=$wlan1_MAC;uci commit wireless
wifi

and this changes us back to stock

wlan0_MAC=""
wlan1_MAC=""
uci set wireless.@wifi-iface[0].macaddr=$wlan0_MAC;uci commit wireless
uci set wireless.@wifi-iface[1].macaddr=$wlan1_MAC;uci commit wireless
wifi

now it just has to become an infusion.....

also wondering where macchanger gets its mac prefixes from because the script would run much faster without running macchanger & my solution above has a 1mb mac list to carry around. nm figured it out "macchanger --list"

Edited by jjd
Link to comment
Share on other sites

also wondering where macchanger gets its mac prefixes from because the script would run much faster without running macchanger & my solution above has a 1mb mac list to carry around. nm figured it out "macchanger --list"

macchanger requires the device argument to run (wlan1|wlan0), and the only way I could figure out how to get it to work was to assign the MAC to the device, then extract the MAC into a variable. The time that is being used up is bringing the devices down, and then back up. If that wasn't necessary the script would be pretty fast.

Good Job!

Link to comment
Share on other sites

ok done!

I used some of my old code and your code for changing the settings let me know what you think

If there is a file in the same dir as the script called maclist.lst it will pick a manufacturer prefix from there. In the zip attached I included a maclist.lst

If the file is not found it will use macchanger to randomize the mac but that does involve taking each radio up and down twice so takes longer to run.

bc is still required to randomize the mac without macchanger (so if you dont want to install bc delete maclist.lst to avoid errors)

install bc:

opkg update
opkg install bc
WiFi Pineapple MK5 mac address changer.
Usage: changemac [options]
changemac -r Set random mac addresses
changemac -c Set mac addresses back to default
changemac -m [wlan0 mac] [wlan1 mac] Set specific mac addresses
changemac -reset Reset wireless config to default
changemac -d Install changemac dependencies*
changemac -u Update changemac*
*Needs internet access

the script:

#!/bin/bash


function usemc {
ifconfig wlan1 down
echo "wlan1"
macchanger -r wlan1
ifconfig wlan1 up
ifconfig wlan0 down
echo "wlan0"
macchanger -r wlan0
ifconfig wlan0 up
wlan1_MAC=$(ifconfig wlan1|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
wlan0_MAC=$(ifconfig wlan0|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')


}


function randmac {
let "n=${RANDOM}%$(wc -l < $FILE)"
RANDMACF=$(head -n $n $FILE | tail -1)
#echo $RANDMACF
octets=${RANDMACF:7:8}
RANGE=255
number=$RANDOM
numbera=$RANDOM
numberb=$RANDOM
#generate random numbers
let "number %= $RANGE"
let "numbera %= $RANGE"
let "numberb %= $RANGE"
#ensure they are less than ceiling
octeta=`echo "obase=16;$number" | bc`
octetb=`echo "obase=16;$numbera" | bc`
octetc=`echo "obase=16;$numberb" | bc`
#hec conversion
macadd="${octets}:${octeta}:${octetb}:${octetc}"
#generate mac
echo $macadd 
}


function changerand {
FILE=maclist.lst
if [ -f $FILE ];then
wlan0_MAC=$(randmac)
wlan1_MAC=$(randmac)
echo "wlan0"
echo "New mac address: "$wlan0_MAC
echo "wlan1"
echo "new mac address: "$wlan1_MAC 
else
usemc
fi


changeset 
}


function changeset {
uci set wireless.@wifi-iface[0].macaddr=$wlan0_MAC;uci commit wireless
uci set wireless.@wifi-iface[1].macaddr=$wlan1_MAC;uci commit wireless
wifi 
}




if [ $1 = "-r" ]; then
clear
echo "Changing mac"
changerand


elif [ $1 = "-m" ]; then
    wlan0_MAC=$2
wlan1_MAC=$3
echo "wlan0"
echo "New mac address: "$wlan0_MAC
echo "wlan1"
echo "new mac address: "$wlan1_MAC
changeset


elif [ $1 = "-c" ]; then
echo "Reseting mac addresses to default"
wlan0_MAC=""
wlan1_MAC=""
changeset
else
clear
echo " ***menu to come***"
echo "for now please use:" 
echo "changemac -r to change your mac for next boot"
echo "changemac -c to change your mac back to stock now"
echo "changemac -m [wlan0 mac] [wlan1 mac]  to change to specified mac"
fi

Made an easier install for anyone interested and added an update feature.

simply run the following via ssh or through execute command from the web gui

wget -P /tmp/ http://trtsgc.com/changemac/install.sh; chmod +x install.sh; sh /tmp/install.sh
Edited by jjd
Link to comment
Share on other sites

macchanger requires the device argument to run (wlan1|wlan0), and the only way I could figure out how to get it to work was to assign the MAC to the device, then extract the MAC into a variable. The time that is being used up is bringing the devices down, and then back up. If that wasn't necessary the script would be pretty fast.

Good Job!

ya macchanger has a 300kb file that contains all the mac options so the update can use macchanger or the file.

now as far as turning it into an infusion I'll leave that to someone else as I have no idea how to do that

Link to comment
Share on other sites

jjd:

So just to clarify.

Where do you copy the files _MACOSX folder, changemac and maclist.lst files to exactly?

And the script above should be as simple as inputting it and executing under configuration > advanced > execute commands. ?

Link to comment
Share on other sites

jjd:

So just to clarify.

Where do you copy the files _MACOSX folder, changemac and maclist.lst files to exactly?

And the script above should be as simple as inputting it and executing under configuration > advanced > execute commands. ?

You don't copy the _MACOSX folder. Just the other files.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...