背景
大多数的php代码加密(不须要额外扩展就能运行的)原理上都是使用eval进行代码的执行,理论上,只要咱们在php内核执行eval函数的时候,将其dump出来,就能够获得源代码。须要注意的是:php
用户上传的代码是不可信的,所以须要一个沙盒 此法虽然方便,看似是一个万能解密的办法,可是 dump 数据的时候会有不少中间值,仍是须要人工的作一个特征库,去识别过滤出须要的代码段c++
实现
在 php 扩展中, module init 的时候替换掉 zend_compile_string,主要代码以下函数
static zend_op_array *edump_compile_string(zval *source_string, char *filename TSRMLS_DC)
{
int c, len;
char *copy;
if (Z_TYPE_P(source_string) != IS_STRING) {
return orig_compile_string(source_string, filename TSRMLS_CC);
}
len = Z_STRLEN_P(source_string);
copy = estrndup(Z_STRVAL_P(source_string), len);
if (len > strlen(copy)) {
for (c=0; c
}
php_printf("----- [tool.lu start] -----\n");
php_printf("%s\n", copy);
php_printf("----- [tool.lu end] -----\n");
yes = 1;
return orig_compile_string(source_string, filename TSRMLS_CC);
}
PHP_MINIT_FUNCTION(edump)
{
if (edump_hooked == 0) {
edump_hooked = 1;
orig_compile_string = zend_compile_string;
zend_compile_string = edump_compile_string;
}
return SUCCESS;
}