8
\$\begingroup\$

I've made a BASh script for Linux/MacOS that allows you to search for a MAC manufacturer and then generates a MAC address from that company and then spoofs it to that using macchanger.

You can download it from GitHub, or the code is put below this paragraph. To run it, chmod +x mac-camo and sudo ./mac-camo.

#!/bin/bash
# MAC-Camo
# Disguise your MAC Address as that of any manufacturer as you want
# Made by Keegan Kuhn
# v0.1

# Defines foreground colors
black='tput setaf 0'
red='tput setaf 1'
green='tput setaf 2'
yellow='tput setaf 3'
blue='tput setaf 4'
pink='tput setaf 5'
skyBlue='tput setaf 6'
white='tput setaf 7'
grey='tput setaf 8'

# Defines background colors
bgBlack='tput setab 0'
bgRed='tput setab 1'
bgGreen='tput setab 2'
bgYellow='tput setab 3'
bgBlue='tput setab 4'
bgPink='tput setab 5'
bgSkyBlue='tput setab 6'
bgWhite='tput setab 7'
bgGrey='tput setab 8'

# Defines other special effects
cols='tput cols'
lines='tput lines'
bold='tput bold'
reverseColor='tput rev'
underlineStart='tput smul'
underlineFinish='tput rmul'
standoutStart='tput smso'
standoutFinish='tput rmso'
stopAllFX='tput sgr0'

# Defines hexadecimal colors
hexchars="0123456789ABCDEF"

function start() {

# Renders ANSI art
$stopAllFX; $bgBlack; $bold; $red; clear
sleep .2; echo "             ▉╗   ╔▉ ╔▉▉▉╗ ╔▉▉▉▉▉        ╔▉▉▉▉▉ ╔▉▉▉╗ ▉╗   ╔▉ ╔▉▉▉╗"
sleep .2; echo "             ▉▉╗ ╔▉▉ ▉   ▉ ▉             ▉      ▉   ▉ ▉▉╗ ╔▉▉ ▉   ▉"
sleep .2; echo "             ▉ ▉▉▉ ▉ ▉▉▉▉▉ ▉      $($white)☷☷☷☷☷$($red)  ▉      ▉▉▉▉▉ ▉ ▉▉▉ ▉ ▉   ▉"
sleep .2; echo "             ▉  ▉  ▉ ▉   ▉ ▉             ▉      ▉   ▉ ▉  ▉  ▉ ▉   ▉"
sleep .2; echo "             ▉  ▉  ▉ ▉   ▉ ╚▉▉▉▉▉        ╚▉▉▉▉▉ ▉   ▉ ▉  ▉  ▉ ╚▉▉▉╝"
sleep .2; echo
sleep .2; $green; echo "  Disguise your MAC Address as that of any manufacturer as you want ($($red)MAC-Camo$($green))"
sleep .2; $skyBlue; echo "                         Made by $($green)Keegan Kuhn ($($red)keeganjk$($green))"
sleep .2; $skyBlue; echo "                                 Version: $($green)1.0"
sleep .2; echo
sleep .2; $green; echo "    Please report all issues to: $($yellow)https://github.com/keeganjk/mac-camo/issues"
$stopAllFX; $bgBlack; echo

# Checks if user is root
override="1"
if [[ $(whoami) == "root" ]]; then
  sleep .2; $green; echo "                                Root successful."
elif [[ $override == "1" ]]; then
  sleep .2; $green; echo "                                Root successful."
else
  sleep .2; $white; echo "                     Sorry, this script must be run as $($bold)root"
  sleep .4; $stopAllFX; $bgBlack; $yellow; echo "                                 Try using $($bold)sudo"
  sleep .4; $red; $bold; echo "                                  [!] $($stopAllFX; $bgBlack; $red)EXITING!"
  $stopAllFX; exit
fi

function spoofBrowse() {

  echo
  $blue; awk -F '#' '{printf("%10d %s\n", NR, ":" $1 )}' oui.txt
  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 !"

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

}

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 -l
  $white
  read -p "[*] $($stopAllFX; $bgBlack; $white)Select an interface: >>> " iface
  $yellow; echo "[-] $iface selected !"
  $white; echo  "[-] Disabling $iface ..."
  ifconfig $iface down
  macchanger -m $macAddress $iface
  echo "[-] MAC Address spoofed !"
  echo "[-] Enabling $iface ..."
  ifconfig $iface up
  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 )}' oui.txt | grep -i --colour="always" $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

}

# Install complete
function installComplete() {

  $white; $bold; echo
  echo "[-] Install complete !"
  echo "[*] $($stopAllFX; $bgBlack; $white)Restart or exit?"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Restart"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Exit"
  read -p ">>> " restartOrExit
  if [[ "$restartOrExit" == "0" ]]; then
    start
  elif [[ "$restartOrExit" == "1" ]]; then
    $yellow; $bold; echo "[!] $($stopAllFX; $bgBlack; $yellow)EXITING !"
    $stopAllFX; exit
  else
    installComplete
  fi

}

# Install cancelled
function installCancelled() {

  echo; $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)INSTALL CANCELLED !"
  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Restart or exit?"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Restart"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Exit"
  read -p ">>> " restartOrExit
  if [[ "$restartOrExit" == "0" ]]; then
    start
  elif [[ "$restartOrExit" == "1" ]]; then
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)ABORT !"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)EXITING !"
    $stopAllFX; exit
  else
    installCancelled
  fi

}

# Linux install, Pt. 3
function linuxInstallPt3() {

  $white; $bold; echo

  echo "[-] Installing macchanger ..."
  if [[ "$pacman" == "pacman" ]]; then
    $pacman -S install macchanger
  elif [[ "$paman" == "IDK" ]]; then
    apt-get install macchanger
    apt install macchanger
    rpm install macchanger
    yum install macchanger
    dnf install macchanger
    pacman -S install macchanger
  else
    $pacman install macchanger
  fi
  if macchanger --help > /dev/null; then
    echo "[-] macchanger installed !"
  else
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)ERROR!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)MACCHANGER NOT INSTALLED!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)EXITING!"
    $stopAllFX; exit
  fi

  echo "[-] Copying files ..."
  cp mac-camo /usr/bin/
  echo "[-] Files copied !"

  echo "[-] Changing file permissions ..."
  chmod +x /usr/bin/mac-camo
  echo "[-] File permissions changed !"

  installComplete

}

# Linux install, Pt. 2
function linuxInstallPt2() {

  $green; $bold; $standoutStart; echo
  echo " OS: $os                "
  echo " macchanger installed: $macchangerInstalled "
  echo " Package Manager: $pacman "
  $standoutFinish; $white; $bold; echo
  echo "[*] ^--- $($stopAllFX; $bgBlack; $white)Install with these settings?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Yes"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)No"
  read -p ">>> " installWithTheseSettings
  if [[ "$installWithTheseSettings" == "0" ]]; then
    linuxInstallPt3
  elif [[ "$installWithTheseSettings" == "1" ]]; then
    installCancelled
  else
    macInstallPt2
  fi

}

# Linux install, Pt. 1
function linuxInstallPt1() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Which package manager do you use on this device?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)apt-get"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)apt"
  $yellow; $bold; echo "        [$($white)2$($yellow)] $($stopAllFX; $bgBlack; $white)rpm"
  $yellow; $bold; echo "        [$($white)3$($yellow)] $($stopAllFX; $bgBlack; $white)yum"
  $yellow; $bold; echo "        [$($white)4$($yellow)] $($stopAllFX; $bgBlack; $white)dnf"
  $yellow; $bold; echo "        [$($white)5$($yellow)] $($stopAllFX; $bgBlack; $white)pacman"
  $yellow; $bold; echo "        [$($white)6$($yellow)] $($stopAllFX; $bgBlack; $white)IDK"
  read -p ">>> " pacman
  if [[ "$pacman" == "0" ]]; then
    pacman="apt-get"
    linuxInstallPt2
  elif [[ "$pacman" == "1" ]]; then
    pacman="apt"
    linuxInstallPt2
  elif [[ "$pacman" == "2" ]]; then
    pacman="rpm"
    linuxInstallPt2
  elif [[ "$pacman" == "3" ]]; then
    pacman="yum"
    linuxInstallPt2
  elif [[ "$pacman" == "4" ]]; then
    pacman="yum"
    linuxInstallPt2
  elif [[ "$pacman" == "5" ]]; then
    pacman="pacman"
    linuxInstallPt2
  elif [[ "$pacman" == "6" ]]; then
    pacman="IDK"
    linuxInstallPt2
  else
    macInstallPt1
  fi

}

# Linux install, Pt. 0
function linuxInstallPt0() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Is $($bold)macchanger$($stopAllFX; $bgBlack; $white) installed on this device?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Yes"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)No"
  $yellow; $bold; echo "        [$($white)2$($yellow)] $($stopAllFX; $bgBlack; $white)IDK"
  read -p ">>> " macchangerInstalled
  if [[ "$macchangerInstalled" == "0" ]]; then
    macchangerInstalled="Yes"
    linuxInstallPt1
  elif [[ "$macchangerInstalled" == "1" ]]; then
    macchangerInstalled="No"
    linuxInstallPt1
  elif [[ "$macchangerInstalled" == "2" ]]; then
    macchangerInstalled="IDK"
    linuxInstallPt1
  else
    macInstallPt0
  fi

}

# MacOS install, Pt. 3
function macInstallPt3() {

  $white; $bold; echo

  echo "[-] Installing Homebrew ..."
  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  if brew ls --versions myformula > /dev/null; then
    echo "[-] Homebrew installed !"
    echo "[-] Updating Homebrew ..."
    brew update
    echo "[-] Homebrew updated !"
  else
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)ERROR!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)HOMEBREW NOT INSTALLED!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)EXITING!"
    $stopAllFX; exit
  fi

  echo "[-] Installing macchanger ..."
  brew install acrogenesis/macchanger/macchanger
  if macchanger --help > /dev/null; then
    echo "[-] macchanger installed !"
  else
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)ERROR!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)MACCHANGER NOT INSTALLED!"
    $red; $bold; echo "[!] $($stopAllFX; $bgBlack; $red)EXITING!"
    $stopAllFX; exit
  fi

  echo "[-] Copying files ..."
  cp mac-camo /usr/bin/
  echo "[-] Files copied !"

  echo "[-] Changing file permissions ..."
  chmod +x /usr/bin/mac-camo
  echo "[-] File permissions changed !"

  installComplete

}

# MacOS install, Pt. 2
function macInstallPt2() {

  $green; $bold; $standoutStart; echo
  echo " OS: $os                "
  echo " Homebrew installed: $brewInstalled   "
  echo " macchanger installed: $macchangerInstalled "
  $standoutFinish; $white; $bold; echo
  echo "[*] ^--- $($stopAllFX; $bgBlack; $white)Install with these settings?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Yes"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)No"
  read -p ">>> " installWithTheseSettings
  if [[ "$installWithTheseSettings" == "0" ]]; then
    macInstallPt3
  elif [[ "$installWithTheseSettings" == "1" ]]; then
    installCancelled
  else
    macInstallPt2
  fi

}

# MacOS Install, Pt. 1
function macInstallPt1() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Is $($bold)macchanger$($stopAllFX; $bgBlack; $white) installed on this device?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Yes"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)No"
  $yellow; $bold; echo "        [$($white)2$($yellow)] $($stopAllFX; $bgBlack; $white)IDK"
  read -p ">>> " macchangerInstalled
  if [[ "$macchangerInstalled" == "0" ]]; then
    macchangerInstalled="Yes"
    macInstallPt2
  elif [[ "$macchangerInstalled" == "1" ]]; then
    macchangerInstalled="No"
    macInstallPt2
  elif [[ "$macchangerInstalled" == "2" ]]; then
    macchangerInstalled="IDK"
    macInstallPt2
  else
    macInstallPt1
  fi

}

# MacOS install, Pt. 0
function macInstallPt0() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Is $($bold)Homebrew$($stopAllFX; $bgBlack; $white) installed on this device?:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Yes"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)No"
  $yellow; $bold; echo "        [$($white)2$($yellow)] $($stopAllFX; $bgBlack; $white)IDK"
  read -p ">>> " brewInstalled
  if [[ "$brewInstalled" == "0" ]]; then
    brewInstalled="Yes"
    macInstallPt1
  elif [[ "$brewInstalled" == "1" ]]; then
    brewInstalled="No"
    macInstallPt1
  elif [[ "$brewInstalled" == "2" ]]; then
    brewInstalled="IDK"
    macInstallPt1
  else
    macInstallPt0
  fi

}

# Installation and Configuration
function installAndConfig() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select your OS from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)MacOS"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Linux"
  read -p ">>> " os
  if [[ "$os" == "0" ]]; then
    os="MacOS"
    macInstallPt0
  elif [[ "$os" == "1" ]]; then
    os="Linux"
    linuxInstallPt0
  else
    installAndConfig
  fi

}

# Menu 0
function menu0() {

  $white; $bold; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Install and configure"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Spoof"
  read -p ">>> " spoofOrInstall
  if [[ "$spoofOrInstall" == "0" ]]; then
    installAndConfig
  elif [[ "$spoofOrInstall" == "1" ]]; then
    spoof
  else
    menu0
  fi

}; menu0

}; start

How can I make this work better?

\$\endgroup\$
  • 1
    \$\begingroup\$ Yay, a Bash coder that knows to use tput! +1. \$\endgroup\$ – Toby Speight May 18 '17 at 20:20
2
\$\begingroup\$

One small thing - you can reduce the number of invocations of tput by storing the output of the tput commands rather than the command lines themselves, and then interpolating those output values when needed.

Example:

bgBlack=$(tput setab 0)
white=$(tput setaf 7)
stopAllFX=$(tput sgr0)
  read -p "[*] $stopAllFX$bgBlack${white}Select an interface: >>> " iface
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.