最近由于对产品做交付,对产品做了License授权,有吧产品分装在kvm里面,但是感觉还是不太安全,于是想到对源码进行加密处理,目前市场上用的比较多的大致如下,本文使用了PHP Screw plus 文章开头使用别人写好的一些方案,就是就是流行的加解密产品
参考如下
# | 方案 | 类型 | 是否免费 | 优劣势分析 |
---|---|---|---|---|
1 | Zend Guard | 基于加解密客户端 | 收费 | PHP官方出品,是目前成熟的加密方案,不支持PHP7。Zend Guard用于加密(安装在开发或打包环境),Zend Guard Loader用于解密(安装在线上环境)软件下载 市面上仅流传出Zend Guard 6.0的破解版,支持PHP 5.3 5.4,安全平台使用的是PHP 5.6.30。 |
2 | ionCube PHP Encode | 基于加解密客户端 | 收费 | Zend Guard只能对带有PHP标记或源码的文件进行加密,而ionCube可对PHP或非PHP文件进行加密,ionCube在功能方面经过测试优胜于Zend公司的ZendGuard。 没有找到破解版。 |
3 | Swoole Compiler | 加密后可直接运行 | 收费 | 支持5.4-7.2全系列版本,优点:进行了很深入的编译优化,以目前 PHP 反汇编领域的情况看,根本破不了。 Swoole Compiler 有两道工序,第一步:从源码编译为 opcode,这一步会移除代码中除逻辑以外的其他信息,如注释、变量名称、类名、常量、函数名。 第二步:opcode 加密混淆处理。这一步才是关键,最终生成的指令连 vld、phpdbg 这些工具都无法识别。 |
4 | PHP Screw | 加密后可直接运行 | 免费 | 开源项目,没有维护了。加密算法比较弱,网上已有 破解方法 |
5 | PHP Screw plus | 基于扩展 | 免费 | 开源项目,基于扩展来加解密,采用AES256算法。他还有个功能,可阻止执行未经许可的php文件,这样黑客就算上传了webshell也不能执行。 |
6 | PHP Beast | 基于扩展 | 免费 | 开源项目,基于扩展来加解密,可选DES、AES、BASE64加密算法。支持自定义开发加密模块。 |
git clone https://git.oschina.net/splot/php-screw-plus.git
/usr/local/php/bin/phpize
./configure --with-config-php=/usr/local/php/bin/php-config
[root@dev02v php-screw-plus]# make
/bin/sh /home/jiangzhijie/safetyPhp/php-screw-plus/libtool --mode=compile cc -I. -I/home/jiangzhijie/safetyPhp/php-screw-plus -DPHP_ATOM_INC -I/home/jiangzhijie/safetyPhp/php-screw-plus/include -I/home/jiangzhijie/safetyPhp/php-screw-plus/main -I/home/jiangzhijie/safetyPhp/php-screw-plus -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/jiangzhijie/safetyPhp/php-screw-plus/php_screw_plus.c -o php_screw_plus.lo
mkdir .libs
cc -I. -I/home/jiangzhijie/safetyPhp/php-screw-plus -DPHP_ATOM_INC -I/home/jiangzhijie/safetyPhp/php-screw-plus/include -I/home/jiangzhijie/safetyPhp/php-screw-plus/main -I/home/jiangzhijie/safetyPhp/php-screw-plus -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/jiangzhijie/safetyPhp/php-screw-plus/php_screw_plus.c -fPIC -DPIC -o .libs/php_screw_plus.o
/bin/sh /home/jiangzhijie/safetyPhp/php-screw-plus/libtool --mode=link cc -DPHP_ATOM_INC -I/home/jiangzhijie/safetyPhp/php-screw-plus/include -I/home/jiangzhijie/safetyPhp/php-screw-plus/main -I/home/jiangzhijie/safetyPhp/php-screw-plus -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -o php_screw_plus.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/jiangzhijie/safetyPhp/php-screw-plus/modules php_screw_plus.lo
cc -shared .libs/php_screw_plus.o -Wl,-soname -Wl,php_screw_plus.so -o .libs/php_screw_plus.so
creating php_screw_plus.la
(cd .libs && rm -f php_screw_plus.la && ln -s ../php_screw_plus.la php_screw_plus.la)
/bin/sh /home/jiangzhijie/safetyPhp/php-screw-plus/libtool --mode=install cp ./php_screw_plus.la /home/jiangzhijie/safetyPhp/php-screw-plus/modules
cp ./.libs/php_screw_plus.so /home/jiangzhijie/safetyPhp/php-screw-plus/modules/php_screw_plus.so
cp ./.libs/php_screw_plus.lai /home/jiangzhijie/safetyPhp/php-screw-plus/modules/php_screw_plus.la
PATH="$PATH:/sbin" ldconfig -n /home/jiangzhijie/safetyPhp/php-screw-plus/modules
----------------------------------------------------------------------
Libraries have been installed in:
/home/jiangzhijie/safetyPhp/php-screw-plus/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
[root@dev02v php-screw-plus]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
[root@dev02v php-screw-plus]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226
[root@dev02v tools]# php -m | grep php_screw_plus
php_screw_plus
进入你相应的目录
/home/jiangzhijie/safetyPhp/php-screw-plus/tools
执行 make 命令
则多了screw文件,说明成功
下面进行真正的操作
加密
随便写入一段php 如 index.php
执行
./screw index.php
出现 Success Decrypting - index.php 表示成功
你的文件则变成
[root@dev02v tools]# more index.php 灛汁谻׆C֓t(Į¦;y캶5۫z+ N^L뫱`7«Kᡓ㟯yu¬¢|tך`®Y,©饁║&a¦½ƙ
㔬ޠ̺
º&D#e6- ²£ЁȤDZҨˠӢ§a̞².dᙏ윂)$«ej¥+~,dYEhKᯤԜG4IRzԶºܠ˳3pTޚ/¢£þfBꥠS±p峚Pڭ½±7X57LSq¥ª9f�_xþsI맙¶[ȫ{Ah¬G(µ¤Ô8P瘄.x!¡ƿN&1{6ʐzv«^L¤]¹㉳.Ȳ㴳F[U»¼°gͶ(^ځ_zµb
Ļcݾd["{s!¹ۿE4cw̤J9ꩄ@ֶٻ©IOoª<ӲrI:ɒ5p$l!
W1N¬IxO狌Jܨ>,²
ϡ£´덍P֧¬¤ߥm|隣µлv¦
m6oU¸~u=_§~΅+`㚣Q¾£َ{dڥ¦¯261*ɍ2܍Cµv3©Ȅ5¥zH³¼jⱰ´^:wº9wº$£9¢_iA쑦bµT¼
cd3塞²«9@o퐯,ˍMwǪCe튚¬Y9U ŰpCP֙z缱ºնҜ-¢ɑ
©$¢ԅYJWкҤJғ©dþ¡[¯܇½
解密:
执行
./screw index.php -d
出现 Success Decrypting - index.php 表示解密成功
希望对大家有帮助