HTN-PT: A Hierarchical Task Network-Guided Framework for LLM-Based Automated Web Penetration Testing

Authors:
  • CWChen Wang
    Chen Wang
  • HLHai Li
    Hai Li
  • GSGuoxuan Sun
    Guoxuan Sun
  • XLXiaofeng Li
    Xiaofeng Li
  • CTChongle Tian
    Chongle Tian

Abstract
Penetration testing is an important security assessment technique for proactively discovering and validating security vulnerabilities. However, conventional penetration testing relies heavily on human expertise, making consistent and repeatable execution at scale difficult to achieve. Large language models (LLMs) offer a new approach to automating penetration testing, yet existing methods still face several challenges in multi-stage tasks, including task-state loss, success judgments unsupported by concrete evidence, and repeated attempts along ineffective execution paths. To address these issues, we propose HTN-PT, an automated web penetration testing framework that integrates LLMs with a Hierarchical Task Network (HTN). HTN-PT explicitly organizes task decomposition, preconditions, and execution dependencies, while structured runtime memory preserves facts across stages. This design prevents long-horizon task state from depending on the LLM’s transient conversational context. Within this framework, the LLM is responsible only for vulnerability interpretation, action generation, and feedback analysis for the current task. Execution outcomes are independently verified using external evidence, while failure feedback is used either to repair the current execution path or to switch to another vulnerability candidate, thereby improving continuity and recoverability across multi-stage execution. We conduct 1600 experiments on 20 authorized web testbeds using four foundation models and four task-control methods. HTN-PT achieves overall Pass@1 and Pass@5 scores of 43.25% and 67.5%, respectively. Testbed-level paired cluster-bootstrap intervals for its differences from the three baselines remain above zero for both metrics. The results show that HTN-PT improves task-state continuity, outcome verification, and failure recovery for LLMs in multi-stage penetration testing, thereby enhancing end-to-end task completion.