pH-7 / Obfuscator-Class

:man_technologist: Simple and effective Obfuscator PHP class (this is not a stupid base64 encoding script, but a real and effective obfuscation script)
http://github.com/pH-7/Obfuscator-Class
MIT License
362 stars 143 forks source link

The function `create_function` has been DEPRECATED in PHP 8 #24

Open BaseMax opened 3 years ago

BaseMax commented 3 years ago

Hi Pierre;

The Function create_function has been DEPRECATED in PHP8 and encoded programs will not run in a new server. (PHP 4 >= 4.0.1, PHP 5, PHP 7)

Warning: This function has been DEPRECATED as of PHP 7.2.0, and REMOVED as of PHP 8.0.0. Relying on this function is highly discouraged. https://www.php.net/manual/en/function.create-function.php

$__________________ = 'Q1JFQXRlX2Z1bkNUaU9u';
$__________________ = $__($__________________);
// print $__________________."\n";
// $__________________ = "create_function";

Trace

[max@workstation Obfuscator-Class]$ php 2-input.php

CREAte_funCTiOn
PHP Fatal error:  Uncaught Error: Call to undefined function CREAte_funCTiOn() in /project/Obfuscator-Class/2-input.php:18
Stack trace:
#0 {main}
  thrown in /project/Obfuscator-Class/2-input.php on line 18

[max@workstation Obfuscator-Class]$ php 2-input.php

PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /project/Obfuscator-Class/2-input.php:21
Stack trace:
#0 {main}
  thrown in /project/Obfuscator-Class/2-input.php on line 21

What I find is obscured code want to use CREAte_funCTiOn function somethings is probably create_function. But this is not available in server.

$ php -v

PHP 8.0.5 (cli) (built: Apr 27 2021 18:07:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies

I'm not sure it's solved before or a trick and solution to solve this. Anyway I submit this since I see encoded programs cannot run anymore.

Best;

konstantinosbotonakis commented 3 years ago

Try this:

if (!function_exists("create_function)) { function __create_function($arg, $body) { static $cache = array(); static $maxCacheSize = 64;

static $sorter;

if ($sorter === NULL) {
    $sorter = function($a, $b) {
        if ($a->hits == $b->hits) {
            return 0;
        }

        return ($a->hits < $b->hits) ? 1 : -1;
    };
}

$crc = crc32($arg . "\\x00" . $body);

if (isset($cache[$crc])) {
    ++$cache[$crc][1];
    return $cache[$crc][0];
}

if (sizeof($cache) >= $maxCacheSize) {
    uasort($cache, $sorter);
    array_pop($cache);
}

$cache[$crc] = array($cb = eval('return function('.$arg.'){'.$body.'};'), 0);
return $cb; } }