Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

  1. #1
    Join Date
    Aug 2010
    Beans
    407
    Distro
    Ubuntu 10.04 Lucid Lynx

    DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    New to Linux, on Windows I ran easily found freeware to pseudo-randomize the wireless MAC address and hostname on every bootup (the hostname uses a lookup table).

    What are the corresponding ways in Ubuntu 10.04 to randomize the wlan0 MAC and laptop Hostname?

    Q: Why would anyone want to randomize the hostname & wlan0 MAC address?
    A: Simple privacy. Access points, e.g., at hotspots, log those two items. Why not change them since they serve no useful purpose to the user otherwise.

    Q: Why not randomize the wlan0 MAC & hostname manually?
    A: I can. But it would be so much nicer to find a program that does this on every boot.

    Here's what I do manually to randomize the hostname:
    Code:
    sudo vi /etc/hosts
    
    Change the contents of /etc/hosts from:
    127.0.1.1      ubuntu      ubuntu
    
    Change the contents of /etc/hosts to:
    # 127.0.1.1 ubuntu ubuntu
    127.0.0.1 foo foo 
        
    sudo echo foo > /etc/hostname
    sudo reboot
    Here's what I do manually to randomize the MAC:
    Code:
    Right click on the "wireless networking" to uncheck "Enable Networking"
    Open a terminal window.
    ifconfig -a | grep HWaddr
    sudo ifconfig wlan0 down hw ether DE:AD:BE:EF:CA:FE
    sudo ifconfig wlan0 up
    !ifconfig
    Right click on the "wireless networking" to check "Enable Networking"
    I searched and found macchanger on Ubuntu, but it only simplifies slightly the task of changing the MAC address and does not randomize the MAC automatically upon every reboot:
    Code:
    sudo apt-get install macchanger
    macchanger -s wlan0
    sudo /etc/init.d/networking stop
    macchanger --another wlan0
    sudo /etc/init.d/networking start
    Since anyone who cares about privacy at hotspots would care about randomizing the data stored at the hotspot (i.e., the hostname and the MAC address), there must already be a better solution out there than what I've found so far.

    What's the best way to randomize the MAC and hostname upon reboot?


    Attached Images Attached Images
    Last edited by rocksockdoc; February 2nd, 2011 at 10:53 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Williams Lake
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    If you use the same Access points frequently you've got a lot more to worry about than your host name or MAC address. Unless you are using ssh tunneling, you're open to man-in-the-middles attacks, it's pretty trivial to find your spoofed mac address and host name.

    If you've got more than one system with a wireless device and a wireless router, you can use one of the systems running Backtrack to find what your spoofed MAC address and host name. Do try this at home, and not anywhere else

  3. #3
    Join Date
    Aug 2010
    Beans
    407
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Quote Originally Posted by cariboo907 View Post
    it's pretty trivial to find your spoofed mac address and host name.
    I don't fully understand your point but I appreciate your advice.

    I definitely understand the need for VPN-style encryption (but that's a whole 'nuther topic altogether - which I'll tackle at a later point). And, I certainly realize the wlan0 MAC address and laptop hostname are "out there" in the packets (open to man-in-the-middle-attacks); and, more importantly, they're definitely LOGGED by the access point router ... So that's why it's a "good thing" to change the MAC & hostname randomly upon every reboot (pseudo randomly is OK for my purposes).

    Backtrack to find what your spoofed MAC address and host name.
    I'll look up this "Backtrack", but, I already know that the MAC address and hostname can be found (it's logged in the access-point router and it's in every packet I think). So, I'm not sure what Backtrack will tell me that I don't already know (but I'll look it up to see if it has a MAGICAL way, perchance, of finding the original hostname and/or wlan0 MAC address even when changed daily).

    Assuming Backtrack doesn't magically find your entire history of old MAC addresses and old hostnames, it's still a "good thing" to randomly (a large lookup table is fine) assign a new MAC to the wlan0 and a new hostname to the laptop upon all reboots.

    I'm sure someone has scripted a hostname change and MAC address change upon boot; so I'd like to stand on the shoulders of giants & find that before I resort to writing my own (and publishing the results back here for others to benefit).

  4. #4
    Join Date
    Jul 2009
    Location
    127.0.0.1
    Beans
    54
    Distro
    Ubuntu

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Here is an alternative way to generate a random mac address without macchanger.


    Code:
    echo $RANDOM$RANDOM | md5sum | sed -r 's/(..)/\1:/g; s/^(.{17}).*$/\1/;'
    Enter it in your bash terminal and see for yourself

    We still have to integrate it in a startup script! I don't have a solution, but perhaps this could help.

    Code:
    oldmac=`ifconfig -a | grep HWaddr | grep wlan0 | awk '{print $NF}'`
    echo "Old mac adress: $oldmac"
    newmac=`echo $RANDOM$RANDOM | md5sum | sed -r 's/(..)/\1:/g; s/^(.{17}).*$/\1/;'`
    sudo ifconfig wlan0 down hw ether $newmac
    sudo ifconfig wlan0 up
    echo "New mac adress: $newmac"
    Last edited by slovenia; September 25th, 2010 at 12:01 AM.
    be XOR !be

  5. #5
    Join Date
    Aug 2010
    Beans
    407
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Quote Originally Posted by slovenia View Post
    alternative way to generate a random mac address

    Code:
    echo $RANDOM$RANDOM | md5sum | sed -r 's/(..)/\1:/g; s/^(.{17}).*$/\1/;'
    ooooh. Nice!

    Let's take this apart ... (looking up the bits I don't understand) ...

    - echo $RANDOM -> outputs a random integer in some shells such as bash, ksch, sh, etc.
    - echo $RANDOM$RANDOM -> outputs a bigger random integer ?
    - | md5sum -> this is a nice way, I think, to force an always-32-bit long result
    - | sed -r -> use extended regular expressions
    - 's/ -> search for
    - (..) -> any two characters
    - /\1: -> replace it with what you found first in the parenthesis and then add a colon
    - /g -> then do that again globally for each set of two characters
    - ; -> begin a new command
    - s/^ -> search for the beginning of the line
    - (.{17}) -> the magic here is a mystery to me ?
    - .*$ -> then search for any character, any number of them, until the end of the line
    - /\1/; -> and replace it with what you found first in the parenthesis

    I'm confused about how the "(.{17})" does its magic. Looking up curly braces in sed, which I've never used before, I see they "group commands", but I don't understand the command "17" at all.

    This clearly works ... but can you explain the magic to me of "(.{17})" in sed?

  6. #6
    Join Date
    Jul 2009
    Location
    127.0.0.1
    Beans
    54
    Distro
    Ubuntu

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    - echo $RANDOM -> outputs a random integer in some shells such as bash, ksch, sh, etc.
    - echo $RANDOM$RANDOM -> outputs a bigger random integer ?
    - | md5sum -> this is a nice way, I think, to force an always-32-bit long result
    - | sed -r -> use extended regular expressions
    - 's/ -> search for
    - (..) -> any two characters
    - /\1: -> replace it with what you found first in the parenthesis and then add a colon
    - /g -> then do that again globally for each set of two characters
    - ; -> begin a new command
    - s/^ -> search for the beginning of the line
    - (.{17}) -> the magic here is a mystery to me ?
    - .*$ -> then search for any character, any number of them, until the end of the line
    - /\1/; -> and replace it with what you found first in the parenthesis
    Here is my explanation:

    - echo $RANDOM -> outputs a random integer such as 1233
    - echo $RANDOM$RANDOM -> outputs two random integers joined such as 12335577
    - | md5sum -> fixed 128bit length and force HEX numbers (from 0 to f) for MAC
    - | sed -r -> use extended regular expressions
    - 's/ -> s stands for substitute
    - (..) -> any two characters
    - /\1: -> replace it with what you found first in the parenthesis and then add a colon
    - /g -> then do that again globally for each set of two characters
    - ; -> begin a new command
    - s/^ -> search for the beginning of the line
    - (.{17}) -> . is any character, {17} repeats 17 times. so it's 17 of any characters
    - .*$ -> all what is left (from 17th character to the end)
    - /\1/; -> and replace what is left with \1

    I hope that explains it to you
    Last edited by slovenia; September 25th, 2010 at 12:49 AM.
    be XOR !be

  7. #7
    Join Date
    Aug 2010
    Beans
    407
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Quote Originally Posted by slovenia View Post
    We still have to integrate it in a startup script!
    I tried and failed but will keep at it until I can figure it out.

    BTW, I found what seems to be a good random hostname upon reboot script here:
    http://cryptoanarchy.org/wiki/Random_hostname_on_boot

    It picks the random hostnames out of /usr/share/dict/words

    I wonder if we can modify it to also change the wlan0 MAC address?

    That web page has only been accessed 400 times since it was written (according to the web counter at the bottom of the page), so, just in case it goes away, I'll reproduce it here.

    Two files are needed:
    /etc/init.d/hostname.sh runs before the filesystem has mounted
    /etc/init.d/hostname-rewrite-files runs just after the filesystem has mounted

    Code:
    #!/bin/sh ### BEGIN INIT INFO # Provides:          hostname # Required-Start: # Required-Stop: # Should-Start:      glibc # Default-Start:     S # Default-Stop: # Short-Description: Sets a random hostname # Description:       Read /usr/share/dict/words, pick a random word #                    and update the kernel value with this value. #                    If /etc/hostname is empty, it is created. #                    The old hostname in /etc/hosts is also replaced #                    If everything fails, the value 'localhost' is used. ### END INIT INFO # INSTALLING: # sudo cp hostname.sh /etc/init.d/hostname.sh # sudo chmod u+x /etc/init.d/hostname.sh # sudo update-rc.d hostname.sh start 02 S . # reboot & pray # WRITTEN BY Pragmatk, May 2010   PATH=/sbin:/bin  . /lib/init/vars.sh . /lib/lsb/init-functions  do_start () { 	# either current name or /etc/hostname (/etc/hostname shouldn't be missing) 	[ -f /etc/hostname ] && OLD_HOSTNAME="$(cat /etc/hostname)"  	# Keep current name if /etc/hostname is missing. 	[ -z "$OLD_HOSTNAME" ] && OLD_HOSTNAME="$(hostname)"  	# below we pick a random word and filter it for special chars (and make sure we still have string) 	# could be approached cleaner (ie rejecting a word with special chars instead of filtering, 	# but that'd give us fewer pretty names to pick from!) 	HOSTNAME=`cat /usr/share/dict/words |/usr/bin/perl -e '@w=<>;$g="";while($_!~/\A[a-z]+\Z/i){@good=$w[int rand $#w]=~/([a-z]+)/ig;$_=join("",@good);}print'`  	#default to localhost (we do not want to use a previously stored value) 	[ -z "$HOSTNAME" ] && HOSTNAME=localhost  	log_action_begin_msg	"$HOSTNAME is now the new hostname :-)" 	[ "$VERBOSE" != no ] && log_action_begin_msg "Setting hostname to '$HOSTNAME'" 	hostname "$HOSTNAME" 	ES=$? 	[ "$VERBOSE" != no ] && log_action_end_msg $ES 	exit $ES }  case "$1" in   start|"") 	do_start 	;;   restart|reload|force-reload) 	echo "Error: argument '$1' not supported" >&2 	exit 3 	;;   stop) 	# No-op 	;;   *) 	echo "Usage: hostname.sh [start|stop]" >&2 	exit 3 	;; esac
    Code:
    #!/bin/sh ### BEGIN INIT INFO # Provides:          hostname-rewrite-files # Required-Start:    mountall # Required-Stop: # Should-Start:      glibc # Default-Start:     S # Default-Stop: # Short-Description: Writes the current hostname to disk # Description:       Writes the current hostname to disk when the #                    filesystem has been remounted (to enable permanent #                    name change). ### END INIT INFO # Written by Pragmatk, May 2010 ## INSTALLING: # sudo cp hostname-rewrite-files /etc/init.d/hostname-rewrite-files # sudo chmod u+x /etc/init.d/hostname-rewrite-files # sudo update-rc.d hostname-rewrite-files start 36 S . # hope it works # ??? # PROFIT!   PATH=/sbin:/bin  . /lib/init/vars.sh . /lib/lsb/init-functions  do_start () { 	HOSTNAME=$(hostname) 	OLD_HOSTNAME=`cat /etc/hostname` 	if [ ! -z "$OLD_HOSTNAME" ] && [ ! -z "$HOSTNAME" ] && [ "$OLD_HOSTNAME" != "$HOSTNAME" ]; then 	for file in /etc/hostname /etc/hosts; do 		log_action_begin_msg "replacing ${OLD_HOSTNAME} with $HOSTNAME in file $file" 		sed s:${OLD_HOSTNAME}:${HOSTNAME}:g $file > ${file}.new && mv ${file}.new $file && log_action_begin_msg "done: replacing ${OLD_HOSTNAME} with ${HOSTNAME}" || log_action_warning_msg "failed when replacing ${OLD_HOSTNAME} with ${HOSTNAME} in $file" 	done 	fi 	exit 0 }  case "$1" in   start|"") 	do_start 	;;   restart|reload|force-reload) 	echo "Error: argument '$1' not supported" >&2 	exit 3 	;;   stop) 	# No-op 	;;   *) 	echo "Usage: hostname.sh [start|stop]" >&2 	exit 3 	;; esac

  8. #8
    Join Date
    Jul 2009
    Location
    127.0.0.1
    Beans
    54
    Distro
    Ubuntu

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Yes, we could easily integrate a wlan0 mac change script into this one but I think this startup script is way too big. It should be small, fast and easy to understand.

    But anyway, if you want to integrate our script put it in the second file where do_start() function is:

    Code:
    do_start () {
            HOSTNAME=$(hostname)
            OLD_HOSTNAME=`cat /etc/hostname`
            if [ ! -z "$OLD_HOSTNAME" ] && [ ! -z "$HOSTNAME" ] && [ "$OLD_HOSTNAME" != "$HOSTNAME" ]; then
            for file in /etc/hostname /etc/hosts; do
                    log_action_begin_msg "replacing ${OLD_HOSTNAME} with $HOSTNAME in file $file"
                    sed s:${OLD_HOSTNAME}:${HOSTNAME}:g $file > ${file}.new && mv ${file}.new $file && log_action_begin_msg "done: replacing ${OLD_HOSTNAME} with ${HOSTNAME}" || log_action_warning_msg "failed when replacing ${OLD_HOSTNAME} with ${HOSTNAME} in $file"
            done
            fi
    #start of mac changing script
            oldmac=`ifconfig -a | grep HWaddr | grep wlan0 | awk '{print $NF}'`
           log_action_begin_msg "Old mac adress: $oldmac"
            newmac=`echo $RANDOM$RANDOM | md5sum | sed -r 's/(..)/\1:/g; s/^(.{17}).*$/\1/;'`
            sudo ifconfig wlan0 down hw ether $newmac
            sudo ifconfig wlan0 up
            log_action_begin_msg "New mac adress: $newmac"
    #end of mac changing script
            exit 0
    }
    Last edited by slovenia; September 25th, 2010 at 01:25 AM. Reason: echo should be replaced with log_action_begin_msg
    be XOR !be

  9. #9
    Join Date
    Aug 2010
    Beans
    407
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    Quote Originally Posted by slovenia View Post
    - (.{17}) -> . is any character, {17} repeats 17 times. so it's 17 of any characters
    Oh, duh! < slaps head >. It's my fault. I should have realized "17" was not a "command" per se, but, the number of characters. Sorry about that. It's so clear now.

    Now the trick will be to insert this wonderful random wlan0 MAC address changer into some startup script.

    I did try the two hostname changer scripts, but, they didn't change the hostname. I need to figure out what makes a script execute in /etc/init.d first, I guess.

    Thanks ... I'll keep digging until we have at least one way of having a new MAC and new hostname on every reboot.

  10. #10
    Join Date
    Jul 2009
    Location
    127.0.0.1
    Beans
    54
    Distro
    Ubuntu

    Re: DIY tutorial for the best way to randomize wlan0 MAC & hostname on every bootup?

    http://cryptoanarchy.org/wiki/Random_hostname_on_boot:
    I've had to modify one script (/etc/init.d/hostname.sh) and write my own (/etc/init.d/hostname-rewrite-files). These are experimental scripts - do not use them if you do not understand them and feel confident they won't screw stuff up
    Did you also modify the original /etc/init.d/hostname.sh and put hostname-rewrite-files in /etc/init.d/? Try to check your boot log messages to check if there were errors or if it didn't run at all.
    Last edited by slovenia; September 25th, 2010 at 01:41 AM.
    be XOR !be

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •