参考
https://www.jianshu.com/p/8e44cb1b5b5b
漏洞原因
phpMyAdmin是一套开源的、基于Web的MySQL数据库管理工具。在其查找并替换字符串功能中,将用户输入的信息拼接进preg_replace函数第一个参数中。
在PHP5.4.7以前,preg_replace的第一个参数可以利用 进行截断,并将正则模式修改为e。众所周知,e模式的正则支持执行代码,此时将可构造一个任意代码执行漏洞。
影响版本
4.0.10.16之前4.0.x版本
4.4.15.7之前4.4.x版本
4.6.3之前4.6.x版本(实际上由于该版本要求PHP5.5+,所以无法复现本漏洞)
4.4.15.7之前4.4.x版本
4.6.3之前4.6.x版本(实际上由于该版本要求PHP5.5+,所以无法复现本漏洞)
触发前提
需要登录和写数据权限
preg_replace漏洞触发有两个前提:
01:第一个参数需要e标识符,有了它可以执行第二个参数的命令
02:第一个参数需要在第三个参数中的中有匹配,不然echo会返回第三个参数而不执行命令。
环境搭建
https://github.com/vulhub/vulhub/tree/master/phpmyadmin/CVE-2016-5734
利用脚本
https://www.exploit-db.com/exploits/40185/
复现
因为目标环境使用root,所以我们可以创建一个临时数据库和数据表,进行漏洞利用。这里,我们使用cve-2016-5734.pyPOC来复现漏洞。
-d是已经可以写的数据库,-c是待执行的PHP语句,如果没有指定表名,这个POC会创建一个名为prgpwn的表。
python cve-2016-5734.py -c 'system(id);' -u root -p root -d test http://:目标ip