

opcache导致的RCE复现 - F12~
source link: https://www.cnblogs.com/F12-blog/p/18001985
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

opcache导致的RCE复现 - F12~ - 博客园
RCE得搭配着文件上传的点来进行利用
用docker搭个php7的环境,作者用的php7.0
docker run -itd --name php7 -p 8083:80 php:7.0-apache
安装opcache拓展
- 进入docker容器:
docker exec -it 容器id /bin/bash
- 安装opcache:
cd /usr/local/bin && docker-php-ext-configure opcache --enable-opcache && docker-php-ext-install opcache
- 重启apache:
cd /etc/init.d && ./apache2 restart
修改一下php.ini,应用opcache:
cd /usr/local/etc/php && cp php.ini-development php.ini
然后改php.ini:
opcache原理
Opache是php中一个生成缓存文件的拓展,当我们访问一个php文件时,他会产生一个缓存文件,下次访问该php文件时,就会直接根据缓存文件回显页面,查看tmp下,已经生成了缓存文件:
RCE操作
想要rce,我们就得覆盖掉生成的bin文件,首先得计算出文件夹的这个system_id,也就是8431e96e6adfc8fc75ad38a0f6a7eb4e
,那么这个system_id怎么计算呢?偷别人的脚本(bushi : https://github.com/GoSecure/php7-opcache-override
非常的方便快捷
现在得生成我们的恶意bin文件去覆盖掉原先的bin文件,先分析一下bin文件的结构:
010可以看出,bin文件的文件头是OPCACHE+system_id,由于opcache有个时间戳验证,如果我们伪造的时候,时间戳对不上是不会生效的,上图中的40h处就是时间戳的值,点击40h处,然后看Signed Int64的值,到时直接替换这个值就行了
我们在自己服务器上生成一个恶意的bin文件,改掉时间戳跟system_id的值,上传覆盖phpinfo.php.bin,访问覆盖成功(我这里语法写错了,难崩)
php8的opcahce
在php8后,system_id的生成方式发生了改变,所以7的脚本用不了了,但是8是有规律的,其实我们只要能获取到php的正确版本,就能自己搭建生成一个完全一样的system_id,其余操作都是相同的,唯一不同的就在于system_id的生成
__EOF__
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK