Manuscript Offprint

arXiv:2609.07344

Staying on the Attack Path: Structured State for Long-Horizon Automated Penetration Testing

Weizhe Wang, Yitong Zhang, Yao Zhang, Xiaoqiang Di, Zhigang Li, Bin Wu, Guangquan Xu

Abstract

Large language model (LLM) based agents are increasingly applied to cybersecurity tasks such as vulnerability discovery and automated penetration testing. On long-horizon security tasks, however, such agents remain limited by context forgetting and intent drift: early critical facts and causal reasoning chains are lost over extended interactions, and the agent falls into aimless, repetitive exploration. This paper proposes Intentest, an intent-graph-guided automated penetration testing agent that externalizes long-horizon state from the LLM's context window onto a persistent fact-intent directed acyclic graph (DAG), thereby substantially reducing invalid transitions. We evaluate Intentest on automated penetration testing of web applications, a representative long-tail task in cybersecurity. In the DAG, verified network states are stored as immutable fact nodes, and exploration directions are constrained as intent edges bounded by predecessor facts. The system adopts a three-layer architecture, in which the fact-intent mapping layer maintains the global state, the task scheduling and allocation layer ensures execution stability through two-phase degradation recovery and multi-dimensional adaptive load balancing, and the intent retrieval and prediction layer provides tactical priors through a top-down five-stage filtering algorithm. On a benchmark of real CTF challenges covering more than ten vulnerability types across three difficulty levels, Intentest achieves an overall success rate of 88.2% and a success rate of 75.0% on hard tasks, improving over the baseline VulnBot (44.1% and 25.0%) by approximately 44 and 50 percentage points. Ablation experiments further show that the intent retrieval and prediction reduce the average number of rounds on successful medium and hard tasks by about 33% and 48%, respectively, without changing the set of solvable tasks.

Keywords: Automated Penetration Testing, Large Language Models, LLM Agents, Intent Drift, Fact-Intent Graph

1. Introduction

With the rapid advances of large language models (LLMs) in natural language processing, complex code generation, and logical reasoning [1], LLM-based agents are increasingly applied to cybersecurity operations as autonomous operators, covering tasks such as vulnerability detection, security assessment, and penetration testing. A central concern for such security-oriented agents is long-horizon state management: an agent accumulates observations over many interaction steps, while the context window of the underlying LLM limits how much of this history the model can attend to at each decision point. These limitations are most consequential in long-tail tasks, where success depends on a small number of subtle facts obtained early in the process and on the causal chains that connect them to later decisions. Automated penetration testing, a representative long-tail security task of this kind, proactively identifies exploitable vulnerabilities, and its automation extends LLM-based agents into the adversarial domain [2]. Traditional security assessment and penetration testing mainly rely on vulnerability scanners built upon static rules or on highly customized manual scripts. As dynamic network environments [3], polymorphic malware, and advanced persistent threats (APTs) become increasingly prevalent, these conventional methods exhibit structural limitations, including weak environment awareness, limited logical reasoning, and insufficient autonomous decision-making. Academia and industry are therefore investing increasing effort in autonomous agents equipped with environment perception and operational capabilities, aiming to make automated penetration testing practical [4, 5, 6].

However, applying LLMs directly to automated penetration testing faces substantial challenges [7, 8]. Penetration testing is a typical high-dimensional, high-uncertainty long-tail task. The target system's network topology, open ports, service versions, and firewall mechanisms are not observable to the agent before probing, and the agent must collect environmental observations through long sequences of reconnaissance and probing operations. More importantly, a successful exploit is rarely the result of a single operation. It requires comprehensive causal reasoning over facts obtained at different time points and across different network layers. The system must identify, among a large number of scattered fact fragments, the vulnerable path that leads to the target privilege. Existing LLMs, when handling such long-context tasks, tend to neglect early critical facts.

∗^{*}Corresponding author

Preprint submitted to arxiv

September 9, 2026 because of attention dilution and context-window limits [9]. In real penetration engagements, this phenomenon manifests as context forgetting and intent drift [10]. Because they often fail to stably persist and retrieve historical facts in memory, many existing penetration testing agents frequently explore aimlessly in complex intranet environments or web applications with deep directory structures, getting stuck in ineffective operations and loops [11, 12, 13], or neglecting facts that are crucial for eventual privilege escalation and vulnerability chaining [14, 15].

To address these problems, this paper proposes Intentest, an intent-graph-guided automated penetration testing agent. The core idea is to relieve the LLM of global state maintenance and instead employ a graph-theoretic state machine built on an immutable fact-intent directed acyclic graph (Fact-Intent DAG) to anchor and constrain agent behavior. In the Intentest architecture, all verified network states are persisted as fact nodes (Fact) in the graph, while the model's exploration directions are strictly defined as intent edges (Intent) constrained by predecessor facts. This design keeps the agent advancing along paths with strict causal inheritance, thereby substantially limiting divergent, aimless exploration.

To evaluate Intentest's ability to handle complex long-tail tasks and multi-fact reasoning, we compared it with baseline systems on real web-based Capture The Flag (CTF) challenges covering mainstream web vulnerabilities, including SQL injection, SSRF, file upload, and deserialization. The challenges are divided into three difficulty levels (easy, medium, and hard) based on the exploitation difficulty of the vulnerabilities they contain. In addition, we conducted an ablation study in which the intent retrieval and prediction module was disabled to further quantify the contribution of intent guidance. The experimental results show that Intentest improves both the effectiveness (task success rate) and the efficiency (exploration rounds) of automated vulnerability exploitation. The main contributions of this paper are summarized as follows:

  1. A fact-intent DAG mapping architecture. Targeting context forgetting and intent drift of LLMs in long-sequence testing, we avoid direct peer-to-peer communication between agents, which easily causes state conflicts and information overload [16], and instead construct a global control blackboard from fact nodes and intent edges, enabling asynchronous collaboration among multiple agents based on shared state and reducing the model's aimless exploration.

  2. A high-robustness task scheduling and allocation mechanism. Targeting network latency and malformed LLM outputs that commonly occur in real environments, we propose a two-phase task degradation recovery mechanism that intercepts a task before termination and recovers partial facts from residual logs. A multi-dimensional adaptive load-balancing algorithm prevents computational overload, improving execution stability and reducing the computational cost of infinite loops.

  3. An intent-graph construction and retrieval prediction method. To address the noise that retrieval-augmented generation (RAG) tends to introduce [17], we design a top-down five-stage filtering algorithm. By enforcing structural constraints, the algorithm can substantially reduce the causal hallucinations that LLMs produce due to mere word overlap, enabling the agent to extract tactical logic and reason precisely.

  4. Systematic experimental comparison and ablation validation. On a real-world CTF test set covering multiple mainstream web vulnerabilities (e.g., SQLi, SSRF, deserialization) with a clear difficulty gradient, we compare Intentest with baseline systems. The experiments show that Intentest improves the overall success rate by approximately 44 percentage points and the hard-task success rate by approximately 50 percentage points over VulnBot, the baseline with the highest overall success rate. The ablation study further corroborates the effectiveness of the proposed method in mitigating the LLM's neglect of long-tail facts and reducing ineffective exploration.

The rest of this paper is organized as follows. Section 2 reviews related work. Section 3 presents the motivation and the challenges addressed in this paper. Section 4 describes the design and implementation of Intentest. Section 5 presents the experimental evaluation together with a case analysis. Section 6 discusses the role and applicability boundary of the intent graph and the evidence for the necessity of graph state, and presents a failure analysis of both Intentest and the baselines. Section 7 discusses threats to validity. Section 8 concludes the paper and outlines future work.

References (39)