ThinkPHP 5.x远程命令执行漏洞 补丁

手动修复5.0版本

在think\App类的module方法的获取控制器的代码后面加上

if (!preg_match(‘/^A-Za-z*\(/', \)controller)) {

throw new HttpException(404, 'controller not exists:' . $controller);

}

5.1版本

在think\route\dispatch\Url类的parseUrl方法,解析控制器后加上

if (\(controller && !preg_match('/^[A-Za-z](\w|\.)*\)/’, $controller)) {

throw new HttpException(404, 'controller not exists:' . $controller);

}





if (!preg_match(‘/^[A-Za-z][\w.]\(/', \)controller)) { throw new HttpException(404, ’controller not exists:‘ . $controller); }
preg_match(’/^A-Za-z\(/', \)controller)

这个正则表达式, 确实存在问题.

  1. (\w)这个捕获分组是没有意义的
  2. 这里应该采用占用优先匹配, 来提高效率. 避免回溯.

下面这种方式, 会更好一些.

preg_match(‘/^[A-Za-z]\w*+\(/', \)controller)