php 钩子 源码,从 php 内核挂载钩子解密源码

背景

大多数的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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值