您现在的位置是:博客首页 > 网站开发 > 网站开发
从php内核挂载钩子解密源码
 程序员之路2021-07-03【个人博客】人已围观
程序员之路2021-07-03【个人博客】人已围观
简介背景 大多数的php代码加密(不需要额外扩展就能运行的)原理上都是使用eval进行代码的执行,理论上,只要我们在php内核执行eval函数的时候,将其dump出来,就可以得到源代码。需要注意的是:
背景
大多数的php代码加密(不需要额外扩展就能运行的)原理上都是使用eval进行代码的执行,理论上,只要我们在php内核执行eval函数的时候,将其dump出来,就可以得到源代码。需要注意的是:
用户上传的代码是不可信的,因此需要一个沙盒此法虽然方便,看似是一个万能解密的办法,但是 dump 数据的时候会有很多中间值,还是需要人工的做一个特征库,去识别过滤出需要的代码段
实现
	在 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("----- [dephp.cn start] -----\n");
	    php_printf("%s\n", copy);
	    php_printf("----- [dephp.cn 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;
	}
很赞哦! ()
上一篇:OPCODE的功能列表
本栏推荐
 ModouCMS框架基础知识介绍
ModouCMS框架基础知识介绍标签云
猜你喜欢
站点信息
- 建站时间:2019-05-13
- 网站程序:魔豆CMS7.5
- 博客名称:程序员之路
- 文章统计:117 篇
- 源码统计:6 篇
- 访问统计:
- 微信公众号:扫描二维码,关注我们
 
      
 
           
           
           
           
           
          
