详情页

新版phpjm混淆加密解密代码分析

时间:2024年05月07日

编辑:佚名

php解混淆加密:简单说明一下,具体是什么加密我也不知道,可能是phpjm2
此加密方式我也不知道叫啥,有的php解密平台显示phpjm2、zym、新版phpjm我也不知道是那个,知道的可以评论我改一下标题。
加密文件里面有#!/usr/bin/php -q标识和一堆类似于base64代码,以及混淆的乱码变量。
phpjm的函数变量命名都是 \$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* 这个范围的。
加密文件如下图:
使用说明:
把下面代码保存一个文件,与需要解密的文件放在同一个目录。
修改$finame使用文件名,使用浏览器访问保存的这个解密文件,会生成一个 “文件名.de.php”的新文件。
$filename='authorize'';//文件名 不要后缀
待加密的文件authorize.php,执行解密文件phpjm.php,会生成authorize.de.php
解密文件phpjm.php
<?php
$filename='authorize';//文件名 不要后缀
$str = file_get_contents("$filename.php");
preg_match_all('|[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*|', $str, $params) or die('err 1.');
$params = array_unique($params[0]); // 去重复
$replace = array();
foreach ($params as $k=>$v){
    if(preg_match('/[a-zA-Z_]+/',$v,$re)){//过滤掉正常的英文变量名
        unset($params[$k]);
        continue;
    }
    $replace[] = 'MD5_'.md5($v);
}
$str = str_replace($params, $replace, $str);
$file_url = str_replace("\\", "/", dirname(__FILE__))."/$filename.php";
$str = str_replace('__FILE__',"'$file_url'", $str);
$str = str_replace('return(eval(',"\$aaa=((", $str);
$str = str_replace(' ?>','return $aaa; ?>', $str);
$str = str_replace('<?php ','', $str);
$str_array = explode(' ?>',$str);
//print_r($str_array[0]);
$cc = eval($str_array[0]);
 
preg_match_all('|[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*|', $cc, $params) or die('err 1.');
$params = array_unique($params[0]); // 去重复
$replace2 = array();
foreach ($params as $k=>$v){
    if(preg_match('/[a-zA-Z_]+/',$v,$re)){//过滤掉正常的英文变量名
        unset($params[$k]);
        continue;
    }
    $replace2[] = 'MD5_'.md5($v);
}
$str = str_replace($params, $replace2, $cc);
//$str = str_replace('{', '{/*', $str);
//$str = str_replace('}', '*/}', $str);
$str = str_replace('return(eval(',"\$bbb=((", $str);
$str = str_replace(' ?>','return $bbb;', $str);
 
preg_match_all('|\@MD5\_[a-z0-9]{32}\(\);|', $str, $params) or die('cccc');
$params = array_unique($params[0]); // 去重复
$str = str_replace($params, 'NULL;', $str);
 
$dd = eval($str);
 
preg_match_all('|[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*|', $dd, $params) or die('err 1.');
$params = array_unique($params[0]); // 去重复
$replace3 = array();
foreach ($params as $k=>$v){
    if(preg_match('/[a-zA-Z_]+/',$v,$re)){//过滤掉正常的英文变量名
        unset($params[$k]);
        continue;
    }
    $replace3[] = 'MD5_'.md5($v);
}
$str = str_replace($params, $replace3, $dd);
$str = str_replace(';?><?php','<?php', $str);
 
preg_match_all('|MD5\_[a-z0-9]{32}\(\'.*?\',\'.*?\'\)|', $str, $params) or die('cccc');
$params1 = array_unique($params[0]); // 去重复
$replace_a1 = array();
foreach ($params1 as $v){
    eval("\$replace_a1[]=\"'\".".$v.".\"'\";");
}
$str = str_replace($params1, $replace_a1, $str);
 
//print_r($replace_a1);
//exit();
preg_match_all('|\$GLOBALS\[\'MD5\_[a-z0-9]{32}\'\]\[\'MD5\_[a-z0-9]{32}\'\]|', $str, $params) or die('cccc');
$params2 = array_unique($params[0]); // 去重复
 
$replace_a2 = array();
foreach ($params2 as $v){
    eval("\$replace_a2[]=".$v.";");
}
//print_r($replace_a2);
//exit();
$str = str_replace($params2, $replace_a2, $str);
 
//print_r($params2);
echo $str;
file_put_contents($filename.".de.php", $str);
echo 'Done.';
 
//print_r($GLOBALS);
 
//print_r($params);
//echo $str;
相关文章
猜你需要