当前位置:网站首页>[HarekazeCTF2019] Avatar Uploader 1
[HarekazeCTF2019] Avatar Uploader 1
2022-07-30 17:01:00 【New Reading of the Classic of Tea.】
[HarekazeCTF2019]Avatar Uploader 1
This topic is given to the source code

Visit and found upload.php
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: ' . getenv('FLAG1') . '');}// 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('/');The audit code learned that there are two important functions, namely the finfo_open() function and the getimagesize() function. The finfo_open() function is to check whether the uploaded file is an image/png file, and if not, return 'Upload file'is not PNG format', the getimagesize() function is used to obtain the image size and related information, and returns an array if successful, or FALSE if it fails, and an E_WARNING level error message is generated.
Array([0] => 290[1] => 69[2] => 3[3] => width="290" height="69"[bits] => 8[mime] => image/png)Return result description
- Index 0 gives the image width in pixels
- Index 1 gives the image height in pixels
- Index 2 gives the type of the image and returns a number, where 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
- Index 3 gives a width and height string that can be used directly in the HTML
tag - Index bits gives the number of bits per color of the image, in binary format
- The index channels gives the channel value of the image, the default is 3 for RGB images
- The index mime gives the MIME information of the image, which can be used to send the correct information in the HTTP Content-type header, such as: header("Content-type: image/jpeg");
After auditing the code again, we learned that the file required to be uploaded exists and must not be larger than 256kb. It is checked by the finfo_open() function (the finfo_open function mainly checks the first line of hexadecimal information) whether it is an image/png file, and the image widthThe pixel value of the height and height should not be greater than 256px. If the upload is successful, the flag of part1 can be given.Use 010 to create a hexadecimal file. 0, 1, 2, and 3 in the second line are the set widths, and 4, 5, 6, and 7 are the set heights. Do not set them directly to bypass the getimagesize() function, and only setpng file header.

Save as 1.png and upload to get flag

This is the end, let's spread the flowers
边栏推荐
- WeChat applet picker scroll selector use detailed explanation
- 04、Activity的基本使用
- What does a good resume look like in the eyes of a big factory interviewer?
- DTSE Tech Talk丨第2期:1小时深度解读SaaS应用系统设计
- PyQt5快速开发与实战 9.2 数据库处理
- HUAWEI CLOUD data governance production line DataArts, let "data 'wisdom' speak"
- 你是一流的输家,你因此成为一流的赢家
- 一篇文 带你搞懂,虚拟内存、内存分页、分段、段页式内存管理(超详细)
- 将 APACHE 日志解析到 SQL 数据库中
- 论文阅读 (63):Get To The Point: Summarization with Pointer-Generator Networks
猜你喜欢
随机推荐
数据预处理:离散特征编码方法
《痞子衡嵌入式半月刊》 第 59 期
KDD 2020 | 深入浅出优势特征蒸馏在淘宝推荐中的应用
【综合类型第 34 篇】喜讯!喜讯!!喜讯!!!,我在 CSDN 的第一个实体铭牌
云厂商做生态需要“真连接、真赋能”,用“技术+真金实银”发展伙伴
华为无线设备配置Mesh业务
No qualifying bean of type问题解决
Mongoose module
京东获取推荐商品列表 API
PHP message feedback management system source code
字符串复制、拼接、比较以及分割函数总结(一)
浅谈在线编辑器中增量编译技术的应用
如何在 UE4 中用代码去控制角色移动
基于STM32F407使用ADC采集电压实验
UI测试新方法:视觉感知测试详解
Explore CSAPP Experiment 2-bomb lab-Section 1
KDD‘21推荐系统离散特征表征无embedding table Learning to Embed Categorical Features without Embedding Tables for
测试管理与规范
[MRCTF2020]Ezaudit
olap——入门ClickHouse









