🎮 Hacking Game

Hacker Simulator

Become a hacker — complete missions, earn points, and rise to the top!

0
🪙 Score
1
📊 Level
0
🎯 Missions
0
💻 Hacks
🟢 Level 1 Mission: SQL Injection
Exploit the SQL injection vulnerability to bypass the login system.

💡 Hint: Try admin' OR 1=1 -- -

🖥️ Welcome, Hacker!
📌 Type help for commands
🎯 Complete the mission to earn points!
 
$>
', command: 'inject', answer: '', successMsg: '🎉 XSS payload executed! Cookie stolen: session=admin123', failMsg: '❌ No XSS payload detected. Try injecting a script tag.' }, { id: 3, title: 'Password Cracking', desc: 'Crack the password hash using a dictionary attack.', hint: 'Try common passwords like: password, 123456, admin', command: 'crack', answer: 'password', successMsg: '🎉 Password cracked! The password was: password', failMsg: '❌ Password not found. Try a common password.' }, { id: 4, title: 'Port Scanning', desc: 'Scan the target to find open ports and services.', hint: 'Use the scan command to find open ports.', command: 'scan', answer: 'scan', successMsg: '🔍 Scanning complete! Open ports: 80, 443, 3306', failMsg: '❌ No ports found. Try scanning again.' }, { id: 5, title: 'Privilege Escalation', desc: 'Escalate your privileges to gain root access.', hint: 'Try the escalate command.', command: 'escalate', answer: 'escalate', successMsg: '🎉 Privilege escalation successful! You are now root!', failMsg: '❌ Privilege escalation failed. Try again.' }]; // ===================================================== // STATE // ===================================================== var currentMission = 0; var score = 0; var totalHacks = 0; var gameCompleted = false; var STORAGE_KEY = 'cybersume_hacking_game'; // ===================================================== // DOM // ===================================================== var terminalOutput = document.getElementById('terminalOutput'); var cmdInput = document.getElementById('cmdInput'); var scoreDisplay = document.getElementById('scoreDisplay'); var levelDisplay = document.getElementById('levelDisplay'); var missionDisplay = document.getElementById('missionDisplay'); var hacksDisplay = document.getElementById('hacksDisplay'); var missionTitle = document.getElementById('missionTitle'); var missionDesc = document.getElementById('missionDesc'); var missionHint = document.getElementById('missionHint'); var levelTag = document.getElementById('levelTag'); var hackBtn = document.getElementById('hackBtn'); var gameOver = document.getElementById('gameOver'); var finalScore = document.getElementById('finalScore'); var toast = document.getElementById('toast'); // ===================================================== // LOAD PROGRESS // ===================================================== function loadProgress() { try { var data = localStorage.getItem(STORAGE_KEY); if (data) { var parsed = JSON.parse(data); if (parsed) { currentMission = parsed.currentMission || 0; score = parsed.score || 0; totalHacks = parsed.totalHacks || 0; if (parsed.completed) { gameCompleted = true; showGameOver(); return; } } } } catch (e) {} updateUI(); loadMission(); } function saveProgress() { try { var data = { currentMission: currentMission, score: score, totalHacks: totalHacks, completed: gameCompleted }; localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); } catch (e) {} } // ===================================================== // UI UPDATE // ===================================================== function updateUI() { scoreDisplay.textContent = score; levelDisplay.textContent = currentMission + 1; missionDisplay.textContent = currentMission; hacksDisplay.textContent = totalHacks; } function loadMission() { if (gameCompleted) { showGameOver(); return; } if (currentMission >= missions.length) { gameCompleted = true; saveProgress(); showGameOver(); return; } var mission = missions[currentMission]; missionTitle.textContent = 'Mission: ' + mission.title; missionDesc.textContent = mission.desc; missionHint.innerHTML = '

💡 Hint: ' + mission.hint + '

'; levelTag.textContent = '🟢 Level ' + (currentMission + 1); // Reset terminal terminalOutput.innerHTML = ''; addLine('info', '🖥️ Mission ' + (currentMission + 1) + ': ' + mission.title); addLine('info', '📌 Type help for commands'); addLine('info', '💡 Command to use: ' + mission.command + ''); addLine('', ''); cmdInput.value = ''; cmdInput.focus(); // Reset hack button hackBtn.textContent = '💻 HACK'; hackBtn.className = 'hack-btn'; hackBtn.disabled = false; updateUI(); saveProgress(); } function showGameOver() { document.getElementById('missionArea').style.display = 'none'; terminalOutput.innerHTML = ''; addLine('success', '🏆 All missions completed!'); addLine('success', 'You are a true CyberSume hacker!'); gameOver.style.display = 'block'; finalScore.textContent = 'Score: ' + score; hackBtn.disabled = true; hackBtn.style.display = 'none'; saveProgress(); } // ===================================================== // TERMINAL // ===================================================== function addLine(type, text) { var div = document.createElement('div'); div.className = type || ''; div.innerHTML = text; terminalOutput.appendChild(div); var terminal = document.getElementById('terminal'); terminal.scrollTop = terminal.scrollHeight; } function processCommand(cmd) { if (gameCompleted) { addLine('info', '🏆 Game completed! Click "Play Again" to restart.'); return; } var mission = missions[currentMission]; var trimmed = cmd.trim().toLowerCase(); // Help if (trimmed === 'help') { addLine('output', '📋 Commands: help, ' + mission.command + ', flag, clear'); return; } // Clear if (trimmed === 'clear') { terminalOutput.innerHTML = ''; addLine('info', '🖥️ Terminal cleared'); return; } // Flag if (trimmed === 'flag') { addLine('output', '🏁 FLAG{MISSION_' + (currentMission + 1) + '_COMPLETE}'); return; } // Check if it's the mission command if (trimmed === mission.command) { addLine('output', '💻 Executing ' + mission.command + '...'); // Check if the user typed the command - they need to type the answer addLine('info', '📝 Now type the payload/answer for this mission.'); return; } // Check if it's the answer if (trimmed === mission.answer.toLowerCase()) { addLine('success', mission.successMsg); // Mission complete! score += 100; totalHacks++; currentMission++; updateUI(); saveProgress(); showToast('🎉 Mission complete! +100 points', 'success'); setTimeout(function() { loadMission(); }, 1500); return; } // Check if answer is close if (mission.answer && trimmed.indexOf(mission.answer.toLowerCase()) !== -1) { addLine('output', '⚠️ Almost! Try exactly: ' + mission.answer); return; } addLine('error', '❌ Invalid command or answer.'); addLine('info', '💡 Try: ' + mission.command + ' then type the payload'); } // ===================================================== // HACK BUTTON // ===================================================== function executeHack() { if (gameCompleted) { showToast('🏆 Game completed! Click "Play Again" to restart.', 'info'); return; } var mission = missions[currentMission]; addLine('prompt', '$> ' + mission.command); addLine('output', '💻 Hacking ' + mission.title + '...'); // Simulate hacking animation hackBtn.disabled = true; hackBtn.textContent = '⏳ Hacking...'; var steps = [ '🔍 Scanning target...', '📡 Finding vulnerabilities...', '💥 Exploiting ' + mission.title + '...', '🔓 Access granted!' ]; var stepIndex = 0; var interval = setInterval(function() { if (stepIndex < steps.length) { addLine('output', steps[stepIndex]); stepIndex++; } else { clearInterval(interval); addLine('info', '📝 Now type the payload/answer for this mission.'); hackBtn.textContent = '💻 HACK'; hackBtn.disabled = false; cmdInput.focus(); } }, 800); } // ===================================================== // GAME OVER - RESET // ===================================================== function resetGame() { currentMission = 0; score = 0; totalHacks = 0; gameCompleted = false; gameOver.style.display = 'none'; document.getElementById('missionArea').style.display = 'block'; hackBtn.style.display = 'block'; hackBtn.disabled = false; hackBtn.textContent = '💻 HACK'; hackBtn.className = 'hack-btn'; saveProgress(); loadMission(); showToast('🔄 Game reset! Good luck, hacker!', 'info'); } // ===================================================== // TOAST // ===================================================== function showToast(msg, type) { toast.textContent = msg; toast.className = 'toast ' + (type || 'success'); toast.classList.add('show'); clearTimeout(toast._timer); toast._timer = setTimeout(function() { toast.classList.remove('show'); }, 3000); } // ===================================================== // EVENTS // ===================================================== cmdInput.addEventListener('keydown', function(e) { if (e.key === 'Enter') { e.preventDefault(); var cmd = this.value; if (cmd.trim()) { addLine('prompt', '$> ' + cmd); processCommand(cmd); } this.value = ''; setTimeout(function() { cmdInput.focus(); }, 10); } }); document.getElementById('terminal').addEventListener('click', function() { cmdInput.focus(); }); // ===================================================== // KEYBOARD SHORTCUTS // ===================================================== document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { cmdInput.value = ''; cmdInput.focus(); } if (e.key === 'Enter' && document.activeElement === cmdInput) { // Already handled } }); // ===================================================== // MAKE FUNCTIONS GLOBAL // ===================================================== window.executeHack = executeHack; window.resetGame = resetGame; // ===================================================== // INIT // ===================================================== loadProgress(); console.log('🎮 CyberSume Hacking Game loaded!'); console.log('📚 Total missions: ' + missions.length); })();