DVWA-XSS(Stored)-httponly分析

2 篇文章 0 订阅

拿DVWA的XSS为例子
httponly是微软对cookie做的扩展。这个主要是解决用户的cookie可能被盗用的问题。
接DVWA的分析,发现其实Impossible的cookie都是设置的httponly=1,samesite=1.
这两个参数的意思参考Set-Cookie

HttpOnly:阻止 JavaScript 通过 Document.cookie 属性访问 cookie。
SameSite:控制 cookie 是否随跨站请求一起发送,这样可以在一定程度上防范跨站请求伪造攻击(CSRF)。

设置

  1. PHP5.2以上版本已支持HttpOnly参数的设置,同样也支持全局的HttpOnly的设置,在php.ini中
 session.cookie_httponly = 

设置其值为1或者TRUE,来开启全局的Cookie的HttpOnly属性。
2. setcookie函数和setrawcookie函数添加了第7个参数来做为HttpOnly的选项,开启方法为:

 setcookie("abc", "test", NULL, NULL, NULL, NULL, TRUE); 
 setrawcookie("abc", "test", NULL, NULL, NULL, NULL, TRUE);

DVWA XSS(Stored)

开始我在服务器的php.ini中设置了session.cookie_httponly = true之后发现Cookie的httponly还是false。
后来发现,源代码中作者设置了http-only。
Cookie一共包含security和PHPSESSID,这里讲下PHPSESSID(session的cookie)。
在dvwaPage.inc.php中,dvwa_start_session()函数先通过dvwaSecurityLevelGet()函数获得security_level。
之后如果security_level为impossible,则httponly设置为true。否则为false。
最后通过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 flags
	session_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';
}

现在这个源码,可以在XSS(Stored) Low Level界面,产生漏洞,拿到cookie。
此时浏览器Cookie中PHPSESSID的http-only为false。
在这里插入图片描述
之后我们将红框位置改为true,也就是所有level下session 的cookie httponly都设置为true。
修改之后再进行漏洞测试,发现只能拿到security的cookie,同时PHPSESSID的httponly为true。
在这里插入图片描述

  • 22
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值