thinkphp代码执行getshell的漏洞解决
时间:2019-12-18来源:系统城作者:电脑系统城
影响范围
5.x < 5.1.31, <= 5.0.23
先把*****\apps\config.php这里改为false(关闭Debug模式)

然后将****\thinkphp\library\think\Request.php里的,菜刀可搜索"获取原始请求类型"找到(https://yq.aliyun.com/articles/686397)
01 |
public function method($method = false) |
03 |
if (true === $method) { |
05 |
return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); |
06 |
} elseif (!$this->method) { |
07 |
if (isset($_POST[Config::get('var_method')])) { |
08 |
$this->method = strtoupper($_POST[Config::get('var_method')]); |
09 |
$this->{$this->method}($_POST); |
10 |
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
11 |
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
13 |
$this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']); |
改为如下代码:
01 |
public function method($method = false) |
03 |
if (true === $method) { |
05 |
return $this->server('REQUEST_METHOD') ?: 'GET'; |
06 |
} elseif (!$this->method) { |
07 |
if (isset($_POST[Config::get('var_method')])) { |
08 |
$method = strtoupper($_POST[Config::get('var_method')]); |
09 |
if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) { |
10 |
$this->method = $method; |
11 |
$this->{$this->method}($_POST); |
13 |
$this->method = 'POST'; |
15 |
unset($_POST[Config::get('var_method')]); |
16 |
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
17 |
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); |
19 |
$this->method = $this->server('REQUEST_METHOD') ?: 'GET'; |

再在 /thinkphp/library/think/App.php这里加上如下代码,菜刀搜索“获取控制器名”可以找到(https://www.jianshu.com/p/73e44d35fac8):
1 |
if (!preg_match('/^[A-Za-z](\w|\.)*$/', $controller)) { |
3 |
//修复ThinkPHP远程代码执行漏洞------By:ximcx(20190407) |
5 |
throw new HttpException(404, 'controller not exists:' . $controller); |

相关信息