PwnGPT: Automatic Exploit Generation Based on Large Language Models

Wanzong Peng, Lin Ye, Xuetao Du, Hongli Zhang, Dongyang Zhan, Yunting Zhang, Yicheng Guo, Chen ZhangACL 2025

Abstract

Automatic Exploit Generation (AEG) is a critical task in offensive security, traditionally hampered by the limitations of symbolic execution and rigid templates. While Large Language Models (LLMs) demonstrate significant potential in code generation, their application to binary exploitation is restricted by context window constraints, precision requirements, and logic gaps in modeling low-level memory states. This paper presents PwnGPT, a modular framework that transforms LLMs into autonomous security researchers. By integrating static analysis for context pruning, role-play prompting for exploit planning, and an iterative verification module for error correction, PwnGPT significantly enhances the success rate of AEG. Our evaluation on a benchmark of 19 diverse Capture The Flag (CTF) challenges shows that PwnGPT increases the exploit completion rate of OpenAI’s o1-preview from 26.3% to 57.9%.

Introduction

The "holy grail" of offensive security is the ability to automatically identify vulnerabilities and generate functional exploit scripts. Traditional AEG systems often struggle with the creative logic required for modern exploits, particularly when dealing with complex attack chains. LLMs offer a new paradigm but face hurdles: decompiled code is often too large for context windows, and exploits require byte-perfect precision. PwnGPT addresses these challenges by decomposing the exploitation process into manageable, specialized modules.

The PwnGPT Framework

PwnGPT utilizes a three-pillar architecture to guide LLMs through the exploitation lifecycle:

  1. Analysis Module: To overcome context window limitations, this module employs static analysis to prune decompiled code. It identifies "key functions" (e.g., those near main or with high-risk names) and provides the LLM with a distilled representation of the program's logic and security mitigations (e.g., NX, Stack Canaries).
  2. Generation Module: This module uses "role-play prompting" to frame the LLM as a CTF expert. It leverages Chain-of-Thought (CoT) reasoning to develop a step-by-step exploit plan before generating Python code using the pwntools library.
  3. Verification Module: The framework attempts to execute the generated exploit in a controlled environment. If execution fails, the resulting traceback and error messages are fed back into the LLM, enabling it to reflect on the failure and iteratively refine the exploit.

Evaluation and Results

The researchers evaluated PwnGPT using a benchmark of 19 challenges covering stack overflows, format string vulnerabilities, integer overflows, and heap exploitation. Models tested included GPT-4o, OpenAI o1-preview, and the Qwen series.

Performance of various LLMs across the four primary stages of the exploitation process.

The results demonstrate that PwnGPT provides a substantial performance boost across all models. For instance, the success rate for OpenAI o1-preview jumped from 26.3% to 57.9%, while GPT-4o saw an increase from 21.1% to 36.8%. The iterative verification module proved essential, as models frequently corrected their own logic after observing execution errors.

Detailed breakdown of model performance across exploitation tasks, categorized by vulnerability type (stack, format string, integer, and heap).

Key Insights

  • Reasoning Models are Superior: Reasoning-focused models like o1-preview significantly outperform standard chat models in AEG. Notably, o1-preview was the only model capable of identifying and exploiting integer overflow vulnerabilities.
  • Context Pruning is Essential: Directly feeding large decompiled files to LLMs introduces excessive noise. Static analysis-driven pruning ensures the model focuses on security-critical code paths.
  • The Heap Challenge: Despite the framework's success, heap exploitation remains a significant hurdle. The abstract nature of dynamic memory management is currently difficult for LLMs to model without real-time debugging integration.

Conclusion

PwnGPT demonstrates that combining LLMs with traditional static analysis and iterative feedback can dramatically improve automatic exploit generation. While challenges like heap exploitation and stripped binaries remain, the framework provides a robust foundation for future autonomous security research. Future work will explore the integration of Retrieval-Augmented Generation (RAG) and live debugging environments to further bridge the gap between LLM reasoning and low-level memory states.

Summary updated

BibTeX
@inproceedings{peng2025pwngpt,
  author = {Wanzong Peng and Lin Ye and Xuetao Du and Hongli Zhang and Dongyang Zhan and Yunting Zhang and Yicheng Guo and Chen Zhang},
  title = {{PwnGPT: Automatic Exploit Generation Based on Large Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure