当前位置:网站首页>跨站点请求伪造(CSRF)
跨站点请求伪造(CSRF)
2022-07-26 16:52:00 【悠然予夏】
CSRF攻击的全称是跨站请求伪造( cross site request forgery ):是一种对网站的恶意利用,尽管听起来跟XSS跨站脚本攻击有点相似,但事实上CSRF与XSS差别很大,XSS利用的是站点内的信任用户,而CSRF则是通过伪装来自受信任用户的请求来利用受信任的网站。

简单理解:一种可以被攻击者用来通过用户浏览器冒充用户身份向服务器发送伪造请求并被目标服务器成功执行的漏洞被称之为CSRF漏洞。
特点:
- 用户浏览器:表示的受信任的用户
- 冒充身份:恶意程序冒充受信任用户(浏览器)身份
- 伪造请求:借助于受信任用户浏览器发起的访问
1、CSRF攻击原理
CSRF攻击攻击原理及过程如下:
1. 用户打开浏览器,访问受信任网站A,输入用户名和密码请求登录网站A;
2. 用户信息通过验证后,网站A产生Cookie信息并返回给浏览器,此时用户登录网站A成功,可以正常发送请求到网站A;
3. 用户未退出网站A之前,在同一浏览器中,打开一个TAB页访问网站B;
4. 网站B接收到用户请求后,返回一些攻击性代码,并发出一个请求要求访问第三方站点A;
5. 浏览器在接收到这些攻击性代码后,根据网站B的请求,在用户不知情的情况下携带Cookie信息,向网站A发出请求。网站A并不知道该请求其实是由B发起的,所以会根据用户C的Cookie信息以C的权限处理该请求,导致来自网站B的恶意代码被执行。

2、CSRF漏洞成因分析
get请求:
<img src="http://www.study.com/admin/resetPassword?id=1" />
<iframe src="http://www.study.com/admin/resetPassword?id=1"style='display:none'></iframe>post请求:
<!--隐藏表单、自动提交,把功能通过iframe引入新页面-->
<iframe src="form.html" style='display:none'></iframe>3、CSRF漏洞危害分析
CSRF攻击特点:
- 攻击时机:网站的cookie在浏览器中没有过期,不关闭浏览器或者退出登录
- 攻击前提:对目标网站接口有一定了解
- 攻击难度:攻击难度高于XSS
- 与XSS攻击相比,CSRF攻击往往不大流行(因此对其进行防范的资源也相当稀少)和难以防范,所以被认为比XSS更具危险性。
危害:

4、CSRF安全防护
- 区分是否为伪造请求
- 二次验证
referer校验:
HTTP Referer是header的一部分,当浏览器向web服务器发送请求的时候,一般会带上Referer,告诉服务器该网页是从哪个页面链接过来的,服务器因此可以获得一些信息用于处理。
- 在网关过滤器中校验
- 在对应的微服务中定义拦截器
- 具体的业务代码中实现
例外情况:登录

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
Exception {
logger.debug("拦截器拦截到对:{}的访问", request.getRequestURI());
String referer = request.getHeader("referer");
logger.debug("referer:{}", referer);
StringBuilder sb = new StringBuilder();
sb.append(request.getScheme()).append("://").append(request.getServerName());
logger.debug("basePath:{}", sb.toString());
if (referer == null || referer == "" || !referer.startsWith(sb.toString())) {
response.setContentType("text/plain; charset=utf-8");
response.getWriter().write("非法访问,请通过页面正常问!");
return false;
}
return true;
}业务二次校验:
- 修改密码,需输入原密码
- 交易系统设置交易密码
- 增加图形验证码校验
- 网银转账短信验证码
5、CSRFTester
CSRFTester是一款CSRF漏洞的测试工具,此工具的测试原理如下:它使用代理抓取浏览器中访问过的连接以及表单等信息,通过在CSRFTester中修改相应的表单等信息,重新提交,相当于一次伪造客户端请求,如果被测试的请求成功被网站服务器接受,则说明存在CSRF漏洞,否则不存在。此款工具也可以被用来进行CSRF攻击。



手动访问浏览器后,会在CSRF tester中记录访问路径,从而生成CSRF攻击html

边栏推荐
- Just this time! Talk about the technical solutions of distributed system in detail
- Oracle is slow to perform a large number of DML operations. Is it the problem of CPU or hard disk?
- Pass-19,20
- Concepts and differences of DQL, DML, DDL and DCL
- VIM visualization mode and its usage
- #夏日挑战赛# OpenHarmony基于JS实现的贪吃蛇
- Common super easy to use regular expressions!
- 使用 replace-regexp 在行首添加序号
- We were tossed all night by a Kong performance bug
- GAN (Generative Adversarial Network,GAN)生成式对抗网络
猜你喜欢

CCS tm4c123 new project

Execution process of select statement in MySQL

Summer Challenge openharmony greedy snake based on JS

What kind of product is the Jetson nano? (how about the performance of Jetson nano)

Pass-19,20

6-19漏洞利用-nsf获取目标密码文件

GAN (Generative Adversarial Network,GAN)生成式对抗网络

6-19 vulnerability exploitation -nsf to obtain the target password file

The user experience center of Analysys Qianfan bank was established to help upgrade the user experience of the banking industry

Tree DP problem
随机推荐
2022 年有哪些流行的技术?
Redis persistence - detailed analysis of RDB source code | nanny level analysis! The most complete network
PIP installation module, error
云渲染-体积云【理论基础与实现方案】
Common super easy to use regular expressions!
Just this time! Talk about the technical solutions of distributed system in detail
环境搭建-MongoDB
[300 opencv routines] 240. Shi Tomas corner detection in opencv
ASEMI整流桥KBPC3510,KBPC3510封装,KBPC3510应用
Leetcode:1206. design jump table [jump table board]
Come on developer! Not only for the 200000 bonus, try the best "building blocks" for a brainstorming
浅谈数据技术人员的成长之路
MySQL foundation - basic database operation
常用超好用正则表达式!
In the first half of the year, sales increased by 10% against the trend. You can always trust Volvo, which is persistent and safe
硬件开发与市场产业
(25)Blender源码分析之顶层菜单Blender菜单
How to use different tools to analyze and optimize code performance when CPU utilization is high
机器学习-什么是机器学习、监督学习和无监督学习
Implementing dropout with mxnet from zero sum