Web之PHP入门1


环境访问

打开网站就是个这个:

1737988655975

F12看源码(ctrl+shift+c):

1737988706989

看到有个这个:

<body>
<!--source.php-->

<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>


</html>

访问这个链接后还是那个图片;

在这个靶机的url+source.php访问到文件:

1737989059503

内容如下:

<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
if (! isset($page) || !is_string($page)) {
echo "you can't see it";
return false;
}

if (in_array($page, $whitelist)) {
return true;
}

$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}

$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
echo "you can't see it";
return false;
}
}

if (! empty($_REQUEST['file'])
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>

看到”hint”=>”hint.php”后寻找hint.php

1737989267028

根据提示找到这个:

1737989344050

不是flag;

源码审计

php源码中定义了一个emm类,且其中实现了一个checkFile函数,然后该类的主题内容如下:

1737989654595

其中_REQUEST[‘file’] 表示从 HTTP 请求中提取名为 file 的参数,直接在url后边加上 ?filename即可设置这个参数:

1737989865952

看源码可知这个file参数不能为空、必须是string,且能通过checkFile的检查:

1737990010142

checkFile表明要在白名单中,

攻击成功

1737990867228

参考

https://cloud.tencent.com/developer/article/2349595


文章作者: q1ming
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 q1ming !
  目录