Abstract
This paper explores the use of reinforcement learning (RL) to automate the discovery and exploitation of SQL injection (SQLi) vulnerabilities. By modeling the attack process as a Markov Decision Process and utilizing tabular Q-learning, the researchers developed agents capable of navigating five major SQLi archetypes: Stacked, Union, Boolean-blind, Error-based, and Time-based blind. A key innovation is the use of HTML response length as a primary feature for state representation, reducing reliance on expert-labeled data. Results demonstrate near 100% success rates in noise-free environments and high robustness to network latency, highlighting the potential for more autonomous security testing tools.
Introduction
SQL injection (SQLi) remains one of the most persistent and dangerous web vulnerabilities. While automated tools like sqlmap are powerful, they often rely on predefined "cheat sheets" and expert-guided logic. When faced with complex, custom, or "Capture The Flag" (CTF) style challenges, these tools frequently fail unless a human expert provides specific guidance to narrow the search space.
The authors address the need for more autonomous security tools by developing RL agents that determine if a site is vulnerable and navigate five distinct archetypes of SQLi (Stacked, Union, Boolean-blind, Error-based, and Time-based blind) which require vastly different exploitation strategies.
Methods
The authors framed SQLi exploitation as a Reinforcement Learning problem using a Markov Decision Process (MDP). They utilized Tabular Q-learning, chosen for its simplicity and interpretability, allowing researchers to observe how the agent’s strategy evolves. A dynamic mock-up server was built to simulate various vulnerabilities, requiring agents to first probe to confirm a vulnerability existed before attempting exploitation.
A key innovation is the reduction of expert reliance through simplified state representation. Instead of a human labeling server responses as "success" or "failure," the agent primarily looks at the length of the HTML response. By grouping actions that produce identical response lengths, the agent builds its own internal map of the server's behavior.
The study used a custom-built synthetic environment to generate thousands of unique challenges across three increasingly difficult simulations, adding error-based and time-based blind vulnerabilities, including scenarios with 5% network traffic "noise" to simulate real-world latency.
Key Results and Insights
The agents achieved near 100% success in exploiting Stacked, Union, Boolean-blind, and Error-based vulnerabilities in noise-free environments. In the most difficult scenario—Time-based blind attacks with 5% network traffic noise—the agent still maintained a 95.83% success rate. Efficiency was also high, with agents typically requiring between 2 and 12 queries to fully exploit a vulnerability.
Beyond raw success rates, the research revealed several key insights:
- Transfer Learning: The agents learned to use queries that provided "joint information." For example, a query designed to test for a Stacked-based vulnerability might also reveal information about the number of columns, aiding a potential Union-based attack.
- Strategy Evolution: Agents shifted from "greedy" strategies in simple environments to more systematic, human-like "interleaving" in complex ones, testing multiple hypotheses in parallel to maximize information gain per query.
- Heuristic Power: Simple syntactical features like response length proved sufficient for an AI to distinguish between complex logical states of a database, reducing the need for natural language processing of error messages.
Conclusion
While successful in controlled simulations, the authors note that scaling to real-world web applications involves challenges like the "curse of dimensionality" and dynamic web content (e.g., random page elements). Future work will likely involve Deep Q-Learning (DQN) or Proximal Policy Optimization (PPO) to handle larger state spaces and more complex environments, including Web Application Firewalls (WAFs) and diverse database backends.
Summary updated