当前位置: 首页 > news >正文

DVWA-CSRF-samesite分析

拿DVWA的CSRF为例子
接DVWA的分析,发现其实Impossible的PHPSESSID是设置的samesite=1.
参数的意思参考Set-Cookie

SameSite:控制 cookie 是否随跨站请求一起发送,这样可以在一定程度上防范跨站请求伪造攻击(CSRF)。
下面用DVWA CSRF Low Level来分析下samsite的设置。

DVWA CSRF

Cookie一共包含security和PHPSESSID,这里讲下PHPSESSID(session的cookie)。
在dvwaPage.inc.php中,dvwa_start_session()函数先通过dvwaSecurityLevelGet()函数获得security_level。
之后如果security_level为impossible,则samesite设置为Strict。否则为None(跨站携带cookie)。不同设置的详细解释在Cookie 的 SameSite 属性
最后通过session_set_cookie_params设置session 的cookie。

function dvwa_start_session() {// This will setup the session cookie based on// the security level.$security_level = dvwaSecurityLevelGet();if ($security_level == 'impossible') {$httponly = true;$samesite = "Strict";}else {$httponly = false;$samesite = "";}$maxlifetime = 86400;$secure = false;$domain = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);/** Need to do this as you can't update the settings of a session* while it is open. So check if one is open, close it if needed* then update the values and start it again.*/if (session_id()) {session_write_close();}session_set_cookie_params(['lifetime' => $maxlifetime,'path' => '/','domain' => $domain,'secure' => $secure,'httponly' => $httponly,'samesite' => $samesite]);session_start();// This is the call that will force a new Set-Cookie header with the right flagssession_regenerate_id();
}
function dvwaSecurityLevelGet() {global $_DVWA;// If there is a security cookie, that takes priority.if (isset($_COOKIE['security'])) {return $_COOKIE[ 'security' ];}// If not, check to see if authentication is disabled, if it is, use// the default security level.if (in_array("disable_authentication", $_DVWA) && $_DVWA['disable_authentication']) {return $_DVWA[ 'default_security_level' ];}// Worse case, set the level to impossible.return 'impossible';
}

与之前在DVWA SCRF的利用不同,因为samesite是跨站设置。所以先用burp抓个包,生成csrf的html,放在kali中。
kali中用python开启简单http服务,在用浏览器去请求kali网站的html,模拟跨站攻击。

<html><!-- CSRF PoC - generated by Burp Suite Professional --><body><form action="http://192.168.20.156/DVWA/vulnerabilities/csrf/"><input type="hidden" name="password&#95;new" value="123" /><input type="hidden" name="password&#95;conf" value="123" /><input type="hidden" name="Change" value="Change" /><input type="submit" value="Submit request" /></form><script>history.pushState('', '', '/');document.forms[0].submit();</script></body>
</html>

现在这个源码,可以在CSRF Low Level界面,产生漏洞,修改密码。
此时浏览器Cookie中PHPSESSID的samestie为None。
在这里插入图片描述
之后将红框位置改为Lax
在这里插入图片描述
看下Lax的解释,我们的表单是Get方式提交的,所以设置了Lax,应该还是可以实现CSRF攻击的
在这里插入图片描述
验证CSRF漏洞,发现PHPSESSID的samesite为Lax,并且漏洞还是存在的。
在这里插入图片描述
最后我们把samesite设置为Strict,再次进行验证,发现无法修改密码。
在这里插入图片描述
用burp抓包分析发现,请求修改密码包Cookie中并没有PHPSESSID
在这里插入图片描述
PHPSESSID中samesite设置为Strict。
在这里插入图片描述

http://www.lryc.cn/news/382289.html

相关文章:

  • 代码随想录训练营Day48
  • React进阶(五):导航守卫_renderroutes
  • Python基础系列教程:从零开始学习Python
  • deepl翻译的PDF文档保护密码解除
  • LeetCode 算法:二叉树的直径 c++
  • 盘立方期货Kdj幅图指标公式源码
  • SkyWalking 极简入门
  • 本篇内容:ArkTS开发系列之事件(2.8.1触屏、键鼠、焦点事件)
  • 测试的基础知识大全【测试概念、分类、模型、流程、测试用例书写、用例设计、Bug、基础功能测试实战】
  • Power Apps
  • qt图像处理-将OpenCV的cv::Mat类型转换为QImage类型
  • 代码随想录训练营第十八天 530二叉搜索树的最小绝对差 501二叉搜索树中的众数 236二叉树的最近公共祖先
  • 微信小程序之横向列表展示
  • 无人机巡检小羊仿真
  • springboot redission 分布式锁
  • Vuex中的重要核心属性
  • Redis哨兵集群搭建
  • 网络爬虫requests库使用指南
  • VSCODE 配置C++ 与OPENCV
  • C语言小例程28/100
  • WPF文本绑定显示格式StringFormat设置-特殊格式时间日期和多数据绑定
  • Java包介绍
  • 【2024.6.21】今日科技时事:科技前沿大事件
  • LeetCode:经典题之1491、896 题解与延伸
  • 2024三掌柜赠书活动第二十五期:Rust 游戏开发实战
  • 基于Java蛋糕甜品商城系统设计和实现(源码+LW+调试文档+讲解等)
  • Tomcat get请求传数组集合参数
  • 信息学奥赛初赛天天练-34-CSP-J2021完善程序-按位异或、模拟算法、数组模拟环、约瑟夫问题应用
  • 【计算机视觉】人脸算法之图像处理基础知识(六)
  • 仓颉编程语言入门