# Lure Lab: measuring which bait SSIDs actually catch clients

*A payload for the Hak5 WiFi Pineapple Pager that broadcasts candidate bait network names, records which ones clients join, and ranks them by catch rate — plus the firmware internals and the three bugs that only showed up on hardware.*

## The problem

The Pager lures Wi-Fi clients two ways. **PineAP's SSID pool** broadcasts a list of network names as beacons, hoping a device auto-joins a name it trusts. **Mimic** (KARMA) answers the directed probe requests devices send for networks they remember. On an engagement you load the pool with names you expect to work — `Free WiFi`, `Hotel Guest`, an ISP default, the local chain — but you're guessing, and you never find out which name did the work.

Lure Lab closes that loop. It puts a list of candidate names on air, counts the clients each one catches, and ranks them by catch rate so you keep the winners and drop the dead weight. The approach is borrowed from A/B testing in marketing — run variants against the same audience, measure one metric, pick by data instead of taste — but the interesting part is the implementation on top of PineAP, not the analogy.

## The data is already on the device

No capture code was needed. Every client that associates with one of the Pager's own APs is recorded in two places:

- `/root/recon/recon.db`, PineAP's SQLite database. Table `hostap_client` holds `mac` (BLOB, 12 hex chars), `ssid` (BLOB), `connected_time` and `disconnected_time`. I always read it from a copy, read-only, so a live write can't corrupt the query:

  ```sh
  cp /root/recon/recon.db /tmp/lurelab/recon.db
  sqlite3 -readonly -separator "$(printf '\t')" /tmp/lurelab/recon.db \
    "SELECT connected_time,
            lower(replace(cast(mac AS TEXT), ':', '')),
            cast(ssid AS TEXT)
     FROM hostap_client WHERE connected_time > 0 AND length(ssid) > 0
     ORDER BY connected_time;"
  ```
- **The** `pineapple_client_connected` **alert**, which fires the instant a client joins. A small alert payload appends `epoch \t mac \t ssid` to `live.tsv`, so the on-screen board updates in real time while the main UI holds the display. The alert exposes `$_ALERT_CLIENT_CONNECTED_CLIENT_MAC_ADDRESS`, `_SSID`, `_AP_MAC_ADDRESS` and `_SUMMARY`.

`recon.db` is the history; `live.tsv` is the tail. The UI merges both.

## The metric: clients per hour on air

The score for a name is **distinct clients that joined it, divided by the seconds it was actually being broadcast**, normalised to an hour. Dividing by airtime is the whole point: a name left on air twice as long catches more devices without being more effective, so raw counts are meaningless and only the rate is comparable. Clients are de-duplicated per name by MAC, so one phone reconnecting five times counts once. A separate column, `asked`, counts distinct devices that *probed* for the name (`ssid` table, `type = 4`) without joining — weaker evidence, kept separate.

## Driving PineAP from a payload

PineAP is controlled through a local HTTP API on a Unix socket and a set of `PINEAPPLE_*` CLI wrappers. The ones Lure Lab uses:

| Action | API / command |
| --- | --- |
| read the pool | `GET /api/pineap/ssidpool/get_config` → `ssid_list` (base64) |
| set the pool | `PINEAPPLE_SSID_POOL_CLEAR` / `_ADD <ssid>` |
| start/stop broadcasting | `PINEAPPLE_SSID_POOL_START` / `_STOP` |
| read the SSID filter | `GET /api/pineap/ssidfilter/get_config` → `mode`, `allowed_ssids` |
| set the filter | `PINEAPPLE_SSID_FILTER_MODE allow` / `_ADD allow <ssid>` / `_CLEAR allow` |
| Mimic state | `GET /api/pineap/hostapd/get_config` → `pineap_disabled` |
| Mimic on/off | `PINEAPPLE_MIMIC_ENABLE` / `_DISABLE` |
| pool collection | `PINEAPPLE_SSID_POOL_COLLECT_START` / `_STOP` |

A test is a detached background process (`setsid`, because firmware 2.1 kills everything left in a stopped payload's session). It:

1. **Backs up** the current pool (`ssid_list`), the SSID filter mode and allow list, the pool-collection flag, and Mimic's state, to files under `test/backup/`.
2. **Runs the list** for up to four hours.
3. **Restores** all of the above exactly, on normal end, on stop, or on the next launch after a crash or power-off.

That backup/restore is non-negotiable: a test must never silently become the operator's permanent config.

## Two scheduling modes

**Rounds.** The names take turns in ten-minute rounds, rotating through the list for the length of the test. Each name accrues the same total airtime spread across the same hours, so a name that happened to run over lunch doesn't beat one that ran at 3 a.m. — a straightforward control for time-of-day confounding. Airtime is reconstructed from `rounds.tsv` (`start \t end \t name`, one row per name per round), and a join counts toward a name only if it lands inside that name's on-air window (plus a two-minute grace for association lag).

**All at once** (the default). Every name in the list is broadcast for the whole test, side by side. This matches how the choice is actually made: a person opens their Wi-Fi list and sees all the names at once, so a head-to-head is more faithful than isolated slots. The round clock still ticks for bookkeeping, but the pool is set once and not cleared between rounds. (Caveat worth stating in any result: iOS sorts the Wi-Fi list alphabetically, which gives names earlier in the alphabet a position advantage independent of their appeal.)

## The screen

The UI is a freestanding C program drawing straight to the framebuffer — no libc on the device side. It's built with:

```plaintext
clang --target=mipsel-linux-musl -march=mips32r2 -msoft-float -G0 -Os \
      -ffreestanding -fno-pic -mno-abicalls -nostdlib -static -fuse-ld=lld \
      -Wl,-e,__start -Wl,--gc-sections
```

`/dev/fb0` is a 222×480 ST7796U panel at 16 bpp. The device is used in landscape, so a landscape pixel `(x, y)` maps to panel index `x*222 + (221-y)`. Input comes from `/dev/input/event0` as 16-byte `input_event` records (`EV_KEY`). The binary is about 40 KB. It renders a ranked board with a tag per name — HOT, KEEP, WILD (caught clients but isn't in your pool, usually a Mimic hit), NEW, DROP — a per-name detail view, and a live feed that flashes a catch the moment the alert writes it.

## Three bugs that only appeared on hardware

**1\. Broadcasting a name and accepting a join are different subsystems.** I added a switch to disable Mimic during a test, assuming it would reduce noise. On hardware, the bait name appeared in the phone's Wi-Fi list but every join attempt failed. `GET /api/pineap/hostapd/get_config` showed `pineap_disabled: true` — Mimic was off, and with it the path that completes an association to a pool SSID. The beacon (SSID pool) and the association handler (Mimic) are separate; killing the second makes the AP visible but unjoinable. Fix: drop the Mimic switch, add **on-air-only** instead, which keeps Mimic on but switches the SSID filter to `allow` mode holding just the names currently on air. Noise scoped out, joins intact.

**2\. Clearing the pool stops the broadcast.** To begin each round I called `PINEAPPLE_SSID_POOL_CLEAR` and re-added the new names. Joins stopped after round one. A sniffer showed the air going silent: clearing the pool also disables broadcasting, so the Pager was beaconing nothing. Fix: re-issue `PINEAPPLE_SSID_POOL_START` after every pool change, and in all-at-once mode don't clear at all after the initial load.

```plaintext
185 Beacon (LL Check One)      # after re-arming POOL_START each round
186 Beacon (LL Check Two)
180 Beacon (LL Check Three)
```

**3\. The Stop button froze the UI.** The dashboard's Stop killed the detached test process, but killed it hard enough that the cleanup which releases the framebuffer never ran, locking the screen. The fix is trap ordering. Leaving via the back button keeps the "goodbye" frame up while the pool is restored:

```sh
trap 'stop_test wait; release' EXIT                              # back button
```

The hardware Stop button (SIGTERM) instead hands the screen back *first* and lets the restore finish detached, so the device never appears hung:

```sh
trap 'trap - EXIT; release; stop_test nowait; exit 0' INT TERM   # Stop button
```

There was a fourth, smaller one: the ranking scrambled whenever an SSID contained a space, because busybox `sort -k4,4gr` splits fields on whitespace and the key column drifted. The desktop coreutils `sort` I tested with masked it. Fix: emit a zero-padded numeric key as the first field and use a plain `sort -r`.

## Output

Each test leaves a folder under `/root/loot/lurelab/results/<date>_<list>/`:

- `results.tsv` — the ranking: `rank, ssid, airtime_s, clients, clients_per_hour, asked`
- `catches.tsv` — every join during the test, flagged counted / not counted
- `rounds.tsv`, `names.txt`, `test.log`

`best`\-performing names can be promoted into the live pool from the device, or copied off with `scp` for the report.

## Status

Firmware 2.1.0 (OpenWrt 24.10.1, MIPS 24KEc, musl). The scoring and restore logic have off-device tests that run the engine against fabricated `recon.db` rows and synthetic PineAP command stubs; the capture, broadcast, join and restore paths are verified on hardware. Authorised use only — your own networks, or an engagement where luring clients is in scope.

Code: [`payloads/interception/lure_lab`](https://github.com/0x8R41NR07/pager_payloads/tree/main/payloads/interception/lure_lab)
