Home  >  Article  >  Backend Development  >  Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:511042browse

In fact, someone on the Internet has already analyzed this and written it as a tool. However, I tested many and none of them worked, so I decided to analyze it from the beginning.

Open the Aegis encrypted source code and you can see code like this

Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

It has advertising comments written on it and cannot be deleted because there is an md5 verification code at the end of the file to verify whether the code has been modified, as shown in the picture,

Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

Looking carefully at the code part, I found that it is full of garbled characters. In fact, this is all a deception.
It uses php variables to expand to the latin1 character range, and its variable matching regularity is $[a-zA-Z_x7f-xff] [wx7f-xff]* Such format.
This has been analyzed a few days ago, and I finally found the answer on the official website. Please see "Aegis Encryption and Decryption Tutorial (1) Available Characters for PHP Variables "

It’s a bit far-fetched, let’s do the first step of decryption.
PS: This is just my decryption idea. I want to share it with you. Maybe you have a better method and would like to share it. .

Copy code The code is as follows:

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

//The first step is to replace all variables
// Regular $[a-zA-Z_x7f-xff][wx7f-xff]*
preg_match_all('|$[a-zA-Z_x7f-xff] [wx7f-xff]*|', $str, $params) or die('err 0.');
$params = array_unique($params[0]); // Remove duplicates
$replace = array();
$i = 1;
foreach ($params as $v) {
$replace[] = '$p' . $i;
tolog($v . ' = > $p' . $i); // Record to log
$i++;
}
$str = str_replace($params, $replace, $str);


// The second step is to replace all function names
// Regular function ([a-zA-Z_x7f-xff][wx7f-xff]*)
preg_match_all('|function ([a -zA-Z_x7f-xff][wx7f-xff]*)|', $str, $params) or die('err 0.');
$params = array_unique($params[1]); // Deduplication
$replace = array();
$i = 1;
foreach ($params as $v) {
$replace[] = 'fun' . $i;
tolog($v . ' => fun' . $i); // Record to log
$i++;
}
$str = str_replace($params, $replace, $str);

// The third step is to replace all non-displayable characters
function tohex($m) {
$p = urlencode($m[0]); // Convert all invisible characters to hexadecimal System,
$p = str_replace('%', 'x', $p);
$p = str_replace('+', ' ', $p); // urlencode will convert spaces to +
return $p;
}
$str = preg_replace_callback('|[x00-x08x0e-x1fx7f-xff]|s', "tohex", $str);

//Write to file
file_put_contents("1_t1.php", $str);

function tolog($str) {
file_put_contents("replace_log.txt", $str . "n", FILE_APPEND);
}
?>

(There is a code recorded in the log, which will be useful in the subsequent secondary decryption.)
After execution, you will get a 1_t1.php file. Open the file and see code similar to this

Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

Find a tool to format it. The phpstorm I use comes with its own formatting function, and then the code becomes much clearer.

Aegis Encryption and Decryption Tutorial (2) PHP Aegis Decryption_PHP Tutorial

After further sorting, the following code is obtained:

Copy code The code is as follows:

//Start code decryption<<===
if (!defined('IN_DECODE_82d1b9a966825e3524eb0ab6e9f21aa7')) {
    define('xA130x8C', true);

    function fun1($str, $flg="") {
        if(!$flg) return(base64_decode($str));

        $ret = '?';
        for($i=0; $i            $c = ord($str[$i]);
            $ret .= $c<245 ? ( $c>136 ? chr($c/2) : $str[$i] ) : "";
        }
        return base64_decode($ret);
    }

    function fun2(&$p14)
    {
        global $p15, $p16, $p17, $p18, $p19, $p3;
        @$p17($p18, $p19 . '(@$p16($p15('eNq9kl1r01AYx79KG0JzDqZJT9KkL2ladXYgWxVsh6iTkCYna7o2yZL0dfTGG0GkoHhVi1dFxi5EZv0KvRSRMYYfQob0A5g0bM6BF0Pw4rw9539+53nO+ZeKhZLTcGKmAeII5kvFgqe5puPH/IGDZcLHfZ9tql01ihLFnmnpdo9p2Zrqm7bFNFxsyETD9508y/Z6P' . $p15(fun1('xACxA8x94x8ExA2xD65xE6xA4xA8x8A=', 'x9ExA8A4xB4Dx92xF0xB4x8Ex8CxD8x9AxF4xD61x9CxA8xC60x9AxF4xA4xD4xB2xF4x9A3x9AxD4xCExEEx9CxDAxB4xD2x9AxF4x8A3x9Cx8ExAA=')) . 'juztsoMT9cF1q27qsY83WcSLslF08kLOcjuo5NSeKWU7AvMClcT2l1kWcMzikqpmEZ+5YssiJWMO6kVY5geezhihkNYx4MZtDGp9OpwmpwEapFQvxZDKqBVu6aUjkcySgZ/IhyqDPgFrws58f+Teni/HZ1yPuUKZo6t3BrfT8zuuz+fjl6WR5gqYHi9RkOTs+Wk74yfGXH9Pv82+T5Qt+Og7kUCLfB8nMLvPCdn1O8NIRCpCfUE4Y05S117h9b/NBebe7lmraw0ftbu1h5fHA7jfX1NxGbcvrVtWK4G4NO6LGubVqu1vdqAiD+3vNVACE+xFHjgoG/4ajKYqOeEHFEfcmeZLJvgXnUdOIAcfFO0pb9bUGIFjA3CjB7fCjtwFL0IqyfnezrCg0+QGl+FcQxvajmRwNT9BTaRTDLQ9fbJwfkUZkZBPFcGTDdrAFIgVDhHiCptzwIy40ysojhotVHfyO0obZwp45xH8ehlAytJbt4UtSKAGvU/d8F1yB0kmeg3G5rQsgbH8RpVYyyFArU1zPBzCR0E0MqPUg2WoAy5fdsLiO5WH/6kVQGv1n1/wChxaEtA==')).$p16($p15($p3)))', "82d1b9a966825e3524eb0ab6e9f21aa7");
    }
}
global $p15, $p16, $p17, $p18, $p19, $p3;
$p17 = 'preg_replace';
$p18 = '/82d1b9a966825e3524eb0ab6e9f21aa7/e';
$p15 = 'base64_decode';
$p19 = 'eval';
$p16 = 'gzuncompress';
$p3 = '';

@$p17($p18, $p19 . '(@$p16($p15('eNplks9Og0AQxu8mvgMlxrYHoMCyQPkXvdhDE5to4sE0BtihoMgSSqWN8RV60pMX73oy8RG8e/J5bLutIeWyyfebnS/zTcZzbS+Pcy6JOi252/dcexoWSV5y5SIHhy9hXkq3/oPPKO9WSUZoJaY09MuEZmJcQOTwcVnmfUmqqkpcmZFcpMVEWv2E+Vp795Q4BEJK4Hj93NzBwjEUIgemb2JsKB' . $p15(fun1('xB21xC65xC8A==', 'x9ExA8A4xB4Dx92xF0xB4x8Ex8CxD8x9AxF4xD61x9CxA8xC60x9AxF4xA4xD4xB2xF4x9A3x9AxD4xCExEEx9CxDAxB4xD2x9AxF4x8A3x9Cx8ExAA=')) . 'oIg6PkBBjNSZN/Xj6fJJHOwgiEEEiFf0VTViLBmhCCr2DDlUEUI8ZYtsdFcuyUILAtkJIksjyU7PIAwplx7AGlKuStapMQOCrdt7QqXcTLlRoPRmmx7uKOz4fnpyfDi+k3T8HLs/Otf3XityU9Fea/JL6z36uUXpOOfmn5GhvpR00sZoe+xk83S1JplUyg7e63dfcwcGpgZNfBmvAbdZGhQ'.($p20.=fun2($p20)))))', "82d1b9a966825e3524eb0ab6e9f21aa7" . ($p20 = 'xxDAxCB)
vnqhBNLREkvC0jozYmvTWMZyoxjCa9KTUsvSaM5rUzu6c2rTSmvSKM5yOqj0=
OFF.xADH5xCF2x88xF0ux8BL*xCDxF2223.
xB1xF0FF1xCF+x02x00xB6xCA
xBE'));
//End of the decryption code===>>
return true;?>76cde264ef549deac4d0fae860b50010

Isn’t it very clear? The rest is the basic code. There is also a knowledge point preg_replace. When the regular modifier contains e, the second parameter will be parsed and executed as a php code,
$ The p18 variable contains the regular rule, and the e at the end is shining.
It is also best to output the content in fun2 to a file again, and then replace the variables with the above method.
@$p17 That line is our real source code, but the tail part is in the fun2 function, because fun2 is the real verification and output tail base64 code.
I am too lazy to write the rest, because I have already mentioned all the knowledge required for decryption,

Tomorrow I will encrypt the decryption code I wrote using this tool and post it, and I will provide the decryption API for everyone to call.
I’m not pretending or showing off, because it’s better to teach someone to fish than to teach someone to fish. You can also say that you can make enough food and clothing by yourself.
Of course there are people who only want the results and not the process, so it’s the same if I give you the API directly, right?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/780719.htmlTechArticleIn fact, someone on the Internet has already analyzed this and written it as a tool, but I have tested many and none It works, so I decided to analyze it from the beginning. Open the Aegis encrypted...
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