大多數的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<len; c++) if (copy[c] == 0) copy[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; }