cd /news/artificial-intelligence/ai-pentest-agent-from-hallucinations… · home topics artificial-intelligence article
[ARTICLE · art-71606] src=promptcube3.com ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

AI Pentest Agent: From Hallucinations to Real Root Shells

An AI penetration testing agent initially produced a flawless report claiming 23 of 23 ports were breached with root access, but in reality zero shells were obtained due to hallucinated results caused by a flawed validator that used simple string matching. The developer fixed the issue by implementing a breach_confirmed() function requiring actual proof of code execution, such as uid/gid output or a root prompt, which dropped the success rate to 3 real shells. Additional deployment bugs including schema mismatches, ANSI poisoning, and version string confusion were also resolved to improve the agent's reliability.

read2 min views1 publishedJul 23, 2026
AI Pentest Agent: From Hallucinations to Real Root Shells
Image: Promptcube3 (auto-discovered)

Early on, the agent handed me a flawless report: "23 of 23 ports breached, root on all." In reality, the number of shells popped was zero. The agent hadn't hacked anything; it had simply hallucinated a total compromise with absolute confidence.

The "Success" String Match Trap #

The failure lived in the validator. To determine if an exploit worked, I had used a simple string match:

if "login:" in output or "shellcodes" in output.lower():
    return "confirmed"

This created two massive failure modes. First, searchsploit

prints a header containing the word "Shellcodes" during every single search. The agent saw that word and flagged the port as breached before it even tried an exploit. Second, any service banner echoing "login:" was counted as a shell. The result was a report full of "High confidence" claims based on zero evidence.

To fix this, I moved from "vibes" to hard evidence. I implemented a breach_confirmed()

function that requires actual proof of code execution:

_SHELL_EVIDENCE = (
    re.compile(r"uid=\d+\([a-z]+\).*gid=\d+"), # id(1) output
    re.compile(r"root@[\w.-]+:[~/]"), # a root prompt
)

def breach_confirmed(output: str) -> bool:
    return any(p.search(output) for p in _SHELL_EVIDENCE)

Once I forced the agent to prove its claims, the "23/23" success rate plummeted to 3. But those 3 were real.

Solving the Plumbing Bugs #

With the lying stopped, I could finally see why the success rate was so low. It wasn't a lack of "intelligence," but boring deployment and parsing bugs:

Schema Mismatches: The model tried to callsearchsploit

using{"query": "vsftpd"}

, but the tool required{"keyword": "..."}

. TheMCPlayer rejected these silently. I fixed this by allowing multiple keys (keyword/query/search).ANSI Poisoning:msfconsole

uses color escape codes. My parser capturedexploit/unix/\x1b[45mftp\x1b[0m/vsftpd_234

as the module path, which obviously failed to load. I added astrip_ansi()

step to clean the logs.Version String Confusion: nmap sometimes reports versions first (e.g., "2 (RPC #100000)"). My parser thought "2" was the product name and sent it to Metasploit. I added a leading-digit guard to prevent this.

This journey from a "perfect" fake report to a flawed but honest AI workflow was the most valuable part of the project. Real-world LLM agent deployment is less about the prompt and more about the rigorous validation of the output.

Next Ekko: Post-Quantum E2EE for Mainstream Messengers →

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @mcp 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ai-pentest-agent-fro…] indexed:0 read:2min 2026-07-23 ·