利用session.upload_progress进行文件包含
source link: https://antipassion.github.io/2021/10/30/%E5%88%A9%E7%94%A8session-upload-progress%E8%BF%9B%E8%A1%8C%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Session 上传进度
此特性自PHP 5.4.0后启用
我们可以利用session.upload_progress
将木马写入session文件,然后包含这个文件。但是首先我们需要知道session文件将会保存在何处
在Linux php中 session文件默认保存在/tmp/sess_session名中
以及会如何保存
默认session.use_strict_mode
为off状态,也就是说,用户可以在浏览器或者Burpsuit中自定义session ID值用于指明sess文件名。
但是session.upload_progress.cleanup
值为默认开启状态
当session.upload_progress.cleanup
默认开启时,一旦读取了所有的POST数据,便会清除session文件。
此处我们可以利用条件竞争的方式进行利用文件上传,生成sess文件,趁着sess文件还未删除,进行包含利用。
CTFshow web入门 web82
<?php
/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-16 11:25:09
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-16 19:34:45
# @email: [email protected]
# @link: https://ctfer.com
*/
if(isset($_GET['file'])){
$file = $_GET['file'];
$file = str_replace("php", "???", $file);
$file = str_replace("data", "???", $file);
$file = str_replace(":", "???", $file);
$file = str_replace(".", "???", $file);
include($file);
}else{
highlight_file(__FILE__);
}
此处可以看出,题目排除了php://
、data://
、日志包含
的手法进行getshell,此处尝试利用PHP_UPLOAD_PROGRESS
进行getshell
此处利用php.net
提供的上传栏代码加以修改:
<html>
<body>
<form action="http://f3c16bd0-8f13-4d36-84b1-193366ace33c.challenge.ctf.show/" method="POST" enctype="multipart/form-data">
<input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" value="123" />
<input type="file" name="file1" />
<input type="file" name="file2" />
<input type="submit" />
</form>
</body>
</html>
cookie处添加PHPSESSID=flag
,在PHP_SESSION_UPLOAD_PROGRESS下添加恶意代码;此时由于PHP的session.use_strict_mode
模式默认关闭,生成的session文件将会是sess_flag
同时Linux PHP
默认将sess文件存放于/tmp目录下
竞争1
利用bp不停写入sess文件
竞争2
在sess文件被删除之前,请求包含,获得命令相应
利用竞争,执行命令从而拿到fl0g.php中的flag
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK