当前位置:网站首页>[HarekazeCTF2019]Avatar Uploader 1
[HarekazeCTF2019]Avatar Uploader 1
2022-07-30 16:43:00 【茶经新读.】
[HarekazeCTF2019]Avatar Uploader 1
这题目是给了源码的

访问并且发现了upload.php
<?php
error_reporting(0);
require_once('config.php');
require_once('lib/util.php');
require_once('lib/session.php');
$session = new SecureClientSession(CLIENT_SESSION_ID, SECRET_KEY);
// check whether file is uploaded
if (!file_exists($_FILES['file']['tmp_name']) || !is_uploaded_file($_FILES['file']['tmp_name'])) {
error('No file was uploaded.');
}
// check file size
if ($_FILES['file']['size'] > 256000) {
error('Uploaded file is too large.');
}
// check file type
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $_FILES['file']['tmp_name']);
finfo_close($finfo);
if (!in_array($type, ['image/png'])) {
error('Uploaded file is not PNG format.');
}
// check file width/height
$size = getimagesize($_FILES['file']['tmp_name']);
if ($size[0] > 256 || $size[1] > 256) {
error('Uploaded image is too large.');
}
if ($size[2] !== IMAGETYPE_PNG) {
// I hope this never happens...
error('What happened...? OK, the flag for part 1 is: <code>' . getenv('FLAG1') . '</code>');
}
// ok
$filename = bin2hex(random_bytes(4)) . '.png';
move_uploaded_file($_FILES['file']['tmp_name'], UPLOAD_DIR . '/' . $filename);
$session->set('avatar', $filename);
flash('info', 'Your avatar has been successfully updated!');
redirect('/');审计代码得知,有两个比较重要的函数,分别是finfo_open()函数和getimagesize()函数,finfo_open()函数是检查上传的文件是不是image/png文件,不是的话返回’Upload file is not PNG format‘,getimagesize() 函数则用于获取图像大小及相关信息,成功返回一个数组,失败则返回 FALSE 并产生一条 E_WARNING 级的错误信息。
Array
(
[0] => 290
[1] => 69
[2] => 3
[3] => width="290" height="69"
[bits] => 8
[mime] => image/png
)返回结果说明
- 索引 0 给出的是图像宽度的像素值
- 索引 1 给出的是图像高度的像素值
- 索引 2 给出的是图像的类型,返回的是数字,其中1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM
- 索引 3 给出的是一个宽度和高度的字符串,可以直接用于 HTML 的 <image> 标签
- 索引 bits 给出的是图像的每种颜色的位数,二进制格式
- 索引 channels 给出的是图像的通道值,RGB 图像默认是 3
- 索引 mime 给出的是图像的 MIME 信息,此信息可以用来在 HTTP Content-type 头信息中发送正确的信息,如: header("Content-type: image/jpeg");
再次审计代码得知,要求上传的文件存在,不得大于256kb,通过finfo_open()函数检查(finfo_open函数主要是检查十六进制的第一行信息)是否是image/png文件,图像宽与高的像素值不得大于256px,上传成功即可给part1的flag。使用010创建十六进制文件,第二行的0、1、2、3是设置的宽,4、5、6、7是设置的高,直接不设置来绕过getimagesize()函数,只设置png文件头即可。

保存为1.png上传即可获得flag

至此完结,撒花
边栏推荐
- Invalid or corrupt jarfile xxx.jar
- 大型综合办公管理系统源码(OA+HR+CRM)源码免费分享
- PyQt5快速开发与实战 9.2 数据库处理
- Goland opens file saving and automatically formats
- 李沐d2l(七)kaggle房价预测+数值稳定性+模型初始化和激活函数
- MySQL 8.0.29 解压版安装教程(亲测有效)
- 大厂高管借钱炒股,亏到破产卖房。。。
- swagger使用教程——快速使用swagger
- 论文阅读 (63):Get To The Point: Summarization with Pointer-Generator Networks
- 云厂商做生态需要“真连接、真赋能”,用“技术+真金实银”发展伙伴
猜你喜欢

Public Key Retrieval is not allowed error solution

PHP留言反馈管理系统源码

全职做自媒体靠谱吗?

登录模块调试-软件调试入门

牛客网刷题——运算符问题
![[NCTF2019] Fake XML cookbook-1|XXE vulnerability|XXE information introduction](/img/29/92b9d52d17a203b8bdead3eb2c902e.png)
[NCTF2019] Fake XML cookbook-1|XXE vulnerability|XXE information introduction

3D激光SLAM:LeGO-LOAM论文解读---特征提取部分

【HMS core】【FAQ】A collection of typical questions about Account, IAP, Location Kit and HarmonyOS 1

如何注册域名、备案以及解析

华为云数据治理生产线DataArts,让“数据‘慧’说话”
随机推荐
@Bean注解详解
华为云数据治理生产线DataArts,让“数据'慧'说话”
huato hot update environment construction (DLL method hot update C# code)
牛客网刷题——运算符问题
Scheduling_Channel_Access_Based_on_Target_Wake_Time_Mechanism_in_802.11ax_WLANs
lotus 爆块失败
Chapter 5 Advanced SQL Processing
3D激光SLAM:LeGO-LOAM论文解读---系统概述部分
PCIE下载的驱动安装
游戏显示分辨率的逆向分析
C语言学习之旅 【函数(二)】
The case of five little pigs (five little pigs compare the size of the body weight)
Is it reliable to work full-time in self-media?
The service already exists! Solution
[AGC] Quality Service 2 - Performance Management Example
Moonbeam创始人解读多链新概念Connected Contract
[TypeScript]简介、开发环境搭建、基本类型
【HMS core】【FAQ】A collection of typical questions about Account, IAP, Location Kit and HarmonyOS 1
如何注册域名、备案以及解析
Chapter 6: Decisive Autumn Moves