Skip to content

Instantly share code, notes, and snippets.

@oliveira-andre
Last active June 27, 2022 01:19
Show Gist options
  • Select an option

  • Save oliveira-andre/4959a5c9968e1e7634f7733e8169aae3 to your computer and use it in GitHub Desktop.

Select an option

Save oliveira-andre/4959a5c9968e1e7634f7733e8169aae3 to your computer and use it in GitHub Desktop.
Spoof Mac Address

Spoof Mac Address on Mac

check if /usr/local/sbin folder exists

ls /usr/local/sbin

create the /usr/local/sbin (if exists this is not required)

sudo mkdir -p /usr/local/sbin
sudo chown $(whoami):admin /usr/local/sbin

check if /usr/local/sbin is on $PATH

echo $PATH | grep /usr/local/sbin

put the /usr/local/sbin on $PATH (if is already on it is not required)

cat << "EOF" >> ~/.zshrc
export PATH=${PATH}:/usr/local/sbin
EOF
source ~/.zshrc

create the spoof.sh and put spoof code on it

cat << "EOF" > /usr/local/sbin/spoof.sh
#! /bin/sh

set -e

export LC_CTYPE=C

basedir=$(dirname "$0")

# Spoof computer name
first_name=`sed "$(jot -r 1 1 2048)q;d" $basedir/first-names.txt | sed -e 's/[^a-zA-Z]//g'`
model_name=`system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//'`
computer_name="$first_name’s $model_name"
host_name=`echo $computer_name | sed -e 's/’//g' | sed -e 's/ /-/g'`
sudo scutil --set ComputerName "$computer_name"
sudo scutil --set LocalHostName "$host_name"
sudo scutil --set HostName "$host_name"
printf "%s\n" "Spoofed hostname to $host_name"

# Spoof MAC address of en0 interface
sudo macchanger -r en0

EOF

make spoof.sh executable

chmod +x /usr/local/sbin/spoof.sh

download some spoof first names to folder that you want (default is on /usr/local/sbin)

curl -o /usr/local/sbin/first-names.txt https://sunknudsen.com/static/media/privacy-guides/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/first-names.txt

executing the spoof code on launch deamon

cat << "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>spoof</string>

    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/sbin/spoof.sh</string>
    </array>

    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>
EOF

Spoofed hostname

$ scutil --get HostName
Gatlins-MacBook-Pro

Spoofed MAC address

$ ifconfig en0 | grep ether | awk '{print $2}'
20:ee:28:31:03:f6

Hardware MAC address

$ networksetup -listallhardwareports | awk -v RS= '/en0/{print $NF}'
9c:f4:8e:d6:2b:7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment