通过hook eval解密混淆的PHP文件

hook eval

PHP中的eval函数在Zend里需要调用zend_compile_string函数,我们写一个拓展直接hook这个函数就行了。不过我不会写c代码,所以参考网上的文章,在GitHub中找到了现成的一个拓展库。

https://github.com/bizonix/evalhook 需要编译

编译好的hook: https://pan.baidu.com/s/1Q0ADl0i7po5lOD7Ly9Dc_w 提取码: 3e2p

static zend_op_array *evalhook_compile_string(zval *source_string, char *filename TSRMLS_DC)
{
        int c, len, yes;
        char *copy;

        /* Ignore non string eval() */
        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("n--------- Decrypt start ------------n");
        php_printf(copy);
        php_printf("n--------- Decrypt done ------------n");
        return orig_compile_string(source_string, filename TSRMLS_CC);

}

centos php5.6+apache 然后运行

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum install --enablerepo=remi --enablerepo=remi-php56 php-devel

phpize && ./configure && make

将 evalhook/modules/evalhook.so 拷贝到 php 的拓展目录下,并且向php.ini中添加

extension=evalhook.so

重新启动apache之后,可以通过web访问php文件,会直接打印出源码。