darsyn/混淆器

此包已废弃,不再维护。未建议替代包。
此包的最新版本(0.1.0)没有可用的许可证信息。

在用户空间代码运行时使用基本的XOR加密来混淆PHP源文件。

0.1.0 2017-02-06 17:05 UTC

This package is auto-updated.

Last update: 2022-02-01 13:05:16 UTC


README

混淆源代码,并在运行时解密它。

这不是为了安全地加密源代码;仅仅混淆源代码以确保任何部分和/或完整源代码的提取都是故意的。这可以在与该方的任何法律争议中提供额外的证据。

这种混淆方法是一个概念验证,在性能方面并不高效。

设置

<?php declare(strict_types=1);

use Darsyn\Obfuscate\Obfuscate;

require_once __DIR__ . '/vendor/autoload.php';
// The call to the Obfuscator library must come *before* any files that are
// obfuscated are loaded by PHP (such as a call to a class which triggers the
// autoloader), therefore just after including the Autoloader is a good idea.
new Obfuscate([
    'excludePaths' => [
        // You *MUST* exclude the vendor directory from being checked for
        // obfuscated code.
        __DIR__ . '/vendor',
    ],
]);

// This file (the entry script) must not be obfuscated, in order to load
// Autoloaders and the Obfuscator library.
// Now continue your application logic as normal, any further files that are
// loaded will be checked if they are obfuscated and decrypted.

魔法

混淆器将拦截加载的PHP文件,并在将其交给PHP解析器之前转换(去混淆)源代码。

示例

文件系统上的PHP文件看起来像这样

<?php exit('Protected by Darsyn Obfuscator.'); ?>

aFcZG1BjeU4PAhFTEUEQAEM0AhViHgsdTAQyJ08HB1IBAxhFH15rZAFTEU9zCggFGhwcMDtVCwoPFyU2
BkEZDRJPAQQ3Bw0BTAYzJwpAIBoGH0wMAXwtABpUE08fCQYHSW8qCAkYUxJOIEUPElUCGzdPAxETARhM
ER0AFh0XEBwBH1ljCgAXABYcGEUGYh4qU09VUhMQQg8GB0VIIQYKB0kGHQAHARBFGWEQEQoaHE0JYUVZ
AEEVbgBJUwBOT1QAHwAVGwZOVEtUGwwQWEwXCRdEABxLVUMUEUYVHQlUSQYbFgYdDgsbCQkAIB8AFAdF
U3tkT1QAQQBTRUNVUkUATAcYUwQxAEkbVABTUVRSCAQNHhVUHEcEBw0KBl9bCxxUNQ8RExQVAEUGQEJL
Fh0bFw9LUgwAEDpKPRpOWgBHUwdBQVoHSABdRSc8ICBjPyoreT49IXAoIWE6ICYMZ0VBTlQAVE8ALkxY
f1JFTFldbxNp

但PHP的解析器将接收这个

<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render(':default:index.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
        ]);
    }
}

待办事项

  • 性能(去混淆源代码的字节码目前未在OpCache中缓存)。
  • 完全禁用用户空间缓存,以确保去混淆代码不会保存到文件系统中。
  • 允许禁用原始AOP源转换器。