Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d9d2ef8
修复某些环境下STRICT_MODE不可用问题, 添加STRICT_MODE错误提示信息
Jun 28, 2018
d6a01b9
Merge pull request #10 from del-xiong/del
del-xiong Jun 28, 2018
9539b1f
PHP_NEW_EXTENSION注册语句更新, 兼容新环境
Jun 29, 2018
7ce6db0
Merge pull request #11 from del-xiong/del
del-xiong Jun 29, 2018
cb42eeb
添加DOCKER 镜像构建文件
Jun 29, 2018
1b73418
Merge pull request #12 from del-xiong/del
del-xiong Jun 29, 2018
7709d0f
修复在某些linux系统由于dirent无法判断文件类型导致的加解密失败
May 9, 2019
085125c
Merge pull request #20 from del-xiong/del
del-xiong May 9, 2019
c396671
Update php_screw_plus.c
m9rco Nov 13, 2019
7a9ff7f
Update php_screw_plus.c
m9rco Nov 13, 2019
0e3a56c
Merge pull request #27 from m9rco/master
del-xiong Nov 26, 2019
c8f08d1
增加版本号 封存历史版本 add version number
Dec 1, 2019
ca0b0ed
Merge pull request #29 from del-xiong/del_dev
del-xiong Dec 1, 2019
b69fd4f
兼容php7.4移除ZEND_HANDLE_FD了定义 ifdef判断下
Jul 2, 2020
d29bd5d
Merge pull request #35 from del-xiong/del_dev
del-xiong Jul 2, 2020
0f9ef3c
Update README.md
del-xiong Jul 2, 2020
7e50168
php8编译支持更改 add supports for php8.*
del-xiong Apr 12, 2022
bdd07b6
Merge pull request #41 from del-xiong/del
del-xiong Apr 12, 2022
49a91d4
解密时申请内存根据文件真实大小申请 更新readme
Jun 21, 2022
6f09ea9
Merge pull request #43 from del-xiong/del_dev
del-xiong Jun 21, 2022
0adb2fe
移除tools工具中maxBytes replace maxBytes with the real file size
Jun 25, 2022
dda209c
Merge pull request #44 from del-xiong/del_dev
del-xiong Jun 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# php screw plus

### 20220621 screw plus不再进行维护,对加密运行有需求的朋友可转向screw opcode,基于opcode的加密,可为php提供更安全、高效的加密运行环境

### screw opcode https://github.com/del-xiong/screw-opcode

--------------------------------------
--------------------------------------

github https://github.com/del-xiong/screw-plus
oschina http://git.oschina.net/splot/php-screw-plus

详细配置教程 http://www.jianshu.com/p/f6425e2f8643 (使用screw plus来保护php代码安全)

**交流QQ群 530887505**

支持版本: php 5.6-8.1
supported versions: php 5.6-8.1

### 简述
- 2016/08/13更新:给screw增加批量解密功能
- 2016/06/27更新:增加了STRICT_MODE,如果只允许服务器执行加过密的php文件,设置php_screw_plus.h STRICT_MODE为1(set STRICT_MODE to 1 if you only want the crypted php files to be executed),此举可防止黑客或其他人执行任意php文件。
Expand Down Expand Up @@ -39,20 +49,20 @@ define('CONFIG_UC', './config/config_ucenter.php');
```
加密后:
```
a57f658413a1a06742855 2盆閡?煉A%匛If???骗叴 聒诧l膢*C??禳颲??蜁爨t?犡c?毉TC誥1%-?q1|9B鑐/, 擤`M柼Vd`q?.r:婺Xo廰損??軋?訍祔tq忄,?uj*坵括罸 ???? -a?A?硾亀浑湀(J蒷驗I榮CRd?~踾T? ~r刜-7嗎?炐z(9.?
a57f658413a1a06742855 2盆閡?煉A%匛If???骗叴 聒诧l膢*C??禳颲??蜁爨t?犡c?毉TC誥1%-?q1|9B鑐/, 擤`M柼Vd`q?.r:婺Xo廰損??軋?訍祔tq忄,?uj*坵括罸 ???? -a?A?硾亀浑湀(J蒷驗I榮CRd?~踾T? ~r刜-7嗎?炐z(9.?
t0+c箝侶Y漟W)?1?吲i碀
^P;y伙異战耠甿F夺9瓟愕簎嵾*B續酉??朴瀹)輤qq疏?Ρo??_族嬇R緬?|?筹誀KT钄籘79薗勜PhS恺堨猞?j_)及B盭w??吠辱c?ra?敺奓嵑$j鹳啎` ?秽⒗P鮡姩到
?羮?I?'湣挸]Ι話宛Lr 驜腢瀶k辖K姲眯J噤N?g喴邃彛¢梴k~?1丛疫葘齍
o4芉!#漫}耑-??朒漜垃
芎wQa?)Dx聢D?w*鬿<?笴!熹6#鲙飯*W.吢濹酋咵攎:5隁?5鄨蚀?ク胍蠜?;V飉5?)笵f餻傿輆l?迳???逢婉I蘈)退欺
瞰RX鹴?地?\┄b槱馐? 吕??嫇k釷,Pw7y0臈懚y???鴀^ 屽 洵&戉_
蒈Z霃"鮼昖靚 6簝hS歉??O低盖??禜?啀Fm=???盾殝斺娎?A≡m-SWg祫a廠睛hV')/ぐE??友?徛7gU勭u脘愨赔?抇/剡飃I-?穟?E愧憂=Bp=楱殓\d膛*鱦鷂?鞦驲藛W;?疉陛菔鐰?eYM葼乛飌间∫曖>cケ:嬺郠椦TY魷 FJ??觺杠B`9€X]┚呿4?k娤?豯v?9??\螐廱鲟`漬\F?#假
蒈Z霃"鮼昖靚 6簝hS歉??O低盖??禜?啀Fm=???盾殝斺娎?A≡m-SWg祫a廠睛hV')/ぐE??友?徛7gU勭u脘愨赔?抇/剡飃I-?穟?E愧憂=Bp=楱殓\d膛*鱦鷂?鞦驲藛W;?疉陛菔鐰?eYM葼乛飌间∫曖>cケ:嬺郠椦TY魷 FJ??觺杠B`9€X]┚呿4?k娤?豯v?9??\螐廱鲟`漬\F?#假
?S阮??8邂璟襹B跷沯僯{¬UI憤
```
### 使用方法:
1. 下载本程序并解压到某个目录
2. 在screw plus目录中执行php bin中的phpize自动生成扩展所需文件(如果你的php里没有可以去官网下载)
3. 执行./configure --with-php=config=[php config path] 进行配置,[php config path]是你的php-config的绝对路径
3. 执行./configure --with-php-config=[php config path] 进行配置,[php config path]是你的php-config的绝对路径
4. 修改php_screw_plus.h中的CAKEY,改为一个你认为安全的字符串
5. 执行make生成扩展 modules/php_screw_plus.so
6. 把扩展路径加入php.ini中 重启php
Expand All @@ -65,4 +75,4 @@ o4芉!#漫}耑-??朒漜垃
```
表示解密web目录的所有php文件

现在可以访问php文件,如果前面没有发生错误,应该可以正常执行了。
现在可以访问php文件,如果前面没有发生错误,应该可以正常执行了。
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ dnl Make sure that the comment is aligned:

if test "$PHP_php_screw" != "no"; then
dnl Action..
PHP_EXTENSION(php_screw_plus, $ext_shared)
PHP_NEW_EXTENSION(php_screw_plus, php_screw_plus.c, $ext_shared)
fi
20 changes: 20 additions & 0 deletions docker_build/php7.1_alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:3.7

RUN echo "https://mirrors.aliyun.com/alpine/v3.7/main/" > /etc/apk/repositories \
&& echo "https://mirrors.aliyun.com/alpine/v3.7/community/" >> /etc/apk/repositories \
&& apk add --update --no-cache rsyslog runit dcron curl wget bash rsync nodejs tzdata \
&& apk add php7 php7-fpm php7-gd php7-redis \
php7-opcache php7-pdo php7-pdo_mysql php7-mbstring php7-json \
php7-mcrypt php7-curl php7-ctype php7-zip php7-xml php7-simplexml \
php7-xmlreader php7-xmlwriter php7-phar php7-fileinfo

RUN apk add --virtual .build-deps build-base php7-dev zlib-dev && \
cd / && \
wget https://codeload.github.com/del-xiong/screw-plus/zip/master && \
unzip master && \
cd /screw-plus-master && \
phpize && \
./configure --with-php-config=php-config && \
make && make install && \
cd tools && make && \
apk del .build-deps
9 changes: 9 additions & 0 deletions docker_build/php7.1_alpine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## alpine+php7.1+screw plus
```
@author QQ群友 chunhui.hu
@size 88.6MB
拉取: docker pull pastyouth/php-screw-plus:php7.1_alpine
运行方法: docker run -p ... -v ...
构建完成后删除了screw plus编译环境, 建议外部挂载程序
若要内部重新编译screw plus, 可注释Dockerfile最后一行 apk del..., 构建镜像成功后可在容器内部编译, 容量会上升至300MB左右
```
221 changes: 221 additions & 0 deletions docker_build/php7.2.6-redis-memcached-swoole/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
FROM centos

# 安装工具
RUN cd / && yum install -y epel-release && \
yum install -y wget vi gcc gcc-c++ autoconf libjpeg libcurl libcurl-devel libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel \
libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libxslt libxslt-devel libevent-devel \
iconv libmcrypt libmcrypt-devel libicu-devel re2c bison bzip2 bzip2-devel unzip; yum clean all && \
ldconfig

# 安装libzip的安装工具cmake https://cmake.org/files/
RUN cd / && wget https://cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz && \
tar -zxvf cmake-3.12.0-rc1.tar.gz && \
cd /cmake-3.12.0-rc1 && \
./configure && make && make install && \
rm -f /cmake-3.12.0-rc1.tar.gz && \
rm -rf /cmake-3.12.0-rc1

# 安装libzip库 https://libzip.org/download/
RUN cd / && wget https://libzip.org/download/libzip-1.5.1.tar.gz && \
tar -xf libzip-1.5.1.tar.gz && \
cd /libzip* && \
mkdir build && cd build && cmake .. && make && make install && \
rm -f /libzip-1.5.1.tar.gz && \
rm -rf /libzip-1.5.1

# 安装ICU库(为了安装intl扩展 owncloud用到)
RUN cd / && wget http://download.icu-project.org/files/icu4c/62rc/icu4c-62rc-src.tgz && \
tar xf icu4c-62rc-src.tgz && \
cd icu/source && \
mkdir /usr/local/icu && \
./configure --prefix=/usr/local/icu && \
make && make install && \
rm -f /icu4c-62rc-src.tgz && \
rm -rf /icu

# 下载并解压源码包
RUN cd / && wget http://jp2.php.net/distributions/php-7.2.6.tar.gz && \
tar -zxvf php-7.2.6.tar.gz
# 编译安装
RUN cd /php-7.2.6 && ./configure --prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-jpeg-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-mhash \
--with-libzip \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-simplexml \
--enable-intl && \
make && make install && \
cp php.ini-production /usr/local/php/lib/php.ini && \
cp sapi/fpm/init.d.php-fpm /usr/local/php/etc/php-fpm && \
sed -i 's/ --daemonize//g' /usr/local/php/etc/php-fpm && \
chmod +x /usr/local/php/etc/php-fpm && \
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf && \
sed -i 's/^;daemonize = yes/daemonize = no/g' /usr/local/php/etc/php-fpm.conf && \
sed -i 's/^listen = 127\.0\.0\.1\:9000/listen = 9000/g' /usr/local/php/etc/php-fpm.d/www.conf && \
rm -rf /php-7.2.6 && \
rm -f /php-7.2.6.tar.gz


#下载mcrypt扩展
RUN cd / && wget http://pecl.php.net/get/mcrypt-1.0.1.tgz && \
tar -zxvf mcrypt-1.0.1.tgz && \
cd mcrypt-1.0.1 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && make install && \
echo "extension_dir=/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/">>/usr/local/php/lib/php.ini && \
echo "extension=mcrypt.so">>/usr/local/php/lib/php.ini && \
rm -rf /mcrypt-1.0.1 && \
rm -f /mcrypt-1.0.1.tgz

# 安装memcached 依赖库igbinary http://pecl.php.net/package/igbinary
RUN cd / && wget http://pecl.php.net/get/igbinary-2.0.6.tgz && \
tar -zxvf igbinary-2.0.6.tgz && \
cd igbinary-2.0.6 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && make install && \
echo "extension=igbinary.so">>/usr/local/php/lib/php.ini && \
rm -f /igbinary-2.0.6.tgz && \
rm -rf /igbinary-2.0.6

# 安装memcached 依赖库msgpack http://pecl.php.net/package/msgpack
RUN cd / && wget http://pecl.php.net/get/msgpack-2.0.2.tgz && \
tar -zxvf msgpack-2.0.2.tgz && \
cd msgpack-2.0.2 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && make install && \
echo "extension=msgpack.so">>/usr/local/php/lib/php.ini && \
rm -f /msgpack-2.0.2.tgz && \
rm -rf /msgpack-2.0.2

# 安装redis依赖库hiredis https://github.com/redis/hiredis/releases
RUN cd / && wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz && \
tar -zxvf v0.13.3.tar.gz && \
cd hiredis-0.13.3/ && \
make && make install && \
ldconfig && \
rm -f /v0.13.3.tar.gz && \
rm -rf /hiredis-0.13.3

# 安装redis https://github.com/phpredis/phpredis/releases
RUN cd / && wget https://github.com/phpredis/phpredis/archive/4.1.0RC1.tar.gz && \
tar -zxvf 4.1.0RC1.tar.gz && \
cd phpredis-4.1.0RC1/ && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && \
make install && \
echo "extension=redis.so">>/usr/local/php/lib/php.ini && \
rm -f /4.1.0RC1.tar.gz && \
rm -rf /phpredis-4.1.0RC1

# 安装 http2依赖库 nghttp2 https://github.com/nghttp2/nghttp2/releases/
RUN cd / && wget https://github.com/nghttp2/nghttp2/releases/download/v1.32.0/nghttp2-1.32.0.tar.gz && \
tar -zxvf nghttp2-1.32.0.tar.gz && \
cd nghttp2-1.32.0/ && \
./configure && \
make && make install && \
rm -f /nghttp2-1.32.0.tar.gz && \
rm -rf /nghttp2-1.32.0

# 安装swoole https://github.com/swoole/swoole-src/releases
RUN cd / && wget https://github.com/swoole/swoole-src/archive/v4.0.0.tar.gz && \
tar -zxvf v4.0.0.tar.gz && \
cd swoole-src-4.0.0/ && \
/usr/local/php/bin/phpize && \
./configure --enable-sockets --enable-openssl --enable-http2 --enable-async-redis --enable-timewheel --enable-mysqlnd --enable-coroutine --with-php-config=/usr/local/php/bin/php-config && \
make clean && make && make install && \
echo "extension=swoole.so">>/usr/local/php/lib/php.ini && \
echo "/usr/local/lib">>/etc/ld.so.conf && \
ldconfig && \
rm -f /v4.0.0.tar.gz && \
rm -rf /swoole-src-4.0.0

# 安装memcached 依赖库 libmemcached https://launchpad.net/libmemcached/
RUN cd / && wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz && \
tar -zxvf libmemcached-1.0.18.tar.gz && \
cd libmemcached-1.0.18 && \
./configure --prefix=/usr/local/libmemcached && \
make && make install && \
rm -f /libmemcached-1.0.18.tar.gz && \
rm -rf /libmemcached-1.0.18

# 安装http://pecl.php.net/package/memcached
RUN cd / && wget http://pecl.php.net/get/memcached-3.0.4.tgz && \
tar -zxvf memcached-3.0.4.tgz && \
cd memcached-3.0.4 && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-igbinary \
--enable-memcached-json --enable-memcached-msgpack && \
make && make install && \
echo "extension=memcached.so">>/usr/local/php/lib/php.ini && \
rm -f /memcached-3.0.4.tgz && \
rm -rf /memcached-3.0.4

# 安装 php screw plus https://codeload.github.com/del-xiong/screw-plus/zip/master
RUN cd / && wget https://codeload.github.com/del-xiong/screw-plus/zip/master && \
unzip master && \
cd /screw-plus-master && \
/usr/local/php/bin/phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config && \
make && \
cp /screw-plus-master/modules/php_screw_plus.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/ && \
echo "extension=php_screw_plus.so">>/usr/local/php/lib/php.ini && \
cd /screw-plus-master/tools && \
make && \
rm -f /master
#rm -rf /screw-plus-master

# 创建好挂载目录
RUN mkdir -p /data/php/log && mkdir -p /data/nginx/www

# 设置时区
RUN cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone

# 启动php服务
RUN chmod +x /usr/local/php/etc/php-fpm && /usr/local/php/etc/php-fpm start &

# 设置环境变量
ENV PATH=$PATH:/usr/local/php/etc:/usr/local/php/bin

#设置生成容器时需要执行的脚本
#ENTRYPOINT ["/usr/local/php/sbin/php-fpm"]
CMD [ "php-fpm", "start" ]

#开放9000端口
EXPOSE 9000
13 changes: 13 additions & 0 deletions docker_build/php7.2.6-redis-memcached-swoole/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## screw plus + php7.2.6 + redis + memcached + swoole
```
@author QQ群友 今日在线
@size 800MB
```
```
// 拉取:
docker pull pastyouth/php-screw-plus:php7.2.6-redis-memcached-swoole
// 运行:
docker run -p 9000:9000 -name web1 -v /data:/data/nginx/www screw-plus:php7.2.6-redis-memcached-swoole
// 进入容器
docker exec -it web1 /bin/sh
```
22 changes: 17 additions & 5 deletions php_screw_plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FILE *pm9screw_ext_fopen(FILE *fp)
memset(lenBuf, 0, 16);
fstat(fileno(fp), &stat_buf);
datalen = stat_buf.st_size;
datap = (char*)malloc(maxBytes);
datap = (char*)malloc(datalen + 16);
memset(datap, 0, sizeof(datap));
fread(datap, datalen, 1, fp);
fclose(fp);
Expand All @@ -58,20 +58,29 @@ FILE *pm9screw_ext_fopen(FILE *fp)
}
fp = tmpfile();

fwrite(datap, datalen, 1, fp);
if (datalen > 0) {
fwrite(datap, datalen, 1, fp);
} else {
fwrite(STRICT_MODE_ERROR_MESSAGE, strlen(STRICT_MODE_ERROR_MESSAGE), 1, fp);
}

free(datap);

rewind(fp);
return fp;
}

ZEND_API zend_op_array *(*org_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
ZEND_API zend_op_array *(*org_compile_file)(zend_file_handle *file_handle, int TSRMLS_DC);

ZEND_API zend_op_array *pm9screw_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
FILE *fp;
char fname[32];


if (!file_handle || !file_handle->filename || strstr(file_handle->filename, ".phar") || strstr(file_handle->filename, "phar://")) {
return org_compile_file(file_handle, type);
}

memset(fname, 0, sizeof fname);
if (zend_is_executing(TSRMLS_C)) {
if (get_active_function_name(TSRMLS_C)) {
Expand All @@ -94,7 +103,9 @@ ZEND_API zend_op_array *pm9screw_compile_file(zend_file_handle *file_handle, int
}

if (file_handle->type == ZEND_HANDLE_FP) fclose(file_handle->handle.fp);
if (file_handle->type == ZEND_HANDLE_FD) close(file_handle->handle.fd);
#ifdef ZEND_HANDLE_FD
if (file_handle->type == ZEND_HANDLE_FD) close(file_handle->handle.fd);
#endif
file_handle->handle.fp = pm9screw_ext_fopen(fp);
file_handle->type = ZEND_HANDLE_FP;

Expand Down Expand Up @@ -124,6 +135,7 @@ PHP_MINFO_FUNCTION(php_screw_plus)
{
php_info_print_table_start();
php_info_print_table_header(2, "php_screw_plus support", "enabled");
php_info_print_table_header(2, "php_screw_plus version", "0.11");
php_info_print_table_end();
}

Expand Down
Loading