buuoj--[HCTF 2018]WarmUp
2020-02-07 13:59
471 查看
buuoj中的第一题:[HCTF 2018]WarmUp
打开题目页面
右键查看源码,发现提示source.php,转到source.php发现源码
<?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\" />"; }?>
上面是一个类(没学过PHP,大同小异嘛)
下面有个判断
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\" />"; }
只要通过这个判断就会执行file传递的参数的文件,想到可能时任意文件包含。
通过引入文件时,引用的文件名,用户可控,由于传入的文件名没有经过合理的校验,或者检验被绕过,从而操作了预想之外的文件,就可能导致意外的文件泄露甚至恶意的代码注入。
再看if中的判断,file参数不为空&&是个字符串&&通过checkFile方法的检验。去看checkFIle方法。
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;}
这里逻辑也不是很复杂。
首先看到了提示的白名单,去看看hint.php
验证了猜想,任意文件包含漏洞。
checkFIle中有白名单,source.php和hint.php。
下面又是很多条件限制。一步一步看。
$whitelist = ["source"=>"source.php","hint"=>"hint.php"]; if (! isset($page) || !is_string($page)) { echo "you can't see it"; return false; }
首先必须存在并且是字符串(必须使函数返回为true才能访问文件)
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;
然后判断参数是否在白名单中;
mb_strpos()查找字符串在另一个字符串中首次出现的位置,即?在前面字符串中出现的位置
mb_substr()方法截断字符串。
然后和白名单比较。
又重复了一次上面的操作。
这个涉及到phpMyAdmin的一个洞CVE-2018-12613,由于PHP会自动urldecode一次,导致我们提交%253f(?的urlencode的urlencode)的时候自动转成%3f,满足if条件,%253f/就会被认为是一个目录,从而include。
? --> %3f --> %253f
payload: file=hint.php%253f/…/…/…/…/…/…/…/ffffllllaaaagggg
目录需要多跳出几次,慢慢尝试。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Nuit du Hack CTF Quals 2018 writeup (web)
- 蓝鲸ctf 逆向0x1 Warmup
- 0ctf-pwn_warmup-re_mips4
- HCTF_2018-Writeup【web题】
- 2018~第三届南宁市网络安全技术大赛~nnctf~write-up
- HITCTF 2018 wp [我真是菜鸟]
- hgame-2018 CTFwp(杭电信安)week1
- hgame-2018 CTFwp(杭电信安)week2
- 2018中原工CTF校赛
- RE-picoCTF2018-be-quick-or-be-dead-2
- hgame-2018 CTFwp(杭电信安)week3
- 初试ctf wp
- 2018,送给大家一份提升技术的宝典
- 如何评价2018字节跳动(今日头条)ACM-ICPC冬令营?
- ZOJ Monthly, January 2018
- 【NIPS2018】Text-Adaptive Generative Adversarial Networks: Manipulating Images with Natural Language
- 任泽平:95页PPT分析2018(经济、房价、政策)
- 计蒜客2018 蓝桥杯省赛 B 组模拟赛(三)回文子串
- 软考之网络工程师(包含2004-2018历年真题详解+官方指定教程+知识总结+各类型视频教程)
- Mindjet MindManager 2018无法输入产品密钥的解决办法