• Stars
    star
    1,665
  • Rank 27,931 (Top 0.6 %)
  • Language
    C
  • Created over 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP source code encrypt module (PHP源码加密扩展)
        ____  __  ______     ____  _________   ___________
       / __ \/ / / / __ \   / __ )/ ____/   | / ___/_  __/
      / /_/ / /_/ / /_/ /  / __  / __/ / /| | \__ \ / /
     / ____/ __  / ____/  / /_/ / /___/ ___ |___/ // /
    /_/   /_/ /_/_/      /_____/_____/_/  |_/____//_/

贡献者名字:
@imaben (windows版本提供者)  https://github.com/imaben
@pinguo-niulingyun (PHP7版本提供者) https://github.com/pinguo-niulingyun

QQ交流群:239243332

Windows DLL:下载地址

php-beast可以自定义加密模块,加密模块编写教程: 点击

编译安装如下:


$ wget https://github.com/liexusong/php-beast/archive/master.zip
$ unzip master.zip
$ cd php-beast-master
$ phpize
$ ./configure
$ sudo make && make install

编译好之后修改php.ini配置文件, 加入配置项: extension=beast.so, 重启php-fpm

温馨提示: 可以设置较大的缓存提高效率

使用php-beast的性能:

不使用php-beast的性能:

配置项:


 beast.cache_size = size
 beast.log_file = "path_to_log"
 beast.log_user = "user"
 beast.log_level = "debug"
 beast.enable = On

beast.log_level支持参数:

 1. DEBUG
 2. NOTICE
 3. ERROR

支持的模块有:

 1. AES
 2. DES
 3. Base64

通过测试环境:


 Nginx + Fastcgi + (PHP-5.2.x ~ PHP-7.1.x)

怎么加密项目

加密方案1

安装完 php-beast 后可以使用 tools 目录下的 encode_files.php 来加密你的项目。使用 encode_files.php 之前先修改 tools 目录下的 configure.ini 文件,如下:

; source path
src_path = ""

; destination path
dst_path = ""

; expire time
expire = ""

; encrypt type (selection: DES, AES, BASE64)
encrypt_type = "DES"

src_path 是要加密项目的路径,dst_path 是保存加密后项目的路径,expire 是设置项目可使用的时间 (expire 的格式是:YYYY-mm-dd HH:ii:ss)。encrypt_type是加密的方式,选择项有:DES、AES、BASE64。 修改完 configure.ini 文件后就可以使用命令 php encode_files.php 开始加密项目。

加密方案2

使用beast_encode_file()函数加密文件,函数原型如下:
beast_encode_file(string $input_file, string $output_file, int expire_timestamp, int encrypt_type)

1. $input_file: 要加密的文件
2. $output_file: 输出的加密文件路径
3. $expire_timestamp: 文件过期时间戳
4. $encrypt_type: 加密使用的算法(支持:BEAST_ENCRYPT_TYPE_DES、BEAST_ENCRYPT_TYPE_AES)

制定自己的php-beast

php-beast 有多个地方可以定制的,以下一一列出:

1. 使用 header.c 文件可以修改 php-beast 加密后的文件头结构,这样网上的解密软件就不能认识我们的加密文件,就不能进行解密,增加加密的安全性。

2. php-beast 提供只能在指定的机器上运行的功能。要使用此功能可以在 networkcards.c 文件添加能够运行机器的网卡号,例如:

char *allow_networkcards[] = {
	"fa:16:3e:08:88:01",
    NULL,
};

这样设置之后,php-beast 扩展就只能在 fa:16:3e:08:88:01 这台机器上运行。另外要注意的是,由于有些机器网卡名可能不一样,所以如果你的网卡名不是 eth0 的话,可以在 php.ini 中添加配置项: beast.networkcard = "xxx" 其中 xxx 就是你的网卡名,也可以配置多张网卡,如:beast.networkcard = "eth0,eth1,eth2"

3. 使用 php-beast 时最好不要使用默认的加密key,因为扩展是开源的,如果使用默认加密key的话,很容易被人发现。所以最好编译的时候修改加密的key,aes模块 可以在 aes_algo_handler.c 文件修改,而 des模块 可以在 des_algo_handler.c 文件修改。


开启debug模式

可以在configure时加上 --enable-beast-debug 选项来开启debug模式。开启debug模式后需要在php.ini配置文件中加入配置项:beast.debug_pathbeast.debug_modebeast.debug_mode 用于指定是否使用debug模式,而 beast.debug_path 用于输出解密后的php脚本源码。这样就可以在 beast.debug_path 目录中看到php-beast解密后的源代码,可以方便知道扩展解密是否正确。

开启禁止执行未加密的脚本

可以在configure时加上 --enable-execute-normal-script=off 选项来禁止执行未加密的PHP脚本。


函数列表

1. beast_encode_file(): 用于加密一个文件

2. beast_avail_cache(): 获取可以缓存大小

3. beast_support_filesize(): 获取beast支持的最大可加密文件大小

4. beast_file_expire(): 获取一个文件的过期时间

5. beast_clean_cache(): 清空beast的所有缓存(如果有文件更新, 可以使用此函数清空缓存)


常见问题

1. linux:如果出现502错误,一般是由于GCC版本太低导致,请先升级GCC再安装本模块。

2. Windows:IIS环境下FastCGI进程异常退出:尝试将IIS的运行用户从ApplicationPoolIdentity改为LocalSystem


我们的公众号


More Repositories

1

linux-source-code-analyze

Linux内核源码分析
936
star
2

atom

PHP unique ID generator
C
188
star
3

mx-queued

a fast and simple message queue server
C
87
star
4

ukg

Unique Key Generate Server
C
82
star
5

bolt

Bolt - The Realtime Image Compress System
C
50
star
6

pcache

PHP local cache
C
48
star
7

CuteDB

Tiny DB implements in PHP
PHP
40
star
8

ptask

libtask extension for php
C
20
star
9

blockchain-php

Blockchain implementation in PHP
PHP
16
star
10

jhttpd

A simple HTTP server for study HTTP protocol
C
16
star
11

JustKit

A C language ToolKit which simple and easy to use
C
15
star
12

php-fastcgi-client

PHP FastCGI client
C
12
star
13

linux-2.4.0

Linux 2.4.0 source code reading notes
C
10
star
14

tdb

Tiny debugger
C
9
star
15

understanding-the-linux-networking

Linux 网络协议栈源码分析
8
star
16

nginx-0.1.0-comments

Add some comments for nginx-0.0.1
C
8
star
17

sensitive-filter-server

Sensitive Word Filter Server
Go
7
star
18

lcache

Golang local cache implements
Go
7
star
19

synflood

C
7
star
20

linux-kernel-analyze

6
star
21

understanding-the-linux-memory-manager

完全理解Linux内存管理
6
star
22

gobenchmark

Go
5
star
23

fast-log

FastLog is a PHP extension for asynchronous logger
C
5
star
24

linux-1.1.0

linux-v.1.1.0 源码分析
C
5
star
25

tcp-ip-stack

TCP/IP stack source code analyze, base on Linux-1.0
C
4
star
26

php-queue

C
3
star
27

tinychain

A tiny blockchain supporting free transactions and state modification experimentally.
Go
3
star
28

go-redis-server

Redis server implement by Golang
Go
3
star
29

cartoon

save call stack when PHP process exception exit
C
2
star
30

canon

A fast and simple web server implemented by C
C
2
star
31

understanding-the-linux-filesystem

2
star
32

linux-0.11-comments

Linux version 0.11 comments
C
2
star
33

simple_encrypt

A simple encrypt and decrypt PHP's extension.
C
2
star
34

tinytcp

C
2
star
35

nginx-0.5.0

C
2
star
36

open-source-reading-comments

open source reading comments
C
2
star
37

tiny-os

My tiny OS
C
1
star
38

web-server-by-go

1
star
39

mujs

copy from http://mujs.com/
C
1
star
40

linux-2.6.26

C
1
star
41

b-tree

b+tree
C
1
star
42

linux-v1.0-comments

Comments for Linux-v1.0
C
1
star
43

build-strace-by-myself

C
1
star
44

linux-kernel-analysis

分享Linux内核的一些有趣知识点
1
star
45

golib

Go library for myself
Go
1
star
46

Linux-1.3.28

C
1
star
47

ucip

C
1
star
48

php-webp

extension for PHP change JPEG/PNG to WebP
Shell
1
star
49

dune

C
1
star
50

ucore

清华大学操作系统课程的ucore os
C
1
star
51

lwip-copy

copy from lwip http://savannah.nongnu.org/projects/lwip/
C
1
star
52

TinyFramework

A tiny PHP MVC framework
1
star
53

Linux-2.4.16

C
1
star
54

tinixdev

Copy from http://code.taobao.org/svn/tinixdev/
C
1
star
55

firebee

Very simple unique ID generator, using HTTP protocol
C
1
star
56

jvm

JVM implementation by Golang
Go
1
star
57

regex-RussCox

C
1
star
58

java-study

Java study
1
star
59

phoenix

PHP extension for HTTP server
C
1
star