php代码审计ctf隐藏了目录,CTF中PHP代码审计小tips-7
閱讀次數
MiniProject_PHP_Code_audit-7 Writeup
整體邏輯:
xctf中的一道題目
考點:
接收參數中不能出現某一字符,file_get_contents()使用可以 php:// 偽協議繞過。
file_get_contents — 將整個文件讀入一個字符串 file_get_contents() 函數是用于將文件的內容讀入到一個字符串中的首選方法。如果操作系統支持,還會使用內存映射技術來增強性能。 但是接收參數中不能出現某一字符,file_get_contents()使用可以 php:// 偽協議繞過 。
php://input可以讀取沒有處理過的POST數據。相較于$HTTP_RAW_POST_DATA而言,它給內存帶來的壓力較小,并且不需要特 殊的php.ini設置。php://input不能用于enctype=multipart/form-data
Coentent-Type僅在取值為application/x-www-data-urlencoded和multipart/form-data兩種情況下,PHP才會將http請求數據包中相應的數據填入全局變量$_POST
測試代碼:class Read{
public $file = 'php://filter/read=convert.base64-encode/resource=f1aG.php';
}
$file = new Read;
echo serialize($file);
結果為序列化字符串【如圖】:
Writeup:
借鑒大佬的思路,
這個題目考察的是php封裝協議和lfi【圖一為index.php,圖二為class.php】
這個題目首先要突破的是:if(isset($user)&&(file_get_contents($user,’r’)===”the user is admin”)) 如何讓file_get_contents($user,’r’)===”the user is admin”呢? 答案是用php的封裝協議php://input,因為php://input可以得到原始的post數據【圖三】:
然后我到了:include($file); //class.php 這一步 這個很明顯是暗示你去讀取class.php 如何讀呢?這里用到php的另一個封裝協議:php://filter 利用這個協議就可以讀取任意文件了 利用方法:php://filter/convert.base64-encode/resource=index.php 這里把讀取到的index.php的內容轉換為base64的格式【圖四】
但是class.php把我們引入到另一個地方,就是利用反序列化來讀取flag文件 于是我們構造反序列化的參數【反序列化后續再講】: http://localhost/ctf/index.php?user=php://input&file=class.php&pass=O:4:"Read":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=f1aG.php";} 這里也是利用php://filter來讀取flag文件【圖五,圖六】
參考鏈接:
總結
以上是生活随笔為你收集整理的php代码审计ctf隐藏了目录,CTF中PHP代码审计小tips-7的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三元前驱体废水除镍钴锰
- 下一篇: 禁止文件夹 icloud_如何更改Win