Abstract
SQL injection is still a major threat to web applications, while web application firewalls (WAFs) serve as the last line of external defense by rejecting requests that are identified as malicious. However, it is possible for attackers to bypass the WAF by changing the syntax of the SQL injection attack without changing the nature of the attack itself. This paper introduces SeqSQLi, which models WAF bypass as a finite-horizon Markov decision process. The agent uses 51 different mutation operators, and the attack is considered successful if it both passes the WAF and successfully extracts the desired data from the target database. To evaluate the effectiveness of the proposed framework, three different reinforcement learning algorithms, PPO, TRPO, and A2C, are compared in the same experiment. In this experiment, the three algorithms are tested against both a live ModSecurity WAF and a learning-based WAF called SafeLine. The results show that TRPO is the most effective algorithm against ModSecurity, with an induced false-negative rate of 92.6% (average of 3 runs) and an average of 6.40 requests to achieve a successful bypass. PPO achieved a false-negative rate of 85.2% and A2C achieved a false-negative rate of 75.9%. To further test the algorithms, they were also tested against an error corpus of 10 different random seeds. The results show that TRPO was the most consistent, with no variation across the 10 seeds. A2C showed significant instability in the training of the models, failing to converge in 3 of the 10 runs. PPO appeared to have some variation across the 10 seeds, but this variation was the result of a greedy evaluation of the models. Using a best-of-five approach eliminated the variation in the performance of the PPO model. Further analysis of the learned models reveals some interesting patterns in the order of the mutation operators used by the agents. The results of the controlled experiments revealed that swapping the order of the pairs of mutation operators that were tested had no effect on the outcomes of the attacks. However, the models trained on the ModSecurity WAF were unable to transfer to the SafeLine WAF, achieving a 0% success rate in bypassing the latter. Models trained directly on the SafeLine WAF were able to successfully bypass the WAF in 89% of the test episodes. However, in none of those episodes were the attacks able to successfully extract data from the targeted database. These results indicate that successfully bypassing the WAF does not guarantee that the SQL injection attack will successfully extract data from the database.