DeepSQLi: Deep Semantic Learning for Testing SQL Injection

Muyang Liu, Ke Li, Tao Chen

Abstract

SQL injection (SQLi) remains a pervasive threat to web applications, often evading traditional rule-based testing tools through complex semantic variations. This paper presents DeepSQLi, a tool that leverages Neural Machine Translation (NMT) and the Transformer architecture to automate the generation of sophisticated SQLi test cases. By treating SQLi as a linguistic problem, DeepSQLi generates diverse, semantically equivalent attacks capable of bypassing modern web application firewalls. Our evaluation shows that DeepSQLi identifies vulnerabilities more efficiently than industry standards like SQLmap, including the discovery of previously unknown zero-day vulnerabilities.

Introduction

Automated testing for SQL injection is traditionally hampered by the reliance on manually defined patterns or blacklists. Attackers can easily circumvent these by altering encodings, using synonymous commands, or manipulating whitespace. While existing AI-based security tools primarily focus on classification, they lack the generative capacity to proactively discover hidden vulnerabilities. DeepSQLi addresses this gap by modeling the "semantic naturalness" of SQL, allowing it to translate simple inputs into complex, evasive attack vectors.

The DeepSQLi Framework

The core of DeepSQLi is a Transformer-based sequence-to-sequence (Seq2Seq) model. Unlike traditional recurrent networks, the Transformer uses multi-head self-attention to capture long-range dependencies within SQL strings. The system operates in a multi-step workflow designed for continuous improvement and diversification.

The DeepSQLi system architecture and workflow, illustrating the integration of training, crawling, test generation, and evaluation.

As shown in the workflow above, the process consists of four primary stages:

  1. Training: Building and preprocessing a dataset of SQLi instances.
  2. Crawling: Identifying input fields within the System Under Test (SUT).
  3. Test Case Generation: Using the NMT model and Beam Search to produce a diverse set of test cases.
  4. Evaluation: Executing test cases against the SUT and feeding failed cases back into the model for further refinement.

Semantic Learning and Data Augmentation

To effectively learn the nuances of SQL syntax and evasion, DeepSQLi requires a robust training dataset. The authors augmented an initial set of 19,220 instances from GitHub into a final dataset of 56,841 instances using five specialized mutation operators.

Mutation operators used to generate semantically equivalent but syntactically diverse SQLi test cases.

These operators—Predicate, Unicode, ASCII, Keywords, and Blank—teach the model how to disguise attacks using different encodings and logical structures without changing the underlying malicious intent. During inference, DeepSQLi employs Beam Search to generate the top m most probable sequences, ensuring a high degree of test case diversity that can bypass specific firewall rules.

Key Results and Performance

DeepSQLi was evaluated against six real-world Java-based web applications and compared with SQLmap, the industry standard for SQLi automation.

  • Detection Capability: DeepSQLi successfully identified all known vulnerabilities in five of the six test applications. Notably, it discovered zero-day vulnerabilities in the "Office Talk" and "Checker" benchmarks that had been missed by previous research.
  • Efficiency and Speed: The tool demonstrated a significantly higher Exploitation Rate (ER), finding more bugs with fewer test cases. In some benchmarks, DeepSQLi operated up to six times faster than SQLmap.
  • Filter Evasion: Under "Advanced" input validation settings (e.g., filtering characters like & or |), SQLmap's effectiveness dropped significantly. In contrast, DeepSQLi's semantic understanding allowed it to generate successful bypasses consistently.

Conclusion

DeepSQLi demonstrates the power of treating SQL injection as a linguistic translation problem. By mastering the semantics of SQL, the tool provides a highly generalizable and effective solution for proactive security testing. Future work will focus on incremental learning to update the model in real-time and expanding the framework to address other injection vulnerabilities, such as Cross-Site Scripting (XSS).

Summary updated

BibTeX
@inproceedings{liu2020deepsqli,
  author = {Muyang Liu and Ke Li and Tao Chen},
  title = {{DeepSQLi: Deep Semantic Learning for Testing SQL Injection}},
  booktitle = {ISSTA},
  year = {2020},
  doi = {10.1145/3395363.3397375},
}
Figure