DVWA
XSS(DOM) 基于DOM型的XSS
一、Low 级别
没有任何的安全保护措施
下拉框选择语言提交后,在url栏中的default参数直接显示:
构造XSS代码,修改参数,成功执行脚本:
?default=<script>alert('/xss/')</script>
查看网页源代码,脚本插入到代码中,所以执行了:
源代码:
<?php
# No protections, anything goes
?>
二、Medium 级别
检查 default 参数是否为空并且过滤了 <script (不区分大小写)
源代码:
<?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;
}
}
?>
先检查了default参数是否为空,如果不为空则将default等于获取到的default值;然后使用了 stripos 检测default值中是否有 <script ,如果有的话,则将default=English,这里过滤了 <script (不区分大小写)。
漏洞利用
由于过滤了 <script ,这里我们传入参数 <img src='#' onerror='alert(/xss/)'>
构造xss:
查看网页源代码,发现我们的语句被插入到了value值中,但是并没有插入到option标签的值中,所以img标签并没有发起任何作用。
所以我们得先闭合前面的标签,构造语句闭合option标签:
先查看js代码,有关option标签的:
构造语句:
</option><img src='#' onerror='alert(/xss/)'>
结果还是没有插入。。
干脆直接再闭合select标签,让img标签成为独立的一条语句:
</option></select><img src='#' onerror='alert(/xss/)'>
三、High 级别
添加了白名单只允许传的 default 值为:French、English、German、Spanish 其中一个
源代码:
<?php
// Is there any input?
if ( array_key_exists( "default", $_GET ) && !is_null ($_GET[ 'default' ]) ) {
# 白名单
switch ($_GET['default']) {
case "French":
case "English":
case "German":
case "Spanish":
# ok
break;
default:
header ("location: ?default=English");
exit;
}
}
?>
代码先判断defalut值是否为空,如果不为空的话,再用switch语句进行匹配,如果匹配成功,则插入case字段的相应值,如果不匹配,则插入的是默认的值。
漏洞利用
由于 form表单提交的数据,想经过 JS 过滤,所以注释部分的 javascript 代码就不会被传到服务器端(也就符合了白名单的要求):
#<script>alert(/xss/)</script>
它会默认的传入English参数。
四、Impossible 级别
源代码:
<?php
# Don't need to do anything, protction handled on the client side
?>
不需要做任何事情,保护在客户端处理!
传入参数,发现页面并没有弹出任何东西,而且语言框内的值是我们输入的参数的经过URL编码后的数据:
我们查看源代码,发现这里对我们输入的参数并没有进行URL解码,所以我们输入的任何参数都是经过URL编码,然后直接赋值给option标签。所以,就不存在XSS漏洞了: