When Prompts Become Payloads: A Framework for Mitigating SQL Injection Attacks in Large Language Model-Driven Applications
作者: Farzad Nourmohammadzadeh Motlagh, Mehrdad Hajizadeh, Mehryar Majd, Pejman Najafi, Feng Cheng, Christoph Meinel
分类: cs.CR, cs.AI
发布日期: 2026-05-11
备注: 11 pages
期刊: ICAART 2026, 18th Int. Conf. on Agents and Artificial Intelligence, pp. 1380-1390, 2026
💡 一句话要点
提出一种多层安全框架,通过提示词清洗与语义异常检测防御LLM驱动的SQL注入攻击
🎯 匹配领域: 支柱一:机器人控制 (Robot Control) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大语言模型 SQL注入 提示词工程 语义异常检测 网络安全 Text-to-SQL 防御纵深
📋 核心要点
- 核心问题:LLM将自然语言转换为SQL查询的过程中,极易受到恶意提示词诱导,导致生成非法SQL语句,造成数据库泄露或破坏。
- 方法要点:构建包含前端清洗、语义异常检测及签名匹配的多层防御体系,从输入预处理到查询执行全链路拦截恶意攻击。
- 实验效果:在多种对抗性场景下验证了框架的有效性,在保持低误报率的前提下,显著提升了对复杂SQL注入攻击的检测能力。
📝 摘要(中文)
随着大语言模型(LLM)的发展,自然语言接口已成为访问结构化数据库的主流方式,但这同时也引入了新的安全风险,特别是通过提示词到SQL转换过程引发的SQL注入漏洞。恶意用户可通过精心设计的对抗性提示词操纵模型行为,生成不安全的数据库查询。本文提出了一种多层安全框架,旨在检测并缓解LLM介导的SQL注入攻击。该框架集成了用于提示词清洗的前端安全防护、用于行为与语义异常识别的高级威胁检测模型,以及针对已知攻击模式的基于签名的控制层。通过在包含提示词注入、混淆SQL载荷及上下文操纵等多种现实攻击场景下的评估,并结合自建的对抗性提示词基准数据集,实验结果表明,该方法在保持低误报率的同时实现了高检测准确率,显著提升了LLM驱动数据库应用的安全性。
🔬 方法详解
问题定义:论文旨在解决LLM在自然语言转SQL(Text-to-SQL)任务中面临的“提示词即载荷”安全威胁。现有方法往往缺乏对用户输入意图的深层语义分析,难以防御复杂的混淆攻击和上下文操纵。
核心思路:采用“防御纵深”策略,不依赖单一检测手段,而是通过多层过滤机制,从输入端(提示词)到执行端(SQL语句)进行全方位校验,确保只有合法的查询请求能触达数据库。
技术框架:框架由三个核心模块组成:前端安全盾(Front-end Security Shield)负责输入清洗与标准化;高级威胁检测模型(Advanced Threat Detection Model)利用语义分析识别异常行为;签名控制层(Signature-based Control Layer)则用于快速拦截已知攻击模式。
关键创新:创新点在于将语义异常检测与传统签名过滤相结合,不仅能识别已知的SQL注入模式,还能通过分析提示词的语义特征,捕捉针对LLM逻辑的对抗性操纵行为。
关键设计:系统引入了专门针对LLM配置的微调策略,通过构建包含多种攻击类型的基准数据集,优化了模型对恶意提示词的敏感度,同时通过阈值控制平衡了检测精度与误报率。
📊 实验亮点
实验通过构建包含提示词注入、混淆载荷及上下文操纵的综合基准数据集,全面评估了框架性能。结果显示,该多层防御体系在处理复杂对抗性提示词时,表现出极高的检测准确率,同时将误报率控制在极低水平,证明了其在实际生产环境中的鲁棒性与实用价值。
🎯 应用场景
该研究适用于所有集成LLM作为数据库交互接口的系统,如企业级智能数据分析平台、自动化报表生成工具及各类AI驱动的业务管理系统。其价值在于为企业提供了一套可落地的安全防御基准,有效降低了因LLM应用部署带来的数据泄露风险,推动了生成式AI在金融、医疗等高敏感数据领域的安全应用。
📄 摘要(原文)
Natural language interfaces to structured databases are becoming increasingly common, largely due to advances in large language models (LLMs) that enable users to query data using conversational input rather than formal query languages such as SQL. While this paradigm significantly improves usability and accessibility, it introduces new security risks, particularly the amplification of SQL injection vulnerabilities through the prompt-to-SQL translation process. Malicious users can exploit these mechanisms by crafting adversarial prompts that manipulate model behavior and generate unsafe queries. In this work, we propose a multi-layered security framework designed to detect and mitigate LLM-mediated SQL injection attacks. The framework integrates a front-end security shield for prompt sanitization, an advanced threat detection model for behavioral and semantic anomaly identification, and a signature-based control layer for known attack patterns. We evaluate the proposed framework under diverse and realistic attack scenarios, including prompt injection, obfuscated SQL payloads, and context-manipulation attacks. To ensure robustness, we generate and curate a comprehensive benchmark dataset of adversarial prompts and assess performance across a fine-tuned LLM configuration. Experimental results demonstrate that the proposed approach achieves high detection accuracy while maintaining low false-positive rates, significantly improving the secure deployment of LLM-powered database applications.