php_screw 1.5:php加密: 安装与使用详解
php文件通常以文本格式存贮在服务器端, 很容易被别人读到源代码, 为了对源代码进行保护, 可以采用对源代码进行加密的方式.要实现该功能需要两部分:
一是加密程序,实现对PHP文件的加密. 另一个就是对加密过的PHP文件进行解析, 以得到运行结果. 前者的实现比较简单, 就是一程序而已. 后者的实现大部分都是通过php module的形式来实现的.
php_screw(螺丝钉)可以实现以上的功能.最新版本是1.5,可以在sourceforge上下载.
安装:
安装的目的其实就是产生两个文件:一个是用于加密PHP文件的screw, 另一个就是php加载的解析模块php_screw.so
1.将源代码包展开, 并进入该入目录:
2. 执行phpize, 就会在该目录下产生一个configure
3. 然后,运行configure
4. 再make
这样, 解析用的php_screw.so就生成了. 接下来要得到加密用的screw
1. 进入源码的tools目录
2. make
这样就生成了screw了. 如果要加密一个lx.php文件, 则: screw lx.php, lx.php就变成加密的了, 原来明文的lx.php被改名为lx.php.screw
接下来的任务就应该是加载php_screw.so模块了,
首先, 将该文件COPY到module目录下, 具体是哪个目录,可以参见/etc/php.ini配置文件中的extension_dir项,RHEL 5中为/usr/lib/php/modules
方法一:可以在/etc/php.d目录下新建一个screw.ini文件(文件是可以任意取的),其内容是一句话extension=php_screw.so
方法二:通过修改php.ini文件, 增加了一句extension=php_screw.so, 重启apache后就成功了.
重要说明:
编译的.so文件理论上跟你当前的php版本是相关的,也就是说,如果你是在php 5.1下编译的,就不能拿到php 5.2下去用,因为php的可加载模块总是与其版本相关的.而加密用的screw可执行文件理论上讲无所谓,只有他跟screw.so属于同一个版本就可以
测试:
编写一个hello, world程序,文件名为hello.php如下:
复制代码 代码如下:
"Hello,world";
?>
用php hello.php测试程序是否能成功显示, 成功显示后, 用screw对其进行加密(screw helllo.php), 然后cat一下该php文件, 发现已经不是文本的了, 变成了许多乱字符, 说明加秘成功, 然后再php hello.php, 如果能正常显示hello,world, 则说明加密的解析也没有问题了, 一切就算OK了.否则, 就说明还有不对的地方, 需要再仔细检查.
安装过程中遇到的问题:
1.找不到phpize
phpize是属于php-develp的一个工具, (具体作用请自行解决) 因此, 必须要安装php-develp包. 中间有一些依赖, 如下:
复制代码 代码如下:
[root@localhost Server]# rpm -ivh php-devel-5.1.6-5.el5.i386.rpm
warning: php-devel-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
autoconf is needed by php-devel-5.1.6-5.el5.i386
automake is needed by php-devel-5.1.6-5.el5.i386
[root@localhost Server]# rpm -ivh autoconf
autoconf213-2.13-12.1.noarch.rpm autoconf-2.59-12.noarch.rpm
[root@localhost Server]# rpm -ivh autoconf-2.59-12.noarch.rpm
warning: autoconf-2.59-12.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
imake is needed by autoconf-2.59-12.noarch
[root@localhost Server]# rpm -ivh imake-1.0.2-3.i386.rpm
warning: imake-1.0.2-3.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:imake ########################################### [100%]
[root@localhost Server]# rpm -ivh autoconf-2.59-12.noarch.rpm
warning: autoconf-2.59-12.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:autoconf ########################################### [100%]
[root@localhost Server]# rpm -ivh automake
automake14-1.4p6-13.noarch.rpm automake16-1.6.3-8.noarch.rpm automake-1.9.6-2.1.noarch.rpm
automake15-1.5-16.noarch.rpm automake17-1.7.9-7.noarch.rpm
[root@localhost Server]# rpm -ivh automake-1.9.6-2.1.noarch.rpm
warning: automake-1.9.6-2.1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:automake ########################################### [100%]
[root@localhost Server]# rpm -ivh php-devel-5.1.6-5.el5.i386.rpm
warning: php-devel-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:php-devel ########################################### [100%]
2.每个加密的文件头部都一个很明显的字符串PM9SCREW, 这样很容易被人猜到是用screw加密的.
这个问题的解决需要在安装的第一步就开始. 该标识串在源码的php_screw.h中. 在编译之前, 可以更改这个字符串, 例如,更改为PeterHu, 相应的下面的长度就不再是10了, 而是\tPeterHu\t,一共7个了.
复制代码 代码如下:
#define PM9SCREW "\tPM9SCREW\t"
#define PM9SCREW_LEN 10
==================================================================================
网上看了好多PHP_SCREW安装文章.也看过好几次源码报里的READEME.
真折腾,要么脚本方式执行不了,要么网页无法显示.经过不屈不挠的折腾终于折腾出来了......分享以下方法...若有大虾知道具体原因不妨指点一二.
PS:CentOS release 5.8 (Final),php5.2.x
下载php-screw-1.5,若是php4用php-screw-1.3
源码包:http://sourceforge.net/projects/php-screw/files/latest/download?source=files
源码包放到/usr/local下,开始安装咯
1.tar -zxvf php_screw-1.5.tar.gz(出来permission之类错误就加sudo)
2.cd php_screw_1.5
3.phpize(执行不了就写phpize的绝对路径,装好了的前提下)
4.vi my_screw.h(里面是密码,想改就改,最好不要超过5位数,若改了要记好,因为重新编译时要用)
5.vi php_screw.h(里面是加密字符串,默认是PM9SCREW,最好改成别的字符串,字符串变了下面长度也要跟着变,改成LOVE的话长度就是6了,字符串要记下)
6. ./configure
7. make && make install
成功了会输出:Installing shared extensions: /usr/lib64/php/modules/(这个目录是/etc下php.ini里extension_dir指定的目录).php_screw.so文件就在这里,当然编译目录的modules下也有.
8. cd tools/
9. make
这样生成了加密用的程序screw了
10. cp screw /usr/bin下
这样加密的时候可以直接screw 文件名了,不用写screw的路径
11.修改ini
cd /etc/php.d(这里是php.ini加载的各种扩展可以在这写,打开别的文件看看就知道了)
vi php_screw.ini
里面写上extension=php_screw.so保存退出
12.重启apache
在根目录下创建hello.php
php hello.php
输出:hello
screw hello.php
输出:Success Crypting(hello.php),说明加密成功,目录下会多出一个文件hello.php.screw,现在的hello.php已经是加密过的了,而多出的则是源文件的备份.
cat hello.php显示乱码.
php hello.php 输出hello.脚本方式解析加密文件成功了.
在根目录下建立phpinfo,里面若有php_screw扩展相关信息就说明可以通过浏览器访问加密的文件了.不用继续往下看了.我是有两个php.ini,网页跟脚本方式调用的ini不同.
接下来要重新编译一次了,为了可以在网页里正常显示.
1.去编译目录
make clean
然后把目录给删了.
2.tar -zxvf php_screw.1.5.tar.gz重新解压
3. phpize
4. myscrew.h跟php_screw.h里的密码跟字符串记得要跟之前的一样
5. ./configure --with-php-config=php-config路径(php安装目录下有)
6.make && make install
输出:Installing shared extensions: /var/www/php5/lib/php/extensions/no-debug-non-zts-20060613/
(这次php_screw.so在这个目录下咯)
7.php_screw.so复制到phpinfo里extension_dir指定的目录,我的是/var/www/modules下
8.修改php.ini(php安装目录下的,phpinfo里会显示载入的是哪个ini,就改那个)
在最下方添加extension=php_scrw.so
9.重启apache
10.在phpinfo里看看有木有php_screw相关信息,有的话就ok了~
至此,安装结束了,虽然有点点头绪,但我还是没太搞明白为什么得这样编译两次才行......
PS:编译过程中碰见的几个问题如下(解决方法)
1。 /root/php_screw-1.5/php_screw.c: In function ‘pm9screw_compile_file':
解决方法:
需要修改php_screw.c
把第78,84,93行的org_compile_file(file_handle, type);
修改为:
org_compile_file(file_handle, type TSRMLS_CC);
然后再make就成功了。
2. /opt/soft/php_screw-1.5/php_screw.c: In function ‘zm_startup_php_screw':/opt/soft/php_screw-1.5/php_screw.c:124: 错误:‘zend_compiler_globals' 没有名为 ‘extended_info' 的成员/opt/soft/php_screw-1.5/php_screw.c: In function ‘zm_shutdown_php_screw':/opt/soft/php_screw-1.5/php_screw.c:133: 错误:‘zend_compiler_globals' 没有名为 ‘extended_info' 的成员make: *** [php_screw.lo] 错误 1
解决方法:
需要修改php_screw.c
把CG(extended_info) = 1;
修改为:
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
php_screw如何对当前目录下,对目录下包含的文件,以及包含目录下的文件进行整体加密
find ./ -name "*.php" -print|xargs -n1 screw //加密所有的.php文件
find ./ -name "*.screw" -print/xargs -n1 rm //删除所有的.php源文件的备份文件
命令都实验过成功的.........应该没什么再补充的咯.....

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.
