欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Web網(wǎng)絡(luò)安全分析二次注入攻擊原理詳解

 更新時(shí)間:2021年11月02日 15:49:01   作者:Phanton03167  
這篇文章主要為大家講解介紹了Web網(wǎng)絡(luò)安全分析二次注入攻擊原理的詳解,有需要相關(guān)學(xué)習(xí)的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步

二次注入攻擊

二次注入攻擊的測試地址:http://127.0.0.1/sqli/double1.php?username=test 和 http://127.0.0.1/sqli/double2.php?id=1。 其中,double1.php頁面的功能是注冊用戶名,也是插入SQL語句的地方;double2.php頁面的功能是通過參數(shù)ID讀取用戶名和用戶信息。

第一步,訪問double1.php?username=test',如圖40所示。

 

圖40 注冊用戶名test'

從頁面返回結(jié)果可以看到用戶名test'對用的ID為9,訪問double2.PHP?id=9,結(jié)果如圖41所示。

 

圖40 訪問test'的信息

從返回結(jié)果可以看到服務(wù)端返回了MySQL的錯誤(多了一個單引號引起的語法錯誤),這時(shí)回到第一步,先訪問double1.php?username=test' order by 1--+,獲取一個新的id=10,當(dāng)再次訪問double2.php?id=10時(shí),頁面返回空白;再次嘗試,訪問double1.php?username=test' order by 10--+,獲取一個新的id=11,當(dāng)再次訪問double2.php?id=11時(shí),頁面返回錯誤信息(Unknown column ‘10' in ‘order clause'),如圖42所示。

 

圖42 訪問order by 10的結(jié)果

這說明空白頁面就是正常返回,通過不斷地嘗試,筆者判斷出數(shù)據(jù)庫中一共有3個字段。

訪問double1.php?username=test' union select 1,2,3--+,獲取一個新id=12,再訪問double2.php?id=12,發(fā)現(xiàn)頁面返回了union select中的1和2字段,結(jié)果如圖43所示。

 

圖43 使用Union語句的結(jié)果

在2或3的位置,插入我們的語句,比如訪問double1.php?username=test' union select 1,user(),3--+,獲得新的id=13,再訪問double2.php?id=13,得到user()的結(jié)果,如圖44所示,使用此方法就可以獲取數(shù)據(jù)庫中的數(shù)據(jù)。

 

圖44 利用二次注入獲取數(shù)據(jù)

二次注入代碼分析

二次注入中double1.php頁面的代碼如下所示,實(shí)現(xiàn)了簡單的用戶注冊功能,程序獲取到GET參數(shù)username的參數(shù)password,然后將username和password拼接到SQL語句,使用insert語句插入到數(shù)據(jù)庫中。由于參數(shù)username使用addslashes進(jìn)行轉(zhuǎn)義(轉(zhuǎn)義了單引號,導(dǎo)致單引號無法閉合),參數(shù)password進(jìn)行了MD5哈希,所以此處不存在SQL注入漏洞。

<?php header('Content-type:text/html;charset=utf-8');
$con=mysqli_connect("localhost","root","root","test");
if (mysqli_connect_errno())
{
    echo "連接失敗: " . mysqli_connect_error();
}
$username = @$_GET['username'];
$password = @$_GET['password'];
$result = mysqli_query($con,"insert into users(`username`,`password`) values ('".addslashes($username)."','".md5($password)."')");
echo "新的id為:".mysqli_insert_id($con);
?>

當(dāng)訪問username=test'&password=123456時(shí),執(zhí)行的SQL語句為:

insert into users(`username`,`password`) values ('test\'','e10adc3949ba59abbe56e057f20f883e')

從圖45中的數(shù)據(jù)庫里可以看到,插入的用戶是test'。

 

圖45 插入到數(shù)據(jù)庫中的數(shù)據(jù)

在二次注入中double2.php中的代碼如下所示。首先將GET參數(shù)ID轉(zhuǎn)換成int類型(防止拼接到SQL語句時(shí),存在SQL注入漏洞),然后到users表中獲取ID對應(yīng)的username,接著到person表中查詢username對應(yīng)的數(shù)據(jù)。

<?php header('Content-type:text/html;charset=utf-8');
$con=mysqli_connect("localhost","root","root","test");
if (mysqli_connect_errno())
{
    echo "連接失敗: " . mysqli_connect_error();
}
$id = intval(@$_GET['id']);

$result = mysqli_query($con,"select * from users where `id`=".$id);
$row = mysqli_fetch_array($result);

$username = $row['username'];
$result2 = mysqli_query($con,"select * from person where `username`='".$username."'");
if (!$result2)
{
    echo mysqli_error($con);
    exit();
}
if($row2 = mysqli_fetch_array($result2))
{
    echo $row2['username'] . " : " . $row2['money'];

}
else
{
    echo mysqli_error($con);
}
?>

但是此處沒有對$username進(jìn)行轉(zhuǎn)義,在第一步中我們注冊的用戶名是test',此時(shí)執(zhí)行的SQL語句為:

select * from users where `username`='test''

單引號被帶入SQL語句中,由于多了一個單引號,所以頁面會報(bào)錯。

以上就是Web網(wǎng)絡(luò)安全分析二次注入攻擊原理詳解的詳細(xì)內(nèi)容,更多關(guān)于Web網(wǎng)絡(luò)安全二次注入攻擊的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論