Pwnagotchi, waveshare 2.13v3, pisugar 3
Tags: security, pwnagotchi
Published: 2022-10-30 12:21:19

I recently built a couple of [pwnagotchi](https://pwnagotchi.ai/) devices. These devices grab wifi handshakes for later cracking, so should only be used on wifi networks you have permission to attack.

The latest version of pwnagotchi is v1.5.5, but this lead to some problems. This supports the Waveshare 2.13" v2 eInk display, but I could only find the v3 for sale. I also wanted to use the PiSugar 3 battery/UPS which is not natively supported. Finally, the 1.5.5 version can not switch from `AUTO` to `AI` mode. Here's how I solved all these issues.

The Waveshare 2.13" v3 eInk display support was the easiest fix. Instead of using the official pwnagotchi image, I used the alternate image referenced in [this comment](https://github.com/evilsocket/pwnagotchi/pull/1069#issuecomment-1161385537), [the pwnagotchi_1.5.5_WSV3Patched image](https://archive.org/details/pwnagotchi_1.5.5_WSV3Patched).

Supporting the PiSugar 3 battery pack is a bit more work. Sign in to the pwnagotchi via ssh, then follow the instructions at [taiyonemo/pwnagotchi-plugin-pisugar3](https://github.com/taiyonemo/pwnagotchi-plugin-pisugar3). In my case, I did this:
```
# Become root
sudo -i
# Copy the pisugar 3 file into the right location
cd /usr/local/lib/python3.7/dist-packages/pwnagotchi/plugins/default
wget https://raw.githubusercontent.com/taiyonemo/pwnagotchi-plugin-pisugar3/main/pisugar3.py
```

Now, I wanted to run the PiSugar power management software so I followed [the official instructions](https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series).
```
curl http://cdn.pisugar.com/release/pisugar-power-manager.sh | sudo bash
```

You should then be able to load the settings page in your browser by going to http://10.0.0.2:8421. I turned on `Safe Shutdown` with a `Battery Level <= 20%`, then went in to `Settings` and enabled `Battery Input Protection`, ensured `Soft Shutdown` was enabled, and set `Soft Shutdown Shell` to `Shutdown`. Now's a good time to update the firmware, too.
```
curl https://cdn.pisugar.com/release/PiSugarUpdate.sh | sudo bash
```

I modified `/boot/config.txt` by adding the following:
```
# If running Pi 4, downclock for more battery.
# No point on the Pi 0.
arm_freq=800

# Enable real-time clock
dtoverlay=i2c-rtc,ds3231
```

Now, let's take a look at my `/etc/pwnagotchi/config.toml` file:
```
# General config
main.name = "pwnagotchi4"
main.lang = "en"

main.plugins.grid.enabled = true
main.plugins.grid.report = false

# PiSugar 3 UPS
main.plugins.pisugar3.enabled = true
main.plugins.pisugar3.shutdown = 15

# eInk display
ui.display.enabled = true
ui.display.type = "waveshare_3"
ui.display.color = "black"

# Reduce writes to SD card
fs.memory.mounts.log.enabled = true     # switch
fs.memory.mounts.log.mount = "/var/log" # which directory to map into memory
fs.memory.mounts.log.size = "50M"       # max size to put into memory
fs.memory.mounts.log.sync = 600         # interval in seconds to sync back onto disk
fs.memory.mounts.log.zram = true        # use zram for compression (recommended)
fs.memory.mounts.log.rsync = true       # use rsync to copy only the difference (recommended)

# ignore networks
main.whitelist = [
  "your network here",
]
```

This leaves one remaining problem. The pwnagotchi won't switch into `AI` mode. Running [`linux_connection_share.sh`](https://github.com/evilsocket/pwnagotchi/blob/master/scripts/linux_connection_share.sh) on my laptop to ensure the pwnagotchi has Internet access, I ssh in to the pwnagotchi and update `numpy`:
```
sudo pip3 install --upgrade numpy
```

On the Raspberry Pi 0, this takes several hours. It's a bit faster on the Pi 4 but still takes a while. Once the update is complete, reboot and give it about twenty minute and you should see the pwnagotchi switch into AI mode.

Phew, we are done!