Home Backend Development PHP Tutorial php_screw 1.5:php encryption: detailed explanation of installation and use_PHP tutorial

php_screw 1.5:php encryption: detailed explanation of installation and use_PHP tutorial

Jul 21, 2016 pm 03:04 PM
php and use encryption exist Install document text server Format end Detailed explanation Pass

PHP files are usually stored on the server side in text format, and the source code can easily be read by others. In order to protect the source code, the source code can be encrypted. To implement this function, two parts are required:

One is an encryption program to encrypt PHP files. The other is to parse the encrypted PHP files to get the running results. The implementation of the former is relatively simple, it is just a program. Most of the implementations of the latter are It is implemented in the form of php module.

php_screw (screw) can achieve the above functions. The latest version is 1.5, which can be downloaded from sourceforge.
Installation:
The purpose of installation is actually to generate two files: one is screw for encrypting PHP files, and the other is the parsing module loaded by php php_screw.so
1. Expand the source code package and enter Enter the directory:
2. Execute phpize, and a configure
3 will be generated in this directory. Then, run configure
4. Then make
In this way, the php_screw used for analysis is used. so is generated. Next, you need to get the encryption screw
1. Enter the tools directory of the source code
2. make
This way, screw is generated. If you want to encrypt an lx.php file , then: screw lx.php, lx.php becomes encrypted, and the original plain text lx.php is renamed lx.php.screw
The next task should be to load the php_screw.so module,
First, copy the file to the module directory. For the specific directory, please refer to the extension_dir item in the /etc/php.ini configuration file. In RHEL 5, it is /usr/lib/php/modules
Method 1: You can create a new screw.ini file in the /etc/php.d directory (the file can be taken at will), the content of which is one sentence extension=php_screw.so
Method 2: Modify the php.ini file, add extension=php_screw.so, and restart apache and it will be successful.
Important note:
The compiled .so file is theoretically related to your current PHP version. That is to say, if you compiled it under PHP 5.1, you cannot get PHP 5.2 to use it, because PHP Loadable modules are always version-specific. Theoretically, the screw executable file used for encryption does not matter, as long as it and screw.so belong to the same version.
Test:
Write a hello, world program, file The name hello.php is as follows:

Copy the code The code is as follows:

"Hello, world ";
?>

Use php hello.php to test whether the program can be successfully displayed. After it is successfully displayed, use screw to encrypt it (screw helllo.php), and then cat the program. php file, it is found that it is no longer text, but has become a lot of garbled characters, indicating that the encryption is successful, and then php hello.php. If hello and world can be displayed normally, it means that there is no problem with the encryption analysis, and everything is OK. Otherwise, it means there is something wrong and you need to check it carefully.
Problems encountered during the installation process:
1. Cannot find phpize
phpize is a tool that belongs to php-develp, (please figure out the specific function by yourself) Therefore, you must install the php-develp package. There are some dependencies in the middle, as follows:
Copy code The code is as follows:

[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了, 而是tPeterHut,一共7个了.
复制代码 代码如下:

#define PM9SCREW        "tPM9SCREWt"
#define PM9SCREW_LEN     10

================================================== ===================================
I have read a lot of PHP_SCREW installation articles on the Internet. I have also read several README.
in the source code report is really frustrating, either the script cannot be executed, or the web page cannot be displayed. After unremitting tossing, I finally figured it out... Share the following method... If anyone knows the details You might as well give some advice on the reasons.
PS: CentOS release 5.8 (Final), php5.2.x
Download php-screw-1.5, if php4 use php-screw-1.3
Source code package: http://sourceforge.net/projects/php-screw/files/latest/download?source=files
Put the source code package under /usr/local and start the installation
1.tar -zxvf php_screw-1.5.tar.gz (Add sudo if there is an error such as permission)
2.cd php_screw_1.5
3.phpize (If it cannot be executed, write the absolute path of phpize, assuming it is installed)
4.vi my_screw.h (It contains the password, change it if you want. It is best not to exceed 5 digits. If you change it, remember it because it will be used when recompiling)
5.vi php_screw.h( There is an encrypted string inside. The default is PM9SCREW. It is best to change it to another string. If the string changes, the length will also change. If it is changed to LOVE, the length will be 6. The string should be written down)
6. ./configure
7. make && make install
If successful, it will output: Installing shared extensions: /usr/lib64/php/modules/ (this directory is the directory specified by extension_dir in php.ini under /etc). The php_screw.so file is here, of course it is also under the modules of the compilation directory.
8. cd tools/
9. make
In this way, the encryption program screw is generated
10. cp screw / Under usr/bin
In this way, when encrypting, you can screw the file name directly without writing the screw path
11. Modify ini
cd /etc/php.d (here are the various files loaded by php.ini Extensions can be written here, just open other files and you will know)
vi php_screw.ini
Write extension=php_screw.so in it, save and exit
12. Restart apache
In the root directory Create hello.php

php hello.php
Output: hello
screw hello.php
Output: Success Crypting(hello.php) , indicating that the encryption is successful, there will be an extra file hello.php.screw in the directory. The current hello.php has been encrypted, and the extra file is a backup of the source file.
cat hello.php displays garbled characters .
php hello.php outputs hello. The script method successfully parsed the encrypted file.
Create phpinfo in the root directory. If there is information related to the php_screw extension, it means that the encrypted file can be accessed through the browser. No need to continue. Look down. I have two php.ini. The web page and the ini called by the script are different.
Next, I need to recompile it so that it can be displayed normally on the web page.
1. Go to the compilation directory
make clean
Then delete the directory.
2.tar -zxvf php_screw.1.5.tar.gz Re-decompress
3. phpize
4. myscrew.h and php_screw.h The password and string must be the same as before
5. ./configure --with-php-config=php-config path (available in the php installation directory)
6.make && make install
Output: Installing shared extensions: /var/www/php5/lib/php/extensions/no-debug-non-zts-20060613/
(This time php_screw.so is in this directory)
7. Copy php_screw.so to the directory specified by extension_dir in phpinfo, mine is under /var/www/modules
8. Modify php.ini (in the php installation directory, phpinfo will show which ini is loaded, just Change that)
Add extension=php_scrw.so at the bottom
9. Restart apache
10. Check if there is any php_screw related information in phpinfo, if there is, it will be ok ~
That’s it , the installation is over. Although I have some clues, I still don’t quite understand why it has to be compiled twice...
PS: Several problems encountered during the compilation process As follows (solution)
1. /root/php_screw-1.5/php_screw.c: In function 'pm9screw_compile_file':
Solution:
Need to modify php_screw.c
to 78, 84, 93 The line org_compile_file(file_handle, type);
is modified to:
org_compile_file(file_handle, type TSRMLS_CC);
and then make succeeds.
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: Error: 'zend_compiler_globals' No member named '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: Error: 'zend_compiler_globals' has no member named 'extended_info' member make: *** [php_screw.lo] Error 1
Solution:
Need to modify php_screw.c
Put CG(extended_info) = 1;
Modify to:
CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
How php_screw encrypts the current directory, the files contained in the directory, and the files in the containing directory as a whole
find ./ -name "*.php" -print|xargs -n1 screw //Encrypt all .php files
find ./ -name "*.screw" -print/xargs -n1 rm //Delete all The backup file
command of the .php source file has been successfully tested... There should be nothing to add...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327735.htmlTechArticlephp files are usually stored in text format on the server side, and the source code can easily be read by others. In order to verify the source code To protect the code, you can encrypt the source code. To achieve this function...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

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

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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 PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

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.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

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.

See all articles