Manuscript Offprint

arXiv:2610.20902

Thinking in Graphs: Neo4j-Backed Exploit-Chain Reasoning for LLM Penetration-Testing Agents

Joas Antonio dos Santos Barbosa

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Joas Antonio dos Santos

Independent Researcher — AI and Offensive Security

São Paulo, SP, Brazil

joas.santos@redteamleaders.com

ORCID: 0009-0003-1772-9826

Abstract—Large language model (LLM) coding agents such as Claude Code and OpenAI Codex can already drive individual penetration-testing tools, but they reason about an engagement as a flat list of findings held in a context window. Attackers, by contrast, think in graphs: isolated low-severity exposures become catastrophic once chained through credential capture, privilege escalation, and lateral movement. This gap feeds a common belief that AI agents cannot truly chain exploitation end to end—a belief we argue describes the flat context window, not the model: give the agent a persistent attack graph and chaining becomes a deterministic database operation rather than an emergent hope. We present CHAINGRAPH, a lightweight pattern that externalizes exploit-chain reasoning into a Neo4j property graph connected directly to an off-the-shelf coding agent via the Model Context Protocol (MCP)—no bespoke harness required. Findings, attack steps, credentials, assets, and tamper-evident evidence receipts are stored as typed nodes with pre/post-condition edges (ENABLES, REQUIRES, YIELDS, ESCALATES_TO, PIVOTS_TO); JSON and Markdown artifacts serve as the documentary/evidential memory while Neo4j serves as the relational reasoning memory. We formalize five operator questions as reusable Cypher and Graph Data Science (GDS) queries—next-step inference, entry-to-crown-jewel pathing, combined-severity promotion, evidence provenance, and chokepoint identification—and introduce a chain severity score that is distinct from per-finding local severity. On a synthetic multi-forest Active Directory engagement modeled on GOAD and loaded into Neo4j 5.26 with GDS 2.13, the graph promotes three findings rated Medium in isolation to Critical once their path to the forest root is materialized, and betweenness centrality identifies the PKINIT authentication and DCSync steps as the highest-value chain break-points. Returning a single eight-hop attack path as a graph query result rather than re-feeding the raw engagement corpus reduced the reasoning payload by roughly 98% on a character-based token proxy. We give a complete, reproducible configuration—Docker, schema, queries, MCP wiring for both Claude Code and Codex, and a PostToolUse evidence-capture hook—and discuss the security, calibration, and dual-use implications of giving an autonomous agent a persistent attack graph. We frame all quantitative observations as illustrative single-run measurements, not a controlled benchmark.

Index Terms—attack graph, Neo4j, exploit chain, LLM agent, autonomous penetration testing, Model Context Protocol, Cypher, Graph Data Science, chain severity, Active Directory, agent memory, evidence grounding

I. INTRODUCTION

In 2015, John Lambert captured the asymmetry at the heart of network defense in a single sentence: “Defenders think in lists; attackers think in graphs. As long as this is true, attackers win” [35]. A vulnerability scanner emits a list. A compliance report emits a list. A ticketing queue emits a list. The adversary, however, does not care about any single finding—they care about the path: the sequence of individually unremarkable conditions that, composed, carries them from an unauthenticated network position to control of the enterprise.

The recent wave of LLM-driven penetration-testing agents inherits the defender's list-shaped worldview almost by accident. PentestGPT [36], AutoAttacker [40], Incalmo [38], VulnBot [42], and autonomous Active Directory (AD) agents [37] all keep their working model of the engagement inside the LLM context window—a flat, linear transcript of observations and tool outputs. This representation has three structural weaknesses. First, it degrades with length: transformer models attend unevenly to long contexts, and relevant facts buried in the middle are effectively lost [45]. Second, it conflates storage with reasoning: every question about the engagement—"does finding X reach a domain admin?"—requires re-reading the entire transcript, because there is no index over relationships. Third, it provides no stable, queryable notion of a chain: the agent must re-derive, token by token, that a Medium-severity LLMNR exposure feeds a crackable hash, which feeds an AD CS misconfiguration, which yields a forged domain-admin certificate.

Consider the running example we return to throughout the paper. An agent captures an LLMNR response, cracks the resulting hash to a domain-user password, finds an Active Directory Certificate Services template that lets any enrollee request a certificate for an arbitrary principal, forges a domain-admin certificate, authenticates with it, and runs DCSync. In a list-shaped report these are five findings: one Medium (LLMNR), one Medium (weak password), one High (the template), and two operational notes. In a graph they are one path from an unauthenticated position to the forest root—and the first Medium is the match that lights the whole chain.

No LLM reasoning over a flat transcript reliably recovers that path on demand; a shortestPath query recovers it in milliseconds and returns only the answer.

The classical security literature solved the representation problem decades ago. Attack graphs—formalized by Phillips and Swiler [26], automated by Sheyner et al. [27], scaled by MulVAL [28] and NetSPA [29], and surveyed exhaustively since [33], [34]—model reachability as a directed graph of pre- and post-conditions and compute security metrics over paths, not nodes [31], [32]. BloodHound [49] brought exactly this idea to AD, storing identities, hosts, and access-control relationships in Neo4j and answering “six degrees of Domain Admin” with a graph query. The missing piece is not the graph; it is the wiring between the graph and the modern LLM agent that now does the hands-on-keyboard work.

The paradigm we break. A common objection to autonomous offensive AI holds that language models cannot truly chain exploitation: they can drive a single tool, but they lose the thread across a multi-step campaign, declare victory on narrative plausibility, and never assemble isolated findings into an end-to-end path from foothold to domain control. This skepticism is not baseless—it accurately describes the flat-context agent, and the pentest literature documents exactly these failures: PentestGPT losing track over long interactions [36], AD agents going “down rabbit holes” [37]. But the limitation is an artifact of the representation, not of the model’s capability. The evidence that models can chain is already in: teams of LLM agents exploit real zero-day vulnerabilities that single agents cannot [39], and systems with an explicit state layer plan multi-host campaigns [38]. Our claim is sharper: give the agent a persistent attack graph as external reasoning memory, and chaining stops being an emergent hope and becomes a database operation—the eight-hop path in our case study (Section IX) is returned by a single shortestPath query, deterministically, every time. The paradigm “AI can’t chain exploitation” is really “a context window can’t hold a chain.” Replace the context window with a graph, and the chain is always there to be walked.

This paper supplies that wiring. We argue that an LLM pentest agent should treat a graph database not as an output format but as its external reasoning memory, and that this can be achieved today with an unmodified coding agent—Claude Code [53] or OpenAI Codex [54]—connected to Neo4j through the Model Context Protocol (MCP) [17]–[19]. We call the pattern CHAINGRAPH. Our contributions are:

  1. A dual-memory architecture (Section IV) that separates documentary/evidential memory (versioned JSON and Markdown with content-hashed evidence receipts) from relational reasoning memory (a Neo4j property graph), and a typed schema (Section V) whose edges encode attack-step pre/post-conditions.

  2. A reasoning layer (Section VI) expressing five concrete operator questions as reusable Cypher/GDS queries, and a chain-severity model that promotes findings by the paths they unlock rather than by their class in isolation.

  3. A zero-harness integration recipe (Section VIII): step-by-step Docker, schema, MCP, permission, and evidence-capture-hook configuration for Claude Code and Codex, with read/write tool separation enforced at the protocol boundary.

  4. A reproducible case study (Section IX) on a synthetic multi-forest AD engagement modeled on GOAD [51], loaded into a live Neo4j 5.26 + GDS 2.13 instance, demonstrating next-step inference, entry-to-crown-jewel pathing, severity promotion, and chokepoint analysis on real query output.

  5. An efficiency and calibration analysis (Section X) measuring the reasoning-payload reduction from graph-scoped retrieval versus flat-context re-reading, and a discussion (Sections XI–XII) of the security, dual-use, and calibration implications.

We are deliberate about scope: the quantitative figures are single-run measurements on a synthetic lab, offered to motivate and illustrate the architecture, not to establish statistically powered benchmarks. Section XII states the threats to validity plainly.

References (58)