打开页面
很乱的感觉 查看源码
感觉是目录可访问 还有本地包含
于是访问一波 (可以买彩票了 =.= )
直接访问 发现不行(废话)
直接尝试读取 flag/flag.txt index.php 都是文件不存在
尝试读取图片 成功返回
尝试读取其他图片 比如 .gif .png 都不行 猜测判断了文件后缀 然而00截断并不行
按基友的话说 这里有个暗坑
按理上面这张图应该返回base64编码的 但是返回的确是一张可视图片
说明filter并没有被执行 然而比赛的时候并没有想这么多..(其实就是菜) 以为图片是直接返回的
====================================================================
以下参考别人的wp 链接在文章最后给出
It returns our image, but not the b64 string of it. Strange behavior.
直接返回了图片 而不是base64加密 这是奇怪的现象 (明眼人一眼就看出来了 Orz)
After some test, we saw that it seems to retrieve the content of the resource with a regex to avoid us to use a php filter
经过测试后猜测 页面用正则过滤 防止直接读取源码
然后用了这么一个url测试
http://ctf.sharif.edu:31455/chal/technews/6ebb0f4f44b73fb0/images.php?id=php://abcdresource=files/flag/heart.jpg
php://abcdresource=files/flag/heart.jpg 这个脑洞 不得不服 附上原图
It still display our image, so I imagined it's using a regex like ^php://.resource=(.)$ and inject the capture into the variable that manage the file that will be loaded
仍然正常返回图片 说明猜测是正确的 意识到正则类似于 ^php://.resource=(.)$
这里感觉其实是先心里有这么个正则的想法 才会这么去测试 就像sqli 先猜测后台语句 再测试一样
当然这只是我做了很多sqli后的经验 不认同也没有关系
接下来 想办法绕过正则就可以了
顺便顺走源码
这题挺好的 会在blog中复现(坑已挖 233) 附上源码
<?php
//if (extract_teamname_from_cookie("technews") === false)
// exit;
if(isset($_GET["id"]) && (strpos($_GET["id"],'jpg') !== false))//is file type is jpg?
{
# echo "$_GET["id"]";
header('Cache-control: private');
preg_match("/^php:\/\/.*resource=([^|]*)/i", trim($_GET["id"]), $matches);
//die ("<pre>" . trim($_GET["id"]));
//die ("<pre>///".print_r($matches, true)."///");
if (isset($matches[1]))
$_GET["id"] = $matches[1];
if (file_exists("./" . $_GET["id"]) == false)
die("file not found");
if (substr(realpath("./" . $_GET["id"]), 0, 24) != "ar/www/technology-news")
die(".");
header('Content-Type: image/jpg');
header('Content-Length: '.filesize($_GET["id"]));
header('Content-Disposition: filename='.$_GET["id"]);
$img_data = file_get_contents($_GET["id"]);
$img_data = sharifctf_internal_put_it($img_data, "technews");
echo $img_data;
}
else //file type is not jpg! show the error message
{
echo "file not found";
}
?>