Mac Spoofing with systemd// This tutorial created by lucid
::In this tutorial- Creating custom systemd scripts(Arch Linux)
- Mac spoofing at startup
::What you will need- Arch Linux switched to systemd. If you do not know what this means visit the Arch Wiki.
- The ability to read.
- A text editor. (nano, vi, emacs, gedit)
- A penis or vagina. (but not both)
- Macchanger
::Let's Get Started!For those of you that do not know what systemd is and are interested in switching over to it should visit the Arch Wiki here
https://wiki.archlinux.org/index.php/Systemd and read through it carefully.
Now. What I'm going to be showing you today is how to write a custom startup script or .service file in systemd. It actually took me a long time to figure out how to write a script and have it run at startup in systemd. It is true that if you are running some WM like openbox/fluxbox you can put your script in an autostart file and that shoud normally do the trick. I should be specific. In particular I'm going to teach you to write a .service file that will spoof your Mac address at startup.
Here's the basic format of a .service file in Arch Linux:
[Unit]
Description=
Before=
[Service]
ExecStart=
[Install]
WantedBy=
These are usually located in /etc/systemd/system. Take a look at a few of them if you like. As I said before I just showed you the
basic format of one of these files. If you're already sick of reading I assure you this tutorial will be short and to the point. These are very simple.
Description=This is pretty straightforward. All this is, is what you will see in the startup messages you will see when you boot up your system if you have systemd. So for example.
[Unit]
Description=Mac Spoof
Before=
[Service]
ExecStart=
[Install]
WantedBy=
Notice what it says in Description. When you start up systemd you will see a bunch of messages on the screen looking like this:
[
OK ]Started Network Manager
[
OK ]Started Mac Spoof << This is what ours will look like
Pretty simple.
Before=This is basically where you put a service you want your custom service to start before. You could also change it to After=. For our example we will use this:
[Unit]
Description=Mac Spoof
Before=dhcpcd.service
[Service]
ExecStart=
[Install]
WantedBy=
The reason we put this in the Before= area is so that your Mac will be spoofed before dhcpcd. That way, you don't have to reconfigure the network after you start up. Lets move on.
ExecStart=This is where you will put whatever script it is that you want to run. In our case we will be using our macchanger script.
[Unit]
Description=Mac Spoof
Before=dhcpcd.service
[Service]
ExecStart=/bin/bash /home/lucid/code/sh/macchanger.sh
[Install]
WantedBy=
The /bin/bash before the path to the script is to make sure it knows that you want to run a bash script. Otherwise this won't work. Also, you have to make sure that you use the full path. In case you aren't sure about this part I will show you my script that I called here:
#! /bin/sh
sudo macchanger -r wlan0
If you can't understand what I did here you should read up on macchanger. All this does is set you interface(wireless in my case)mac address to a random one(-r).
WantedBy=This creates a symlink in the .wants/ directory. Doing this enables whatever service you put here along with your custom service.
[Unit]
Description=Mac Spoof
Before=dhcpcd.service
[Service]
ExecStart=/bin/bash /home/lucid/code/sh/macchanger.sh
[Install]
WantedBy=network.target
This way, the network service is started along with our macchanger service. That's about all you need to do to write a very simple .service file. For a more detailed and harder to read documentation you can refer to man systemd.unit. Also, don't forget to put this in /etc/systemd/system and name it something like
macspoof@wlan0.service. or
macchanger@wlan0.service. Make sure that after you create this file you run systemctl start
macspoof@wlan0.service to enable your new service. Oh, and one more thing. Before you do this you can run this command:
ifconfig wlan0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
To see what your mac address is. After you have done this, run it again to verify the change of mac so that you know it worked. I hope this helped someone who is either looking to create their own system service files and/or spoof your mac address on startup in Arch linux. Thanks for reading.
-lucid