前言
- iframe是可用于在HTML页面中嵌入一些文件(如文档,视频等)的一项技术。对iframe最简单的解释就是“iframe是一个可以在当前页面中显示其它页面内容的技术”。
- 通过利用iframe标签对网站页面进行注入,是利用了HTML标签,实际上就是一个阅读器,可以阅读通过协议加载的活服务器本地的文件、视频等
靶场练习
输出代码
<?php
if($_COOKIE["security_level"] == "1" || $_COOKIE["security_level"] == "2")
{
?>
<iframe frameborder="0" src="robots.txt" height="<?php echo xss($_GET["ParamHeight"])?>" width="<?php echo xss($_GET["ParamWidth"])?>"></iframe>
<?php
}
else
{
?>
<iframe frameborder="0" src="<?php echo xss($_GET["ParamUrl"])?>" height="<?php echo xss($_GET["ParamHeight"])?>" width="<?php echo xss($_GET["ParamWidth"])?>"></iframe>
<?php
}
?>
安全等级对应的过滤函数
function xss($data)
{
switch($_COOKIE["security_level"])
{
case "0" :
$data = no_check($data);
break;
case "1" :
$data = xss_check_4($data);
break;
case "2" :
$data = xss_check_3($data);
break;
default :
$data = no_check($data);
break;
}
return $data;
}
1.low
由于没有对参数进行过滤就输出,我们可以控制param的输入来访问本地文件
?ParamUrl=…/README.txt&ParamWidth=250&ParamHeight=250
也可以访问百度啥的
?ParamUrl=https://www.baidu.com&ParamWidth=250&ParamHeight=250
2.medium
从代码可以看出,medium等级不能控制paramurl的输入,所以只能通过控制ParamHeight和ParamWidth来实现注入。用"></iframe>
将它闭合。刚开始用了""
,还在想怎么没弹出来,忘了xss_check4的addslashes()函数会在预定义字符(单引号、双引号、反斜杠、NULL)之前添加反斜杠了
function xss_check_4($data)
{
// addslashes - returns a string with backslashes before characters that need to be quoted in database queries etc.
// These characters are single quote ('), double quote ("), backslash () and NUL (the NULL byte).
// Do NOT use this for XSS or HTML validations!!!
return addslashes($data);
}
payload:
?ParamUrl=robots.txt&ParamWidth=250">&ParamHeight=250
3.high
对输出进行了限制并且对预定义字符进行了HTML实体编码所以绕过失败…
function xss_check_3($data, $encoding = "UTF-8")
{
// htmlspecialchars - converts special characters to HTML entities
// '&' (ampersand) becomes '&'
// '"' (double quote) becomes '"' when ENT_NOQUOTES is not set
// "'" (single quote) becomes ''' (or ') only when ENT_QUOTES is set
// '<' (less than) becomes '<'
// '>' (greater than) becomes '>'
return htmlspecialchars($data, ENT_QUOTES, $encoding);
}