diff --git a/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/README.md b/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/README.md index b24d761..2d55acb 100644 --- a/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/README.md +++ b/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/README.md @@ -12,9 +12,7 @@ Listed: true [![How to spoof MAC address and hostname automatically at boot on macOS](how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos.png)](https://www.youtube.com/watch?v=ASXANpr_zX8 "How to spoof MAC address and hostname automatically at boot on macOS") -> Heads-up: unfortunately this guide doesn’t work on Macs equipped with T2 chips running macOS Mojave. If that’s your case, consider upgrading to Catalina. - -> Heads-up: unfortunately this guide doesn’t work on Macs equipped with M1 processors (see [issue](https://github.com/sunknudsen/privacy-guides/issues/15)). +> Heads-up: unfortunately, it is not possible to spoof MAC address on some Macs (see [issue](https://github.com/sunknudsen/privacy-guides/issues/15)). ## Caveats @@ -48,7 +46,23 @@ echo 'export PATH=$PATH:/usr/local/sbin' >> ~/.zshrc source ~/.zshrc ``` -### Step 3: create `spoof.sh` script +### Step 3: download [first-names.txt](./first-names.txt) + +This list includes the top 2048 most popular baby names from the [USA Social Security Administration](https://www.ssa.gov/oact/babynames/limits.html). + +```shell +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 +``` + +### Step 4: download [mac-address-prefixes.txt](./mac-address-prefixes.txt) + +This list includes 768 Apple MAC address prefixes. + +```shell +curl -o /usr/local/sbin/mac-address-prefixes.txt https://sunknudsen.com/static/media/privacy-guides/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/mac-address-prefixes.txt +``` + +### Step 5: create `spoof.sh` script ```shell cat << "EOF" > /usr/local/sbin/spoof.sh @@ -71,41 +85,27 @@ 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 +# Turn on Wi-Fi interface +networksetup -setairportpower en0 on + +# Spoof MAC address of Wi-Fi interface mac_address_prefix=$(sed "$(jot -r 1 1 768)q;d" $basedir/mac-address-prefixes.txt | sed -e 's/[^A-F0-9:]//g') mac_address_suffix=$(openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//') mac_address=$(echo "$mac_address_prefix:$mac_address_suffix" | awk '{print toupper($0)}') +sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --disassociate sudo ifconfig en0 ether "$mac_address" printf "%s\n" "Spoofed MAC address of en0 interface to $mac_address" EOF ``` -### Step 4: make `spoof.sh` executable +### Step 6: make `spoof.sh` executable ```shell chmod +x /usr/local/sbin/spoof.sh ``` -### Step 5: download [first-names.txt](./first-names.txt) - -This list includes the top 2048 most popular baby names from the [USA Social Security Administration](https://www.ssa.gov/oact/babynames/limits.html). - -```shell -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 -``` - -### Step 6: download [mac-address-prefixes.txt](./mac-address-prefixes.txt) - -This list includes 768 Apple MAC address prefixes. - -```shell -curl -o /usr/local/sbin/mac-address-prefixes.txt https://sunknudsen.com/static/media/privacy-guides/how-to-spoof-mac-address-and-hostname-automatically-at-boot-on-macos/mac-address-prefixes.txt -``` - ### Step 7: create `local.spoof.plist` launch daemon -This step is responsible for running `spoof.sh` every time your Mac boots. - ```shell cat << "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist @@ -127,7 +127,44 @@ cat << "EOF" | sudo tee /Library/LaunchDaemons/local.spoof.plist EOF ``` -### Step 8: reboot and confirm hostname and MAC address have been spoofed +### Step 8: create `spoof-hook.sh` script + +```shell +cat << "EOF" > /usr/local/sbin/spoof-hook.sh +#! /bin/sh + +# Turn off Wi-Fi interface +networksetup -setairportpower en0 off +EOF +``` + +### Step 9: make `spoof-hook.sh` executable + +```shell +chmod +x /usr/local/sbin/spoof-hook.sh +``` + +### Step 10: make sure `com.apple.loginwindow` does not exist + +> Heads-up: if `com.apple.loginwindow` exists, one needs to backup user default carefully and consider using an abstraction that runs both current `LogoutHook` script and `/usr/local/sbin/spoof-hook.sh`. + +```console +$ sudo defaults read com.apple.loginwindow +2021-09-27 06:58:02.301 defaults[2267:25227] +Domain com.apple.loginwindow does not exist +``` + +Domain com.apple.loginwindow does not exist + +👍 + +### Step 11: configure user default (used to disable Wi-Fi interface at logout) + +```shell +sudo defaults write com.apple.loginwindow LogoutHook "/usr/local/sbin/spoof-hook.sh" +``` + +### Step 12: reboot and confirm hostname and MAC address have been spoofed #### Spoofed hostname @@ -150,7 +187,7 @@ $ networksetup -listallhardwareports | awk -v RS= '/en0/{print $NF}' 9c:f4:8e:d6:2b:7d ``` -“Spoofed hostname” is random and “Spoofed MAC address” doesn’t match “Hardware MAC address”? +“Spoofed hostname” is random and “Spoofed MAC address” does not match “Hardware MAC address”? 👍 @@ -158,9 +195,25 @@ $ networksetup -listallhardwareports | awk -v RS= '/en0/{print $NF}' ## Want things back the way they were before following this guide? No problem! -### Step 1: set computer name, local hostname and hostname +### Step 1: delete files -Replace `John` with a name to your liking. +```shell +rm /usr/local/sbin/first-names.txt +rm /usr/local/sbin/mac-address-prefixes.txt +rm /usr/local/sbin/spoof-hook.sh +rm /usr/local/sbin/spoof.sh +sudo rm /Library/LaunchDaemons/local.spoof.plist +``` + +### Step 2: delete user default + +```shell +sudo defaults delete com.apple.loginwindow LogoutHook +``` + +### Step 3: set computer name, local hostname and hostname + +> Heads-up: replace `John` with your name. ```shell sudo scutil --set ComputerName "John’s MacBook Pro" @@ -168,20 +221,6 @@ sudo scutil --set LocalHostName "Johns-MacBook-Pro" sudo scutil --set HostName "Johns-MacBook-Pro" ``` -### Step 2: set MAC address to default value - -Given MAC address spoofing is ephemeral, deleting the `/Library/LaunchDaemons/local.spoof.plist` launch daemon and rebooting will reset your MAC address to its default value. - -```shell -sudo rm /Library/LaunchDaemons/local.spoof.plist -``` - -### Step 3: delete script and datasets - -```shell -rm /usr/local/sbin/spoof.sh -rm /usr/local/sbin/first-names.txt -rm /usr/local/sbin/mac-address-prefixes.txt -``` +### Step 4: reboot 👍