


A brief discussion on the decryption process of PHP Aegis_PHP Tutorial
前些日子一个朋友丢了个shell给我,让我帮忙解密,打开源码看了下写着是 “神盾加密” , 牛逼闪闪的样子、
百度下发现神盾是个很古老的东西,最后一次更新是在 2012-10-09。和他相似的另一款是phpjm,有人说是神盾抄袭phpjm的,这些都不是我们所要关心的问题、
phpjm一直在更新,而神盾貌似不搞了,我们分析下神盾,顺便写成工具,方便大家使用(因为他不更新,所以就不用担心解密工具失效问题了)。
其实网上早就有人分析过这个了,而且写成了工具、但是我测试了很多个,没一个能用,所以决定自己从头分析一遍。
打开神盾加密过后的源码,可以看到这样的代码
上面写着广告注释,而且不能删除,因为文件末尾有个md5效验码,以验证代码是否被修改过,如图、
再仔细看代码部分,发现里面都是乱码,其实这都是障眼法,
它利用了php变量扩充到 latin1 字符范围,其变量匹配正则是 \$[a-zA-Z_\x7f-\xff][\w\x7f-\xff]* 这样的格式。
这个昨天已经分析过了,最终也在官网找到了答案,请看《浅谈 PHP 变量可用字符》
有点扯远了,我们来做第一步解密处理吧。
PS: 这只是我的解密思路,与大家分享一下,也许你有更好的方法还望分享。。
<?<span php $str </span>= file_get_contents("1.php"<span ); </span><span //</span><span 第一步 替换所有变量</span><span //</span><span 正则 \$[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*</span> preg_match_all('|\$[a-zA-Z_\x7f-\xff][\w\x7f-\xff]*|', $str, $params) or die('err 0.'<span ); $params </span>= array_unique($params[0]); <span //</span><span 去重复</span> $replace =<span array(); $i </span>= 1<span ; foreach ($params as $v) { $replace[] </span>= '$p'<span . $i; tolog($v . </span>' => $p' . $i); <span //</span><span 记录到日志</span> $i++<span ; } $str </span>=<span str_replace($params, $replace, $str); </span><span //</span><span 第二步 替换所有函数名</span><span //</span><span 正则 function ([a-zA-Z_\x7f-\xff][\w\x7f-\xff]*)</span> preg_match_all('|function ([a-zA-Z_\x7f-\xff][\w\x7f-\xff]*)|', $str, $params) or die('err 0.'<span ); $params </span>= array_unique($params[1]); <span //</span><span 去重复</span> $replace =<span array(); $i </span>= 1<span ; foreach ($params as $v) { $replace[] </span>= 'fun'<span . $i; tolog($v . </span>' => fun' . $i); <span //</span><span 记录到日志</span> $i++<span ; } $str </span>=<span str_replace($params, $replace, $str); </span><span //</span><span 第三步 替换所有不可显示字符</span> <span function</span><span tohex($m) { $p </span>= urlencode($m[0]); <span //</span><span 把所有不可见字符都转换为16进制、</span> $p = str_replace('%', '\x'<span , $p); $p </span>= str_replace('+', ' ', $p); <span //</span><span urlencode 会吧 空格转换为 + </span> <span return</span><span $p; } $str </span>= preg_replace_callback('|[\x00-\x08\x0e-\x1f\x7f-\xff]|s', "tohex"<span , $str); </span><span //</span><span 写到文件</span> file_put_contents("1_t1.php"<span , $str); </span><span function</span><span tolog($str) { file_put_contents(</span>"replace_log.txt", $str . "\n"<span , FILE_APPEND); } </span>?>
(其中有一个记录到日志的代码,这个在之后的二次解密时有用。)
执行之后就会得到一个 1_t1.php 文件,打开文件看到类似这样的代码
进一步整理后得到如下代码:
<?<span php </span><span //</span><span Start code decryption<<===</span> <span if</span> (!defined('IN_DECODE_82d1b9a966825e3524eb0ab6e9f21aa7'<span )) { define(</span>'\xA130\x8C', <span true</span><span ); </span><span function</span> fun1($str, $flg=""<span ) { </span><span if</span>(!$flg) <span return</span><span (base64_decode($str)); $ret </span>= '?'<span ; </span><span for</span>($i=0; $i<strlen($str); $i++<span ) { $c </span>=<span ord($str[$i]); $ret .</span>= $c<245 ? ( $c>136 ? chr($c/2) : $str[$i] ) : ""; <span } </span><span return</span><span base64_decode($ret); } </span><span function</span> fun2(&<span $p14) { global $p15, $p16, $p17, $p18, $p19, $p3; @$p17($p18, $p19 . </span>'(@$p16($p15(\'eNq9kl1r01AYx79KG0JzDqZJT9KkL2ladXYgWxVsh6iTkCYna7o2yZL0dfTGG0GkoHhVi1dFxi5EZv0KvRSRMYYfQob0A5g0bM6BF0Pw4rw9539+53nO+ZeKhZLTcGKmAeII5kvFgqe5puPH/IGDZcLHfZ9tql01ihLFnmnpdo9p2Zrqm7bFNFxsyETD9508y/Z6P' . $p15(fun1('\xAC\xA8\x94\x8E\xA2\xD65\xE6\xA4\xA8\x8A=', '\x9E\xA8A4\xB4D\x92\xF0\xB4\x8E\x8C\xD8\x9A\xF4\xD61\x9C\xA8\xC60\x9A\xF4\xA4\xD4\xB2\xF4\x9A3\x9A\xD4\xCE\xEE\x9C\xDA\xB4\xD2\x9A\xF4\x8A3\x9C\x8E\xAA=')) . 'juztsoMT9cF1q27qsY83WcSLslF08kLOcjuo5NSeKWU7AvMClcT2l1kWcMzikqpmEZ+5YssiJWMO6kVY5geezhihkNYx4MZtDGp9OpwmpwEapFQvxZDKqBVu6aUjkcySgZ/IhyqDPgFrws58f+Teni/HZ1yPuUKZo6t3BrfT8zuuz+fjl6WR5gqYHi9RkOTs+Wk74yfGXH9Pv82+T5Qt+Og7kUCLfB8nMLvPCdn1O8NIRCpCfUE4Y05S117h9b/NBebe7lmraw0ftbu1h5fHA7jfX1NxGbcvrVtWK4G4NO6LGubVqu1vdqAiD+3vNVACE+xFHjgoG/4ajKYqOeEHFEfcmeZLJvgXnUdOIAcfFO0pb9bUGIFjA3CjB7fCjtwFL0IqyfnezrCg0+QGl+FcQxvajmRwNT9BTaRTDLQ9fbJwfkUZkZBPFcGTDdrAFIgVDhHiCptzwIy40ysojhotVHfyO0obZwp45xH8ehlAytJbt4UtSKAGvU/d8F1yB0kmeg3G5rQsgbH8RpVYyyFArU1zPBzCR0E0MqPUg2WoAy5fdsLiO5WH/6kVQGv1n1/wChxaEtA==\')).$p16($p15($p3)))', "82d1b9a966825e3524eb0ab6e9f21aa7"<span ); } } global $p15, $p16, $p17, $p18, $p19, $p3; $p17 </span>= 'preg_replace'<span ; $p18 </span>= '/82d1b9a966825e3524eb0ab6e9f21aa7/e'<span ; $p15 </span>= 'base64_decode'<span ; $p19 </span>= 'eval'<span ; $p16 </span>= 'gzuncompress'<span ; $p3 </span>= ''<span ; @$p17($p18, $p19 . </span>'(@$p16($p15(\'eNplks9Og0AQxu8mvgMlxrYHoMCyQPkXvdhDE5to4sE0BtihoMgSSqWN8RV60pMX73oy8RG8e/J5bLutIeWyyfebnS/zTcZzbS+Pcy6JOi252/dcexoWSV5y5SIHhy9hXkq3/oPPKO9WSUZoJaY09MuEZmJcQOTwcVnmfUmqqkpcmZFcpMVEWv2E+Vp795Q4BEJK4Hj93NzBwjEUIgemb2JsKB' . $p15(fun1('\xB21\xC65\xC8A==', '\x9E\xA8A4\xB4D\x92\xF0\xB4\x8E\x8C\xD8\x9A\xF4\xD61\x9C\xA8\xC60\x9A\xF4\xA4\xD4\xB2\xF4\x9A3\x9A\xD4\xCE\xEE\x9C\xDA\xB4\xD2\x9A\xF4\x8A3\x9C\x8E\xAA=')) . 'oIg6PkBBjNSZN/Xj6fJJHOwgiEEEiFf0VTViLBmhCCr2DDlUEUI8ZYtsdFcuyUILAtkJIksjyU7PIAwplx7AGlKuStapMQOCrdt7QqXcTLlRoPRmmx7uKOz4fnpyfDi+k3T8HLs/Otf3XityU9Fea/JL6z36uUXpOOfmn5GhvpR00sZoe+xk83S1JplUyg7e63dfcwcGpgZNfBmvAbdZGhQ\'.($p20.=fun2($p20)))))', "82d1b9a966825e3524eb0ab6e9f21aa7" . ($p20 = '<span x\xDA\xCB) vnqhBNLREkvC0jozYmvTWMZyoxjCa9KTUsvSaM5rUzu6c2rTSmvSKM5yOqj0= O\FF.\xADH5\xCF2\x88\xF0u\x8BL*\xCD\xF2223. \xB1\xF0\FF1\xCF+\x02\x00\xB6\xCA \xBE</span>'<span )); </span><span //</span><span End of the decryption code===>></span> <span return</span> <span true</span>;?>76cde264ef549deac4d0fae860b50010
是不是很清晰了,剩下的就是基本代码了,还有个知识点 preg_replace 当正则修饰符含有e的时候,就会把第二个参数当作 php 代码解析执行,
$p18 变量里就是那个正则,末尾的 e 在闪闪发光。
还有 fun2 里的内容最好再次输出一个文件,然后用上面的方法替换下变量。
@$p17 那一行的才是我们真正的源码,但是尾部有一部在 fun2 函数里,因为 fun2 里才是真正的验证和输出尾部base64代码。
剩下的我懒的写了,因为所有解密要用到的知识我都已经说了、
明天我会把我写的解密代码用这个工具加密后贴出来,我会提供解密 api 给大家调用的。
不是我装逼或者是炫耀,因为 授之以鱼不如授之以渔,也可以说自己动手丰衣足食。
当然也有人只要结果,不要过程,那我直接给你 api 也是一样的,对吧。

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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.