漏洞描述
2019年1月11日,阿里雲雲盾應急響應中心監測到ThinkPHP官方發布安全更新,披露了一個高危安全漏洞,攻擊者構造特定的 惡意請求,可以直接獲取服務器權限,受影響的版本包括5.0.0~5.0.23版本及5.1多個版本。
漏洞造成的影響
由於ThinkPHP5框架對Request類的method處理存在缺陷,導致黑客構造特定的請求,可直接GetWebShell。
驗證請求: POST http://xxx.xx/ s=c4ca4238a0b923820dcc509a6f75849b&_method=__construct&filter[]=print_r&method= 返回內容: xxx.xxc4ca4238a0b923820dcc509a6f75849b__constructprint_rc4ca4238a0b923820dcc509a6f75849b__const ructprint
修復方法 \thinkphp\library\think\Request.php 找到 public function method($method = false) { if (true === $method) { // 獲取原始請求類型 return $this->server('REQUEST_METHOD') ?: 'GET'; } elseif (!$this->method) { if (isset($_POST[Config::get('var_method')])) { $this->method = strtoupper($_POST[Config::get('var_method')]); $this->{$this->method}($_POST); } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); } else { $this->method = $this->server('REQUEST_METHOD') ?: 'GET'; } } return $this->method; } 替換為 public function method($method = false) { if (true === $method) { // 獲取原始請求類型 return $this->server('REQUEST_METHOD') ?: 'GET'; } 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')]); } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); } else { $this->method = $this->server('REQUEST_METHOD') ?: 'GET'; } } return $this->method; }