当前位置:网站首页>[GXYCTF2019]BabyUpload
[GXYCTF2019]BabyUpload
2022-06-23 09:14:00 【K00sec】
[GXYCTF2019]BabyUpload
打开靶场地址,考文件上传思路还是挺重要的。

先上传一个php文件看看,这大概率是上传不了的,接着就抓包然后跟着思路走一波。

限制后缀中不能有 **ph ,**可能是黑名单,在用随机字符测试下。

提示上传类型的也限制了,没什么问题,修改下 Content-Type 字段值的 MIME 类型。



没想到这题不仅设置了黑名单限制(后缀不能包含ph) 还有白名单限制(上传类型是 image/jpeg) 。提示说标志是 php 说明对文件的内容进行了检查。这样的话还是可以绕过。
## 一句话木马
<script language='php'>eval($_POST[cmd]);</script>

成功的上传上去了,但是又有一个问题,上传上去的文件是 .123123 的是一个不存在的后缀,无法解析。但是访问 /upload 目录的时候发现了 403 错误。给出了靶场中间件的版本是 Apache 这就好办了。

Apache 中的用户配置文件 .htaccess 没有 ph 关键字而且也上可以上传,只需要在配置中设置 .123123 可以被php解析就行。

用 蚁剑连接木马(上面用的木马是接收 GET 请求的不能用,后面改成了 POST)。

找到flag了。

题目源码
<?php
session_start();
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Upload</title> <form action=\"\" method=\"post\" enctype=\"multipart/form-data\"> 上传文件<input type=\"file\" name=\"uploaded\" /> <input type=\"submit\" name=\"submit\" value=\"上传\" /> </form>";
error_reporting(0);
if(!isset($_SESSION['user'])){
$_SESSION['user'] = md5((string)time() . (string)rand(100, 1000));
}
if(isset($_FILES['uploaded'])) {
$target_path = getcwd() . "/upload/" . md5($_SESSION['user']);
// 文件上传的目录
$t_path = $target_path . "/" . basename($_FILES['uploaded']['name']);
$uploaded_name = $_FILES['uploaded']['name'];
$uploaded_ext = substr($uploaded_name, strrpos($uploaded_name,'.') + 1);
// 文件的后缀
$uploaded_size = $_FILES['uploaded']['size'];
// 文件大小
$uploaded_tmp = $_FILES['uploaded']['tmp_name'];
if(preg_match("/ph/i", strtolower($uploaded_ext))){
die("后缀名不能有ph!");
}
else{
if ((($_FILES["uploaded"]["type"] == " ") || ($_FILES["uploaded"]["type"] == "image/jpeg") || ($_FILES["uploaded"]["type"] == "image/pjpeg")) && ($_FILES["uploaded"]["size"] < 2048)){
// 限制文件大小、文件类型(jpeg和pjpeg)
$content = file_get_contents($uploaded_tmp);
// 获取文件的内容
if(preg_match("/\<\?/i", $content)){
// 匹配文件内容如果有 <? 就报错
die("诶,别蒙我啊,这标志明显还是php啊");
}
else{
mkdir(iconv("UTF-8", "GBK", $target_path), 0777, true);
move_uploaded_file($uploaded_tmp, $t_path);
echo "{
$t_path} succesfully uploaded!";
}
}
else{
die("上传类型也太露骨了吧!");
}
}
}
?>
边栏推荐
- Redis learning notes - Database Management
- MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
- Redis learning notes - detailed explanation of redis benchmark
- Redis学习笔记—地理信息定位(GEO)
- ucosii(学习笔记)
- Best time to buy and sell stock II
- Leetcode topic analysis 3sum
- 类型从属名称的使用必须以“typename”为前缀
- 636. Exclusive Time of Functions
- swagger UI :%E2%80%8B
猜你喜欢

学习SCI论文绘制技巧(F)

Redis学习笔记—客户端通讯协议RESP

Custom tag - JSP tag Foundation

使用base64,展示图片

Community article | mosn building subset optimization ideas sharing

986. Interval List Intersections

Click Add drop-down box

The sliding window of the force button "step by step" (209. sub array with the smallest length, 904. fruit basket)

一元函数求极限三大方法---洛必达法则,泰勒公式

JSP入门总结
随机推荐
也无风雨也无晴
Redis learning notes - traverse key
Redis learning notes - slow query analysis
The fourth online workshop review
Redis学习笔记—数据类型:有序集合(zset)
Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project
Redis学习笔记—持久化机制之RDB
Redis learning notes - AOF of persistence mechanism
2022-06-22:golang选择题,以下golang代码输出什么?A:3;B:1;C:4;D:编译失败。
node request模塊cookie使用
Redis learning notes - client communication protocol resp
Bit binding
一个采用直接映射方式的32KB缓存......存储器课后习题
MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
One of the 12 balls is different from the others. Provide a balance and find it three times
Basic use of lua
Structure binary tree from inorder and postorder traversal for leetcode topic analysis
Redis learning notes - data type: ordered set (Zset)
简易学生管理
Redis learning notes - data type: string (string)