screw plus是一个开源的php扩展,采用AES256对php文件进行加密,目前只能在linux下作加密处理,加密后的php文件只能在本服务器运行。相对于混淆加密方式而来说,更安全。
测试环境采用的是Vmware的CentOS 7.6,安装了宝塔, php版本为7.1
首先安装扩展,Github地址是https://github.com/del-xiong/screw-plus
1、[root@localhost screw-plus]# git clone https://github.com/del-xiong/screw-plus.git
2、进入screw-plus目录,执行phpize生成php所需要的扩展,要找到php安装目录,
[root@localhost screw-plus]# /www/server/php/71/bin/phpize
3、配置,路径要写绝对路径
[root@localhost screw-plus]# ./configure --with-php-config=/www/server/php/71/bin/php-config
4、修改php_screw_plus.h 的加密key,将#define CAKEY "FwWpZKxH7twCAG4JQMO" 改成自己的字符串,最好是16位以上
[root@localhost screw-plus]# vim php_screw_plus.h
5、编译解密程序
[root@localhost screw-plus]# make
6、进入tools编译加密程序
[root@localhost screw-plus]# cd tools
[root@localhost tools]# make
7、在php.ini的里写入新生成的扩展,加入以下这行代码,重启php
extension=/usr/local/src/screw-plus/modules/php_screw_plus.so
8、查看phpinfo,可以看到已经安装完成php_screw_plus扩展
9、在tools目录里执行 ./screw [文件名] [文件夹名], 就可以对php文件或整个文件夹进行加密
对index.php 进行加密
[root@localhost screw-plus]# cd tools
[root@localhost tools]# ./screw /www/wwwroot/default/index.php
Success Crypting - /www/wwwroot/default/index.php
或者
[root@localhost tools]# ./screw /www/wwwroot/default/
加密之后的index.php文本内容:
访问加密后的index.php,运行正常
10、php_screw_plus 可以设置非加密的php文件不运行,将php_screw__plus.h的STRICT_MODE 改为1
然后要再重新编译并重启php
[root@localhost screw-plus]# vim php_screw_plus.h
[root@localhost screw-plus]# vim php_screw_plus.h
[root@localhost screw-plus]# make clean && make
[root@localhost screw-plus]# /etc/init.d/php-fpm-71 restart
在网站目录新建一个php文件并访问,很明显的看到 'ACCESS DENIED',被拒绝访问
11、解密
在tools里执行./screw [文件夹] -d 命令进行解密
[root@localhost tools]# ./screw /www/wwwroot/default/ -d
原来加密的index.php又恢复原来的代码
[补充]
不适合对thinkphp框架进行加密,加密后会报错
感谢博主,喝杯咖啡~
还没有人发表评论