AdvSQLi: Generating Adversarial SQL Injections against Real-world WAF-as-a-service

Zhenqing Qu, Xiang Ling, Ting Wang, Xiang Chen, Shouling Ji, Chunming Wu · DOI

TL;DR

This paper introduces AdvSQLi, a novel framework for generating adversarial SQL injection (SQLi) payloads that can bypass Web Application Firewalls (WAFs) as a service, even in black-box settings. AdvSQLi achieves this by transforming SQLi payloads using a context-free grammar and a Monte Carlo Tree Search, ensuring the payloads retain their malicious functionality while evading detection. The research demonstrates that even commercial WAF-as-a-service solutions are vulnerable, highlighting significant security gaps.

What Problem Does This Paper Address?

Web Application Firewalls (WAFs) are a crucial first line of defense against web attacks like SQL injection (SQLi). With the rise of cloud computing, WAF-as-a-service (WaaS) has become popular for its ease of deployment and management. However, the security vulnerabilities of these WaaS offerings remain largely unexplored, despite their widespread adoption. Existing methods for generating adversarial SQLi payloads often fail to preserve the original payload's functionality or are inefficient in the discrete, complex space of SQL queries. This gap leaves WaaS solutions susceptible to sophisticated attacks, posing a significant risk to web services.

Methods

AdvSQLi tackles this challenge with a two-pronged approach:

  1. Hierarchical Tree Representation and Context-Free Grammar (CFG) Mutation: The original SQLi payload is first parsed into a hierarchical tree structure. Then, a weighted mutation strategy based on a context-free grammar is applied. This CFG defines rules for transforming nodes within the tree, generating a set of equivalent SQLi payloads. Crucially, these mutations are designed to preserve the original payload's semantics (functionality and maliciousness). The CFG allows for fine-grained manipulation, going beyond simple string replacements.
  2. Monte Carlo Tree Search (MCTS) Guided Exploration: The space of potential adversarial payloads is vast. To efficiently navigate this space, AdvSQLi employs MCTS. MCTS guides the search for effective adversarial payloads by building a search tree, where nodes represent states of the SQLi hierarchical tree and edges represent mutations. This approach is efficient and does not require feedback on maliciousness scores from the WAF, making it suitable for strict black-box scenarios.

Datasets

The authors utilized several datasets for their evaluation:

  • HPD (HttpParamsDataset): Contains malicious SQLi payloads and benign HTTP request parameters.
  • SIK (SQL Injection Dataset): A Kaggle dataset used for SQLi evaluation.
  • MDD (Malicious SQL Injection Dataset): A custom dataset created by the authors, including prevalent SQLi payloads like union-based, blind, and error-based injections.

For training ML models, they used subsets of HPD and SIK. For evaluating WAF bypasses, they used MDD and subsets of HPD and SIK.

Key Insights and Ideas

  • Semantic Preservation is Key: Unlike many prior works that focused on simply finding any payload to trigger a vulnerability, AdvSQLi emphasizes generating payloads that functionally and maliciously match the original. This is critical for realistic attack scenarios and for understanding WAF vulnerabilities comprehensively.
  • CFG for Structured Mutation: Using a context-free grammar to guide mutations on a hierarchical representation of SQLi payloads allows for more systematic and semantically sound transformations than simple string manipulation.
  • MCTS for Black-Box Efficiency: Monte Carlo Tree Search proves to be an effective strategy for navigating the complex, discrete search space of SQLi payloads in a black-box setting, where direct feedback on attack success is limited.
  • WAFs are Surprisingly Vulnerable: Even commercial WAF-as-a-service solutions, often considered robust, exhibit significant vulnerabilities to AdvSQLi, particularly in handling JSON-based requests and parsing complex SQL structures.

Key Results

  • High Attack Success Rate (ASR): AdvSQLi achieved a maximum ASR of 100% against state-of-the-art ML-based SQLi detectors.
  • Bypassing Commercial WAFs: AdvSQLi successfully bypassed all 7 tested WAF-as-a-service solutions from mainstream vendors (AWS, F5, CSC, Fortinet, Cloudflare, Wallarm, ModSecurity).
  • Significant Bypass Rates: For instance, AdvSQLi achieved an ASR of over 79% against the F5 WAF.
  • Efficiency: AdvSQLi demonstrated higher effectiveness and efficiency compared to baseline methods, achieving higher ASRs with fewer queries.
  • Semantic Preservation: AdvSQLi consistently preserved the semantic validity of generated payloads (VGP of 1.0), while baseline methods like WAF-A-MOLE often produced invalid payloads.
  • Identification of WAF Weaknesses: The study identified general flaws in WAFs, such as issues with parsing JSON-type parameters and non-robust detection signatures for semantic matching and regular expression matching.

Limitations and Future Work

  • Dataset Limitations: The authors acknowledge the lack of a comprehensive, standardized benchmark dataset for SQLi, forcing them to rely on existing ones and create their own, which might not cover all possible scenarios.
  • Semantic Equivalence Verification: Verifying semantic equivalence of SQLi payloads is challenging and primarily relies on observing running results, making it difficult to guarantee strict equivalence in all cases.
  • Manual CFG Definition: The context-free grammar is manually defined, which, while ensuring safety, might limit the scope of generated payloads based on prior knowledge. However, the framework is designed to be extensible by adding new grammar rules.
  • Future Work: The authors plan to continue tracking vendor responses, develop methods for automatically summarizing bypass patterns, and extend their framework to other attack domains like cross-site scripting (XSS) and webshells. They also suggest exploring multi-modal detection mechanisms for WAFs.

Summary updated

BibTeX
@article{qu2024advsqli,
  author = {Zhenqing Qu and Xiang Ling and Ting Wang and Xiang Chen and Shouling Ji and Chunming Wu},
  title = {{AdvSQLi: Generating Adversarial SQL Injections against Real-world WAF-as-a-service}},
  journal = {IEEE Trans. Inf. Forensics Secur.},
  year = {2024},
  doi = {10.1109/tifs.2024.3350911},
}
Figure