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 (
{/* Header */}
⚡

Command Execution Terminal

Execute system commands through our web interface

{/* Terminal Interface */}

💻 Terminal

{/* Command Input */}
hacksmith@server:~$ setCommand(e.target.value)} onKeyPress={handleKeyPress} placeholder="Enter command here..." className="flex-1 bg-transparent border-none outline-none text-white font-mono" disabled={isExecuting} />
{/* Output Display */}
Output:
{output ? (
                    {output}
                  
) : (
No output yet. Execute a command to see results.
)}
{/* Command History */} {commandHistory.length > 0 && (

Command History

{commandHistory.map((entry, index) => (
$ {entry.command} {entry.timestamp}
                        {entry.output}
                      
))}
)}
{/* Sidebar */}
{/* Quick Commands */}

Quick Commands

{commonCommands.map((item, index) => ( ))}
{/* Security Warning */}

⚠️ Security Alert

This interface is vulnerable to command injection:

  • No input sanitization
  • Direct command execution
  • No access controls
  • Command chaining allowed

Try using operators like ; && || |

{/* CTF Hints */}

💡 CTF Hints

To find flags, try:

  • Basic system commands
  • File listing and reading
  • Environment variables
  • Command chaining techniques
  • Process and user information
{/* System Info */}

🖥️ System Info

OS: Ubuntu 20.04
Shell: bash
User: hacksmith
Privileges: Limited
); }