2010年7月7日 星期三

PHP Obfuscator

若是不想要PHP的原始碼讓別人看到, 可以使用open source的PHP Screw, 以下是1.5的安裝步驟:

0.系統需求
PHP 5.x的環境
具有zlib的支援(可透過<?php gzopen(); ?>來檢查)

1.解壓縮
修改my_screw.h, 裡面的數字就是seed, 可視為密碼

2.編譯成so
$ phpize
$ ./configure –with-php-config=/path/to/php-config
$ make

若發生錯誤如
/path/to/php_screw-1.5/php_screw.c:78: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:84: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:91: error: too few arguments to function 'org_compile_file'
/path/to/php_screw-1.5/php_screw.c:93: error: too few arguments to function 'org_compile_file'
從官方bug列表找到解決方法:
modify php_screw.c
org_compile_file(file_handle, type);
to
org_compile_file(file_handle, type TSRMLS_CC);

或發生錯誤如
/path/to/php_screw-1.5/php_screw.c: In function 'zm_startup_php_screw':
/path/to/php_screw-1.5/php_screw.c:124: error: 'zend_compiler_globals' has no member named 'extended_info'
/path/to/php_screw-1.5/php_screw.c: In function 'zm_shutdown_php_screw':
/path/to/php_screw-1.5/php_screw.c:133: error: 'zend_compiler_globals' has no member named 'extended_info'
閱讀source後
modify php_screw.c
CG(extended_info) = 1;
to
// CG(extended_info) = 1;

3.修改php.ini設定
[php_screw]
extension=php_screw.so

4.編譯混淆器
$ cd tools $ make )

5.使用(對foo.php做混淆)
$ ./tools/screw foo.php
$ Success Crypting(foo.php)

若要對多個檔案進行混淆,可以簡單的使用兩行指令搞定
$ find . -name "*.php" -exec /path/to/tools/screw -exec {} \;
$ find . -name "*.screw" -exec rm -f {} ;

注意, 混淆過的檔案, 對方主機需安裝php_screw才能讀取, 所以虛擬主機類的應該就沒辦法用這一招了...

參考資料:
* 使用自由加密軟件PHP screw對PHP源碼加密
* 用php_screw加密PHP代碼

沒有留言: