search
Homephp教程php手册浅谈PHP神盾的解密过程

浅谈PHP神盾的解密过程

Jun 06, 2016 pm 07:53 PM
linuxphpCommunityDecryptprocessEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 前些日子一个朋友丢了个shell给我,让我帮忙解密,打开源码看了下写着是 "神盾加密" , 其实网上早就有人分析过这个了,而且写成了工具、但是我测试了很多个,没一个能用,所以决定自己从头分析一遍。

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  前些日子一个朋友丢了个shell给我,让我帮忙解密,打开源码看了下写着是 "神盾加密" , 其实网上早就有人分析过这个了,而且写成了工具、但是我测试了很多个,没一个能用,所以决定自己从头分析一遍。

  我们来做第一步解密处理吧。

  PS: 这只是我的解密思路,与大家分享一下,也许你有更好的方法还望分享

  

  $str = file_get_contents("1.php");

  // 第一步 替换所有变量

  // 正则 \$[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*

  preg_match_all('|\$[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*|', $str, $params) or die('err 0.');

  $params = array_unique($params[0]); // 去重复

  $replace = array();

  $i = 1;

  foreach ($params as $v) {

  $replace[] = '$p' . $i;

  tolog($v . ' => $p' . $i); // 记录到日志

  $i++;

  }

  $str = str_replace($params, $replace, $str);

  // 第二步 替换所有函数名

  // 正则 function ([a-zA-Z_\x7f-\xff][\w\x7f-\xff]*)

  preg_match_all('|function ([a-zA-Z_\x7f-\xff][\w\x7f-\xff]*)|', $str, $params) or die('err 0.');

  $params = array_unique($params[1]); // 去重复

  $replace = array();

  $i = 1;

  foreach ($params as $v) {

  $replace[] = 'fun' . $i;

  tolog($v . ' => fun' . $i); // 记录到日志

  $i++;

  }

  $str = str_replace($params, $replace, $str);

  // 第三步 替换所有不可显示字符

  function tohex($m) {

  $p = urlencode($m[0]); // 把所有不可见字符都转换为16进制、

  $p = str_replace('%', '\x', $p);

  $p = str_replace('+', ' ', $p); // urlencode 会吧 空格转换为 +

  return $p;

  }

  $str = preg_replace_callback('|[\x00-\x08\x0e-\x1f\x7f-\xff]|s', "tohex", $str);

  // 写到文件

  file_put_contents("1_t1.php", $str);

  function tolog($str) {

  file_put_contents("replace_log.txt", $str . "\n", FILE_APPEND);

  }

  ?>

  (其中有一个记录到日志的代码,这个在之后的二次解密时有用。)

  执行之后就会得到一个 1_t1.php 文件,打开文件看到类似这样的代码

  找个工具格式化一下,我用的 phpstorm 自带了格式化功能,然后代码就清晰很多了。

  进一步整理后得到如下代码:

  

  //Start code decryption《===

  if (!defined('IN_DECODE_82d1b9a966825e3524eb0ab6e9f21aa7')) {

  define('\xA130\x8C', true);

  function fun1($str, $flg="") {

  if(!$flg) return(base64_decode($str));

  $ret = '?';

  for($i=0; $i

  $c = ord($str[$i]);

  $ret .= $c136 ? chr($c/2) : $str[$i] ) : "";

  }

  return base64_decode($ret);

  }

[1] [2] 

浅谈PHP神盾的解密过程

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor