首页 > 实用技巧 > 网络安全

Web网络安全解析cookie注入攻击原理

发布时间:2021-11-25 16:32 作者:Phanton03167

cookie注入攻击

cookie注入攻击的测试地址:http://127.0.0.1/sqli/cookie.php。

发现URL中没有GET参数,但是页面返回正常,使用Burp Suite抓取数据包,发现cookie中存在id=1的参数,如图56所示。

 

图56 cookie数据

修改cookie中的id=1为id=1',然后再次访问该URL,发现页面返回错误。接下来,分别修改cookie中id=1 and 1=1和id=1 and 1=2,再次访问,判断该页面是否存在SQL漏洞,返回结果如图57和图58所示,得出cookie中的参数ID存在SQL注入的结论。

 

图57 访问id=1 and 1=1的结果

 

图58 访问id=1 and 1=2的结果

接着使用order by查询字段,使用Union注入方法完成此次注入。

cookie注入代码分析

通过$_COOKIE能获取浏览器cookie中的数据,在cookie注入页面中程序通过$_COOKIE获取参数ID,然后直接将ID拼接到select语句中进行查询,如果没有结果,则将结果输出到页面,代码如下所示。

<?php
$id = $_COOKIE['id'];
$value = '1';
setcookie("id","$value");
$con = mysqli_connect("localhost","root","root","test");
if(mysqli_connect_error())
{
    echo "连接失败" . mysqli_error($con) ;
}
$result = mysqli_query($con,"select * from users where id=$id ");
if(!$result)
{
    printf("Error: %s\n", mysqli_error($con));
    exit();
}
$row = mysqli_fetch_array($result);
echo $row{'username'} ." : ". $row{'password'};
echo "<br>";
?>

这里可以看到,由于没有过滤coookie中的参数ID且直接拼接到SQL语句中,所以存在SQL注入漏洞。当在cookie中添加id=1 union select 1,2,3–+时执行的SQL语句为:

select * from users where `id`=1 union select 1,2,3--+

此时,SQL语句可以分为select * from users where `id`=1和union select 1,2,3两条,利用第二条语句(Union查询)就可以获取数据库中的数据。

以上就是Web网络安全解析cookie注入攻击原理的详细内容,更多关于Web网络安全cookie注入攻击的资料请关注猪先飞其它相关文章!

原文出处:https://blog.csdn.net/qq_25505167/article/details/120505170

标签:[!--infotagslink--]

您可能感兴趣的文章: