2

I've been making a BASh script that changes your MAC Address to that of any manufacturer of your choice from a list. At the last part of the script that is run, it stops before finishing. Here is the code for that part:

function spoofUseMAC() {

  echo
  read -p "[*] $($stopAllFX; $bgBlack; $white)Enter the number code for manufacturer: >>> " num
  echo "[-] Generating MAC Address"
  num=$( expr $num - 1 )
  declare -a array
  while read -r; do
    array+=( "$REPLY" )
  done < addr.txt
  end=$( for i in {1..6} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
  macAddress=${array[$num]}$end
  echo "[-] MAC Address generated !"
  echo "[-] Using address: $macAddress"

  $skyBlue; $bold; echo
  ifconfig
  $white
  read -p "[*] $($stopAllFX; $bgBlack; $white)Select an interface: >>> " iface
  $yellow; echo "[-] $iface selected !"
  $white; echo  "[-] Disabling $iface ..."
  ifconfig $iface down
  ifconfig '$iface' hw ether '$macAddress'
  echo "[-] MAC Address spoofed !"
  sleep 1
  echo "[-] Enabling $iface ..."
  ifconfig '$iface' up
  echo "[-] $iface enabled !"
  echo "[-] Using address: $macAddress"
  exit

}

function spoofSearchAgainOrNot() {

  $bold; $white; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search again"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Use one of these"
  read -p ">>> " searchAgainOrNot
  if [[ "$searchAgainOrNot" == "0" ]]; then
    spoofSearch
  elif [[ "$searchAgainOrNot" == "1" ]]; then
    spoofUseMAC
  else
    spoofSearchAgainOrNot
  fi

}

# Spoof, search option selected
function spoofSearch() {

  $bold; echo
  read -p "[*] $($stopAllFX; $bgBlack; $white)Search for a manufacturer: >>> " search
  $blue; awk -F '#' '{printf("%10d %s\n", NR, ":" $1 )}' /usr/bin/oui.txt | grep -i $search

  spoofSearchAgainOrNot

}

# Spoof
function spoof() {

  echo; $white
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search for a manufacturer"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Browse for a manufacturer through $($bold)long $($stopAllFX; $bgBlack; $white)list"
  read -p ">>> " searchOrBrowse
  if [[ $searchOrBrowse == "0" ]]; then
    spoofSearch
  elif [[ $searchOrBrowse == "1" ]]; then
    spoofBrowse
  else
    spoof
  fi

}

Why can't I use the internet (git clone says could not resolve hostname: github.com) after running this script? And why is it not finishing?

EDIT: This is supposed to work on MacOS and Linux. On MacOS, there is no ip route command, but in Linux, ip route results in:

192.168.0.0/24 dev wlp1s0  proto kernel scope link  src 192.168.0.18 
192.168.0.0/24 dev wlp1s0  proto kernel scope link  src 192.168.0.18  metric 600
10
  • please add to the question, in text mode, the output of the command 'ip route' Commented May 20, 2017 at 3:04
  • @RuiFRibeiro Done.
    – anonymous
    Commented May 20, 2017 at 3:15
  • On Mac OS, you can do netstat -nr. Commented May 20, 2017 at 3:18
  • 1
    Are you at home, wifi or in a corporate network? Commented May 20, 2017 at 3:20
  • 2
    If a WiFi router is doing access control based on the MAC address, then I'm not surprised if you can't connect to the Internet.
    – Kusalananda
    Commented May 20, 2017 at 7:54

2 Answers 2

3

Some cards are a bit finicky about changing/spoofing the MAC address.

In OSX the interface MAC address change, in particular the wifi interface, has to be done several times until getting it right e.g. often in a loop, because it must be done in a certain time, I suspect; it often is not assumed at first time with the latest versions of OSX/MacOS.

Notably in OSX the interface/drivers seem to get confused for a couple of seconds after the MAC, however they do recover.

Rare brands won't like it, in some brands you are not advised to change the first 3 octets (the first 6 digits, minus ":"), that are the manufacturer id.

Often you lose your default route, or the router/AP may lose the notion of who you are; while the process should be mostly automatic, in some cases, in Linux you may have to restart the DHCP service after changing the MAC address.

1
  • 1
    The last part of the code that is visibly run is "[-] Enabling $iface ...", and then it exits...
    – anonymous
    Commented May 20, 2017 at 11:20
0

I found the problem: one of the $ifaces had quotes around it when it shouldn't have.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .