Adversarial SQL Injection Generation with LLM-Based Architectures Ali Karakoc1 and H. Birkan Yilmaz1*
arXiv:2605.11188v1 [cs.CR] 11 May 2026
1
Department of Computer Engineering, NETLAB, Bogazici University, Istanbul, Turkey.
*Corresponding author(s). E-mail(s): [email protected]; Contributing authors: [email protected]; Abstract SQL injection (SQLi) attacks are still one of the serious attacks ranked in the Open Worldwide Application Security Project (OWASP) Top 10 threats. Today, with advances in Artificial Intelligence (AI), especially in Large Language Models (LLMs), an opportunity has been created for automating adversarial attack tests to measure the defense mechanisms. In this paper, we aim to create a comprehensive evaluation of use cases that utilize LLMs for adversarial SQL injection generation. We introduce two novel LLM-based systems, Retrieval Augmented Generation for Adversarial SQLi (RADAGAS) and Reflective Chain-of-Thought SQLi (RefleXQLi), and compare them with existing baselines against 10 Web Application Firewalls (WAFs) and one execution-based MySQL validator. To perform a comprehensive test, we used six rule-based open-source WAFs (ModSecurity PL1–3, Coraza PL1–3), 2 AI/ML-based WAFs (WAF Brain, CNN-WAF), and 2 commercial WAFs (AWS WAF and Cloudflare WAF). For the LLM models, we used GPT-4o, Claude 3.7 Sonnet, and DeepSeek R1. Our tests consist of 240 experiments that generate 240,000 payloads and perform 2.2 million tests against WAFs. Our comprehensive evaluation reveals that RADAGAS-GPT4o outperforms other baseline models with a 22.73% bypass rate. The proposed RADAGAS variants are highly successful on AI/ML-based WAFs (92.49% on WAF-Brain by RADAGAS-DeepSeek, 80.48% on CNN-WAF by RADAGASClaude), but struggle to bypass rule-based WAFs (0–5.70% on ModSecurity and Coraza). In addition to these findings, another observation is that creating less diverse payloads achieves more bypasses, however they show poor results if the initially chosen payload is not successful. We observe that our findings provide a comprehensive view on using LLM-based approaches in security testing. Keywords: SQL injection, Large language models, Web application firewalls, Adversarial testing, RAG-based generation, Security benchmarking
1
1 Introduction Web applications are the fundamental part of the modern digital world, and connect people and businesses in different critical domains like healthcare, finance, social networking, e-commerce and government services. Although it is one of the very known and initial web application attacks, SQL Injection vulnerabilities are still one of the major problems persisting on the Open Worldwide Application Security Project (OWASP)’s Top 10 most critical web application security risks [1]. The impact of SQL injection attacks can be leveraged with more sophisticated techniques to steal critical information, obtain remote services or denial of services. To protect the web application services against SQL Injection attacks, using advanced defense mechanisms is crucial. However, defense mechanisms do not work with simple installation; there are necessary configuration settings, fine tunings and manual or automatic rule creation that must be done to establish more robust and secure systems. This can be done by adversarial assessment on the systems to see the potential weaknesses. Traditional approaches to test web applications against SQL injection (SQLi) attacks rely on two main methodologies: manual penetration testing performed by real security experts and automated scanning via mainstream rule-based SQLi automation tools such as SQLmap [2]. While these methods have proven success revealing SQLi vulnerabilities, they face significant limitations against modern AI/ML based and commercial WAFs. Manual testing is time consuming, expensive and the success totally depends on the expertise of the security tester. Automated rule-based testing is not able to generate novel SQLi attacks to bypass next generation systems and they can be easily recognized by signature based defense systems. In addition to these, both approaches do not perform coverage tests for different variants of the SQLi attacks. The purpose of adversarial testing against defense systems is increasing the defense bar proactively even before an incident happens. The recent studies in Large Language Models (LLMs) have sparked significant interest in implementation of these approaches to security testing. Models such as GPT-4o [3], Claude Sonnet [4], and DeepSeek [5] demonstrated advanced capabilities of understanding and generating code-like structures including SQL syntax. Their ability of understanding syntax and making advanced reasoning positions them as a promising tool for generating adversarial SQL injection payloads. However, the existing work on adversarial testing with LLMs has several challenges: single-model focus, limited parameter exploration, insufficient diversity and feedback mechanisms. Single-Model Focus: Previous researches mainly evaluate the capability of a single LLM, that limits understanding the behavior of cross model setups and optimal parameter configurations. This prevents understanding the nature of LLM based adversarial SQLi generation comprehensively. Limited Parameter Exploration: Existing studies demonstrate the performance of adversarial generations under fixed or minimally varied hyperparameter settings. This prevents exploring model specific optimal parameter settings and understanding of their effectiveness. Insufficient Diversity and Feedback Mechanisms: Current LLM based approaches generally do not put diversity enforcements that result in repetitive SQLi
2
payloads and limit the attack coverage [6]. This makes the SQLi generator easily detectable by advanced defense systems [7]. To address these challenges and to analyze adversarial SQLi generation with LLMs, we introduce two novel architectures and a comprehensive benchmarking study against modern WAF defenses. Our contributions can be listed as follows: 1. Comprehensive Benchmarking Framework: We present a systematic evaluation framework to compare LLM SQLi generator models against ten comprehensive WAFs: AI/ML-based (WAF-Brain, CNN-WAF), rule based open source (ModSecurity PL1-3, Coraza PL1-3), commercial (Cloudflare, AWS WAF), and MySQL execution validation. We created 240 different experiment cases then generated 240,000 SQLi payloads and performed 2.2 million tests against ten WAFs and one execution test that provides an extensive benchmarking on LLM based adversarial SQLi generation. 2. Retrieval-Augmented Generation for Adversarial SQLi (RADAGAS): We introduce RADAGAS architecture that utilizes Retrieval Augmented Generation (RAG) and LLM generation with multi stage diversity and execution filtering. RADAGAS collects and retrieves proven successful attack patterns from curated knowledgebase (OWASP, Portswigger, Github) and generates adversarial SQLi payloads via RAG prompting. We experimented RADAGAS with different foundation models (GPT-4o, Claude 3.7 Sonnet and Deepseek-r1) to demonstrate its cross-model performance. 3. Reflective Chain-of-Thought SQLi (RefleXQLi): Our second proposed method is RefleXQLi that employs four step chain of thought reasoning (WAF Analysis, Strategy Formulation, Payload Design, Refinement) to generate high quality adversarial SQLi payloads followed by dual-LLM validation. The architecture consists of two modules: generator LLM creates SQLi payloads and discriminator LLM refines them iteratively that resulted in generation of payloads with 100% uniqueness. 4. The experiments demonstrated that RADAGAS variations (22.73%, 22.09%, 21.73%) and RefleXQLi (21.21%) outperformed existing traditional methods (15.01%), vanilla zero-shot LLM generator (12.90%) and GenSQLi (20.35%) [8] in terms of average WAF bypass rate, showing that both proposed methods are superior to the traditional approaches. 5. The experiments demonstrated that the temperature settings are model specific and counter intuitive [9]. While GPT-4o performed better in lower temperature (T=0.1, 22.73%), Deepseek-r1 performed better in high temperature (T=0.9, 22.09%) with more creativity and Claude 3.7 Sonnet has the optimal performance in medium temperature (T=0.6, 21.73%). This demonstrates LLMs have different characteristics under different temperature conditions in terms of exploitation versus exploration in adversarial generation. 6. MySQL Validation as Ground Truth: As an additional validation layer, we introduced a vulnerable web application backed by a MySQL server to validate the generated SQL injection payloads. The experiment results show that RADAGAS systems achieve 60-64% execution success, while the baseline systems stay at 2137% execution success against MySQL validation.
3
7. WAF Performance Characterization: We demonstrated system specific performance across all 10 WAFs and one MySQL validation layer. RADAGAS-DeepSeek performed high bypass rates on ML based WAFs with 92.49% on WAF-Brain, 78.39% on CNN-WAF, GenSQLi achieved the highest rule-based WAF bypass with 16.26% on ModSecurity PL1, and RADAGAS-GPT4o achieved the highest bypass rate on Cloudflare with 49.50%. This heterogeneous result set shows that there is no single system that outperforms universally, and the practical implementations should combine multiple approaches together. 8. RefleXQLi Chain of Thought Evaluation: We introduced RefleXQLi which is one of the first implementations of Chain of Thought reasoning combined with dual-LLM architecture for adversarial attack generation. RefleXQLi demonstrated 21.21% bypass rate with low variance σ = 0.37, that shows explicit reasoning provides more stable output for adversarial payload generation. However, 27.80% MySQL execution success is lower than RADAGAS’s 60-64% revealing a tradeoff between creative adversarial generation and semantic correctness of the generated outputs.
2 Related Work We organized related work section into three categories: Traditional SQLi generation, LLM based security testing, and diversity in adversarial generation.
2.1 Traditional SQL Injection Generation SQLi vulnerability is known for decades and SQLi testing tools and approaches are quite comprehensive and contain decades of expert knowledge embedded into rule based attack patterns. SQLMap [2] is one of the industry standard popular tools and extensively used in penetration testing to cover SQLi scenarios since 2006. The tool consists of thousands of hand crafted SQL injection payloads in its database, covering union based, error based, time based blind, boolean based blind and stacked queries across multiple database platforms like MySQL, PostgreSQL, Oracle and MSSQL. SQLMap utilizes automated parameter detection, DBMS fingerprinting and enumeration strategies to achieve comprehensive coverage. Surveys [10, 11] state the evolution of attack types and their countermeasures of traditional SQLi frameworks over the past two decades. Although traditional tools have extensive coverage in testing SQLi vulnerabilities, there are several limitations against modern defense systems. Since the tools generate deterministic payloads, those patterns can be captured easily by signature based WAFs [12]. ML based detection systems are quite effective on template based approaches since these approaches have weakness on contextual adaptation [13, 14] and ML based WAFs can learn the attack characteristics easily. In [12], Appelt et al. show that the commercial WAFs are significantly effective on detecting SQLMap generated attack payloads with 94% prevention rate. Even sophisticated manual tests are ineffective against multi layer defense in depth systems.
4
2.2 LLM-Based Security Testing SQLiGPT was one of the first uses of LLMs for adversarial security testing [15]. The tool examines the capability of GPT model when it generates and detects SQLi payloads with prompt engineering but in a limited scale. In [16], Yang et al. developed a system named LLMSqli to detect SQLi attacks using generalization capabilities of LLMs. Fang et al. introduced an agent based LLM architecture to learn exploiting web vulnerabilities via adaptive feedback loops [17]. In another approach, Deng et al. designed pentestGPT to perform automated penetration testing [18]. In [19], Liu et al. introduced a mechanism to detect adversarial prompt injection techniques against LLM based systems. Babaey and Ravindran introduced a comprehensive framework named GenSQLi to generate adversarial SQLi attacks and generate corresponding WAF rule to create defense for these payloads [8]. GenSQLi employs GPT-4o [3] with in context learning. They also evaluated Google Gemini Pro which performed lower bypass rate than GPT-4o, highlighting performance variance due to LLM dependency. In [20, 21], the authors worked on temperature scaling LLMs extensively. According to the experiments, the higher temperatures increase the diversity, but affect the coherence negatively. Top-k and top-p sampling provide alternative sampling methodology [20]. In [22, 23], the authors study on the effects of temperature on trade off in between functionality and creativity. The results show that the optimal parameter settings strongly depend on the model and task and need empirical evaluation for each domain.
2.3 Diversity in Adversarial Payload Generation Correlation of the diversity with successful adversarial attack generation is one of the assumptions of prior work. GenSQLi assumes payload variation increases the successful attack probability with genetic diversity through template mutation [8]. Effective defense rules are produced by grouping similar attack payloads via ML clustering approaches. They are aiming a comprehensive coverage by utilizing the diversity as a proxy. SQIRL [24] uses reinforcement learning [25] to optimize grey-box detection of SQLi vulnerabilities by exploring new payloads through diversity. If there are repeating payload patterns, the reward function penalizes them to achieve improvement in evasion by uniqueness. SQUIRREL [26] is an implementation of a fuzzing with mutation operators to achieve diverse query generation. The study utilizes a fuzzing principle [27, 28] to explore new and unknown payloads to search more edge cases. To achieve this, the study uses coverage guided fuzzing [29] and diversity metrics to optimize the exploration of new payloads. In information retrieval process, Maximum Marginal Relevance (MMR) [30] plays critical role to balance the diversity and relevance of information. While this mechanism selects items relevant with the query, it also considers how it is diverse from already selected items: MMR is used in retrieval and summarization extensively, and it has not been evaluated for adversarial attack testing extensively and systematically in the previous works.
5
Although there are studies that employ diversity to achieve more successful payload generation, diversity and WAF bypass correlation has still not been tested empirically and holistically. Our study provides extensive experiments and analysis on real world systems to show this correlation.
2.4 Positioning of This Work With the aim of establishing more robust and secure systems via adversarial assessment to see the potential weaknesses, our study is designed to cover holistic real world scenarios by employing seven SQLi generators (three base-line, and four our proposal) and test them against 10 WAFs (including commercial and AI/ML based WAFs) with validity check via real vulnerable web application backed by a MySQL server under identical conditions, providing: 1. Multi Metric Diversity Analysis: Seven complementary diversity metrics (uniqueness, semantic, lexical, contextual, n-gram, Abstract Syntax Tree (AST), and functional diversity) evaluated against generated SQL injection payloads across all generators. 2. Comprehensive System Comparison: Traditional SQL injection tools (SqlMap), recent studies GenSQLi, Vanilla GPT-4o (zero-shot), and our novel algorithms; three RADAGAS variants (GPT-4o, DeepSeek, Claude) and RefleXQLi (CoT+Adversarial). 3. Real World Scenarios: Two commercial WAFs, six Rule Based WAFs and two AI/ML based WAFs to test generated payloads against wide range of real world scenarios. 4. Model Specific Optimization Characteristics: Tuning LLM Parameters and diversity threshold to find optimal settings for generating successful SQL Injection payload.
3 Methodology This section provides detailed information on our experimental methodology, system designs, algorithms, diversity check pipeline, metrics, and WAF settings.
3.1 System Architecture The overall system is illustrated in Fig. 1. Our testbed consists of seven generators, ten WAFs, one SQL execution validator and six diversity filters. As a result of our tests, 240K payloads were generated and approximately 200K valid payloads were tested against 10 WAFs and one execution checker. In total we performed approximately 2.2M tests.
3.2 SQL Injection Generation Systems Our testbed consists of seven SQL injection generation systems including the existing studies and our novel systems to provide comprehensive comparison for LLM based SQL Injection generation techniques.
6