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 ); |

相關信息