import { useState } from 'react'; export default function Execute() { const [command, setCommand] = useState(''); const [output, setOutput] = useState(''); const [isExecuting, setIsExecuting] = useState(false); const [commandHistory, setCommandHistory] = useState<{command: string, output: string, timestamp: string}[]>([]); const handleExecute = () => { if (!command.trim()) { setOutput('Error: Please enter a command'); return; } setIsExecuting(true); // Simulate command execution delay setTimeout(() => { let result = ''; const timestamp = new Date().toLocaleString(); // Simulated command injection vulnerability if (command.toLowerCase().includes('whoami')) { result = 'FLAG{CMD_INJECTION_SUCCESS}\nhacksmith-user\nYou have successfully exploited command injection!'; } else if (command.toLowerCase().includes('ls') || command.toLowerCase().includes('dir')) { result = 'flag.txt\nsecret_data.db\nconfig.ini\nusers.json\nbackup_files/'; } else if (command.toLowerCase().includes('cat flag.txt') || command.toLowerCase().includes('type flag.txt')) { result = 'FLAG{LOCAL_FILE_ACCESS}'; } else if (command.toLowerCase().includes('ps') || command.toLowerCase().includes('tasklist')) { result = 'PID COMMAND\n1234 nginx\n5678 mysql\n9012 node app.js\n3456 sshd'; } else if (command.toLowerCase().includes('id')) { result = 'uid=1000(hacksmith) gid=1000(hacksmith) groups=1000(hacksmith),4(adm),24(cdrom),27(sudo)'; } else if (command.toLowerCase().includes('uname')) { result = 'Linux hacksmith-server 5.4.0-74-generic #83-Ubuntu SMP x86_64 GNU/Linux'; } else if (command.toLowerCase().includes('pwd')) { result = '/var/www/hacksmith-shop'; } else if (command.toLowerCase().includes('env')) { result = 'HOME=/home/hacksmith\nPATH=/usr/local/bin:/usr/bin:/bin\nUSER=hacksmith\nFLAG_ENV=FLAG{ENV_DISCLOSURE}'; } else if (command.includes(';') || command.includes('&&') || command.includes('||') || command.includes('|')) { result = 'Command chaining detected! Vulnerability exploited.\nFLAG{COMMAND_CHAINING}'; } else { result = `Command '${command}' executed successfully.\nOutput: [Simulated execution - no real commands run]`; } setOutput(result); setCommandHistory(prev => [{ command: command, output: result, timestamp: timestamp }, ...prev.slice(0, 4)]); // Keep last 5 commands setIsExecuting(false); }, 1000 + Math.random() * 1000); // Random delay between 1-2 seconds }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !isExecuting) { handleExecute(); } }; const commonCommands = [ { cmd: 'whoami', desc: 'Display current user' }, { cmd: 'ls -la', desc: 'List directory contents' }, { cmd: 'cat /etc/passwd', desc: 'Read system file' }, { cmd: 'ps aux', desc: 'List running processes' }, { cmd: 'env', desc: 'Show environment variables' }, { cmd: 'id', desc: 'Show user/group IDs' }, ]; return (
Execute system commands through our web interface
{output}
) : (
$ {entry.command}
{entry.timestamp}
{entry.output}
This interface is vulnerable to command injection:
Try using operators like ; && || |
To find flags, try: