Introduction
Last weekend I was working on a CTF lab where capturing one of the flags required exploiting a local service vulnerable to a stack overflow. I had limited shell access on that system, through an application remote code execution vulnerability, which allowed me identify a service listening on port 8080 on localhost.
The underlying operating system was Windows 10, which led to an immediate challenge of matching environment for debugging the binary and developing a working exploit and I did not have access to intel-based machine. This is where Claude Opus came into the picture. Out of curiosity I asked Claude to write an exploit without the Windows 10 machine and it helped me with a working exploit within few minutes.
Setup
The Setup that I used was,
- MacOS with Claude Desktop and Opus 4.6 model - Host system used during the CTF
- Kali Linux ARM as virtual machine - System with VPN connection to the lab
- Vulnerable binary downloaded and copied to Kali Linux
- Double pivot tunnel using Ligolo-ng - Advanced tunneling tool (alternative to Chisel)
Establishing Access to Port 8080
- The Linux Server on 10.10.100.10 had the Ligolo-ng agent connected to Ligolo-ng proxy running on Attackers system.
- A route to 172.20.10.0/24 via tunnel 1 was added to Attackers system.
- A listener was added to this Linux Server where connection on port 4444 would be forwarded to port 11601 which is the Ligolo-ng agent port.
- Ligolo-ng agent on Target Server connected to listener port 4444 on Linux Server which forwarded the traffic to Ligolo-ng agent and that established the connection with Ligolo-ng proxy running on Attackers system.
- A route to 240.0.0.1/24 via tunnel 2 was added to Attackers system. 240.0.0.0/4 is a magic CIDR that allows access to local ports on connected agents.
Claude Opus 4.6 Magic
Claude Code taking initial SSH access to Kali Linux
Initial analysis of the file, basically what you would normally do using file and checksec
- 32-bit x86 PE binary
- NX (DEP) is disabled (nx: false) - we can execute shellcode on the stack!
- ASLR/PIC disabled (pic: false) - addresses are predictable
- Canary: true - but let's verify if it's actually used in the vulnerable function
- Compiled with MSVC (Windows)
File reversing to understand the application input flow
- Server sends "Enter User Name: "
- Receives username, compares with "iroot" (5 bytes)
- If username is "iroot", sends "User Password: " and receives password
- Then calls fcn.10473ac7 with the password buffer
Identify JMP ESP address
Vulnerability Summary
- Password handler (0x10477cb0) allocates a 1024-byte (0x400) stack buffer
- Calls strncpy_s(stack_buf, 2049, user_input, 2048) - copies up to 2048 bytes into a 1024-byte buffer
- DEP disabled, ASLR disabled, no stack canary in the vulnerable function
- JMP ESP gadget at 0x10477d73 (no null bytes)
- EIP overwrite offset: 1024 (buffer) + 4 (saved EBP) = 1028 bytes
- Bad character: 0x00 (null terminates strncpy_s)
Adjusting Exploit and Gaining Shell :)
- Sizes 1028-1040 return "Wrong password!" — this is expected because the server sends the response before the function returns and crashes
- Crashes start at 1044+ — the intermittent timeouts mean the thread crashes on ret after we corrupt EIP
- Offset 1028 is correct — at 1032 bytes we overwrite EIP (1028 padding + 4 bytes of return address)
- The Kali IP on tun0 is 10.10.10.200. Let me generate shellcode and finalize the exploit.
Prompt 2:
fine_scan.py - EIP Offset Finder
- Connects to the Server on 240.0.0.1:8080
- Authenticates with username iroot
- Sends increasingly large payloads (1028 to 1080 bytes, in 4-byte increments) as the "password"
- Reports whether each size keeps the server alive or causes a crash/timeout
exploit.py - Stack Buffer Overflow Exploit
- Vulnerability: The Server's password handler (fcn.10477cb0) allocates a 1024-byte (0x400) stack buffer but calls strncpy_s allowing up to 2048 bytes — a classic stack buffer overflow.
- Payload structure (1398 bytes total):
- 1028 bytes of "A" — fills the buffer (1024) + saved EBP (4)
- JMP ESP gadget (0x10477d73) — overwrites the return address (EIP) to jump to the stack
- 16-byte NOP sled — landing zone for the jump
- 351-byte shellcode — msfvenom-generated windows/shell_reverse_tcp (shikata_ga_nai encoded, no null bytes
- Execution flow: Connects to the server, sends Admin as username, then sends the overflow payload as the password. The server's ret instruction jumps to the gadget, which jumps to ESP (the NOP sled), which slides into the reverse shell shellcode connecting back to 10.10.10.200:443.
Using Claude to tackle CTF challenges turned out to be a genuinely rewarding experience. What started as a shortcut to avoid hunting down a remote Windows 10 setup ended up being something exciting. Agreed that the above example was relatively simple and the model would have struggled or not worked if there were more bad characters, or ASLR/DEP Enabled, but the results were compelling enough to try it further on other CTFs simple and complex alike.










