Practical Pi Zero Projects for Hackers
Why Pi Zero?
The Raspberry Pi Zero is:
- Tiny: 65 × 30 mm form factor
- Affordable: $15-20 for Pi Zero 2W
- Low Power: Perfect for battery-powered projects
- Capable: Enough processing for most tasks
- Easy: Standard Raspberry Pi OS support
1. Portable Hacking Toolkit
Create a compact penetration testing device:
Setup
# Install on Pi Zero
sudo apt update
sudo apt install aircrack-ng hashcat hostapd dnsmasq nmap
# Create configuration
cat > /home/pi/hack-config.sh << 'EOF'
#!/bin/bash
# Enable WiFi AP mode
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
# Configure interfaces
sudo nano /etc/hostapd/hostapd.conf
EOF
Hostapd Configuration
interface=wlan0
driver=nl80211
ssid=NetworkSniff
hw_mode=g
channel=6
wmm_enabled=0
auth_algs=1
wpa=2
wpa_passphrase=hacker123
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
Running an AP
#!/bin/bash
# Start access point
sudo hostapd /etc/hostapd/hostapd.conf &
sudo dnsmasq -C /etc/dnsmasq.conf &
# Monitor traffic
sudo tcpdump -i wlan0 -w capture.pcap
sudo wireshark capture.pcap
2. USB Gadget - Rubber Ducky
Turn Pi Zero into a USB keyboard that types commands:
Enable USB Gadget Mode
# On Raspberry Pi OS with Bookworm
echo "dtoverlay=dwc2" | sudo tee -a /boot/firmware/config.txt
echo "modules-load=dwc2,g_hid" | sudo tee -a /boot/firmware/cmdline.txt
sudo reboot
Create HID Payload
#!/usr/bin/env python3
import time
import usb1
# HID keyboard codes
KEYS = {
'a': 0x04, 'b': 0x05, 'c': 0x06, 'd': 0x07, 'e': 0x08,
'f': 0x09, 'g': 0x0a, 'h': 0x0b, 'i': 0x0c, 'j': 0x0d,
'0': 0x27, '1': 0x1e, '2': 0x1f, '3': 0x20,
'enter': 0x28, 'space': 0x2c
}
def send_key(dev, key, shift=False):
"""Send a single keystroke"""
modifier = 0x02 if shift else 0x00
key_code = KEYS.get(key.lower(), 0x00)
# HID report: [modifier, reserved, key1, key2, key3, key4, key5, key6]
report = bytes([modifier, 0x00, key_code, 0, 0, 0, 0, 0])
dev.controlTransfer(0x21, 0x09, 0x0300, 0, report)
# Release key
time.sleep(0.1)
dev.controlTransfer(0x21, 0x09, 0x0300, 0, bytes(8))
def type_string(dev, text):
"""Type a string"""
for char in text:
send_key(dev, char)
time.sleep(0.05)
# Connect and execute
dev = usb1.getBackendFromCtypes().getDeviceList()[0].open()
type_string(dev, "whoami")
send_key(dev, "enter")
3. Wireless Access Point / WiFi Repeater
Extend your network coverage:
Setup
sudo apt install hostapd dnsmasq
# Configure wlan0 as AP
sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=HomeLabExtender
hw_mode=g
channel=11
wpa=2
wpa_passphrase=secure_password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
Enable IP Forwarding
sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
# Configure dnsmasq
sudo nano /etc/dnsmasq.conf
interface=wlan0
dhcp-range=192.168.50.100,192.168.50.200,24h
sudo systemctl restart hostapd dnsmasq
4. Security Camera with Motion Detection
sudo apt install motion ffmpeg
# Configure motion
sudo nano /etc/motion/motion.conf
camera_name Camera1
width 800
height 600
framerate 25
netcam_url http://192.168.1.100:8080/?action=stream
# Enable motion detection
locate_motion_mode on
event_gap 60
pre_capture 0
post_capture 5
# Start service
sudo systemctl start motion
# Access stream: http://localhost:8081
Python Script
#!/usr/bin/env python3
import cv2
import subprocess
from datetime import datetime
cap = cv2.VideoCapture(0)
fgbg = cv2.createBackgroundSubtractorMOG2()
while True:
ret, frame = cap.read()
if not ret:
break
fgmask = fgbg.apply(frame)
contours, _ = cv2.findContours(fgmask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if len(contours) > 0:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
cv2.imwrite(f"/home/pi/motion/{timestamp}.jpg", frame)
print(f"Motion detected: {timestamp}")
# Send alert
subprocess.run(["curl", "-X", "POST", "https://webhook.example.com/motion"])
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
5. Network Printer Server
Share a USB printer over the network:
sudo apt install cups cups-client
# Configure CUPS
sudo nano /etc/cups/cupsd.conf
# Allow network access
<Location />
Order allow,deny
Allow 192.168.1.*
</Location>
# Add printer
sudo lpadmin -p myprinter -E -v usb://path/to/printer -m everywhere
# Test
lpstat -p -d
lp -d myprinter /tmp/testfile.txt
6. Temperature and Humidity Logger
Monitor environmental conditions with a sensor:
#!/usr/bin/env python3
import board
import adafruit_dht
import sqlite3
from datetime import datetime
import time
# DHT22 sensor on GPIO 4
sensor = adafruit_dht.DHT22(board.D4)
# Database setup
conn = sqlite3.connect('/home/pi/sensor_data.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS readings (
timestamp TEXT,
temperature REAL,
humidity REAL
)''')
def log_reading():
try:
temp = sensor.temperature
humidity = sensor.humidity
timestamp = datetime.now().isoformat()
cursor.execute('INSERT INTO readings VALUES (?, ?, ?)',
(timestamp, temp, humidity))
conn.commit()
print(f"{timestamp}: {temp:.1f}°C, {humidity:.1f}%")
except RuntimeError as err:
print(f"Error: {err}")
# Log every 5 minutes
while True:
log_reading()
time.sleep(300)
Query Data
sqlite3 /home/pi/sensor_data.db
SELECT * FROM readings ORDER BY timestamp DESC LIMIT 10;
SELECT AVG(temperature) FROM readings;
7. Bluetooth Speaker Controller
Control speakers over Bluetooth:
sudo apt install bluez bluez-tools alsa-utils
# Pair device
bluetoothctl
> scan on
> pair XX:XX:XX:XX:XX:XX
> connect XX:XX:XX:XX:XX:XX
# Set as output
amixer cset numid=3 2
aplay /home/pi/music.wav
8. Magic Mirror Display
Create a smart mirror:
# Install MagicMirror²
git clone https://github.com/MichMich/MagicMirror
cd MagicMirror
npm install
# Create config
cp config/config.js.sample config/config.js
# Configure modules (weather, calendar, news, etc)
npm start
9. Email Server Alert
Send alerts via email for events:
#!/usr/bin/env python3
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
def send_alert(subject, body):
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
# Use local mail server
server = smtplib.SMTP('localhost', 25)
server.send_message(msg)
server.quit()
while True:
if GPIO.input(17):
send_alert("Alert", "Motion detected!")
time.sleep(5)
10. Cryptocurrency Node
Run a lightweight blockchain node:
# Bitcoin Core lightweight mode
sudo apt install bitcoin-qt
# Or use Docker
docker run -d \
--name bitcoin \
-v /home/pi/.bitcoin:/data \
-p 8333:8333 \
-p 8332:8332 \
btcpayserver/bitcoin:24.0
11. Learning Webserver
Serve static content for learning:
sudo apt install nginx
# Create simple page
cat > /var/www/html/index.html << 'EOF'
<html>
<head><title>Pi Zero Server</title></head>
<body>
<h1>Hello from Pi Zero!</h1>
<p>Hostname: <code id="hostname"></code></p>
<script>
document.getElementById('hostname').textContent =
location.hostname;
</script>
</body>
</html>
EOF
sudo systemctl start nginx
Powering Your Pi Zero
Options:
- USB power bank (5000mAh = 24+ hours)
- Solar panel + battery
- PoE (Power over Ethernet) adapter
- AA battery pack (8 × AA = 12V with buck converter)
Power Monitoring
#!/usr/bin/env python3
import subprocess
result = subprocess.run(['vcgencmd', 'measure_volts'], capture_output=True)
voltage = result.stdout.decode()
print(f"Current voltage: {voltage}")
result = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True)
temp = result.stdout.decode()
print(f"Current temperature: {temp}")
Project Ideas by Difficulty
Beginner:
- WiFi access point
- Temperature logger
- Printer server
Intermediate:
- Motion detection camera
- Rubber ducky gadget
- Email alerts
Advanced:
- Tor node
- Blockchain node
- Custom HID device
Conclusion
Pi Zero is perfect for learning embedded systems and creating innovative solutions. Start small and expand as you gain confidence.