filter_var()函数

 

我们使用 payload :?url=javascript://comment%250aalert(1) ,可以执行 alert 函数:

实际上,这里的 // 在JavaScript中表示单行注释,所以后面的内容均为注释,那为什么会执行 alert 函数呢?那是因为我们这里用了字符 %0a ,该字符为换行符,所以 alert 语句与注释符 // 就不在同一行,就能执行。当然,这里我们要对 % 百分号编码成 %25 ,因为程序将浏览器发来的payload:javascript://comment%250aalert(1) 先解码成: javascript://comment%0aalert(1) 存储在变量 $url 中(上图第二行代码),然后用户点击a标签链接就会触发 alert 函数。

 

 


 

返回值 ¶

Returns the filtered data, or FALSE if the filter fails.

 

filter_var : (PHP 5 >= 5.2.0, PHP 7)

功能 :使用特定的过滤器过滤一个变量

定义 :mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] )

针对这两处的过滤,我们可以考虑使用 javascript伪协议 来绕过。为了让大家更好理解,请看下面的demo代码

 

htmlspecialchars :(PHP 4, PHP 5, PHP 7)

功能 :将特殊字符转换为 HTML 实体

定义 :string htmlspecialchars ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string$encoding= ini_get("default_charset") [, bool $double_encode = TRUE ]]] )

& (& 符号)  ===============  &
" (双引号)  ===============  "
' (单引号)  ===============  '
< (小于号)  ===============  &lt;
> (大于号)  ===============  &gt;

参考:[红日安全]代码审计Day2 - filter_var函数缺陷 - 先知社区 https://xz.aliyun.com/t/2457

posted @ 2019-08-05 11:16  壹個人坐在角落  阅读(825)  评论(0编辑  收藏  举报