hackerTyper = {
const rnd = Math.random;
// ---------- DOM ----------
const container = document.createElement("div");
container.className = "ht-wrap";
container.tabIndex = 0;
container.setAttribute("role", "application");
container.setAttribute("aria-label", "Hacker typer terminal. Click to focus, then press any keys.");
container.innerHTML = `
<style>
.ht-wrap{position:relative;width:100%;height:400px;box-sizing:border-box;overflow:hidden;border-radius:10px;
background:#020a05;border:1px solid #14532d;outline:none;user-select:none;-webkit-user-select:none;
font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
transition:box-shadow .2s,border-color .2s}
.ht-wrap.ht-on{border-color:#39ff7a;box-shadow:0 0 0 2px rgba(57,255,122,.25),0 0 28px rgba(57,255,122,.18) inset}
.ht-bar{position:absolute;top:0;left:0;right:0;height:28px;display:flex;align-items:center;gap:10px;padding:0 10px;
background:#0a170e;border-bottom:1px solid #14532d;color:#7fbf92;font-size:12px;z-index:3}
.ht-dots{display:flex;gap:6px}
.ht-dots i{width:10px;height:10px;border-radius:50%;background:#ff5f56;display:block}
.ht-dots i:nth-child(2){background:#ffbd2e}
.ht-dots i:nth-child(3){background:#27c93f}
.ht-title{flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-align:center}
.ht-state{font-size:11px;letter-spacing:.08em;color:#4b6b57;white-space:nowrap}
.ht-on .ht-state{color:#39ff7a}
.ht-body{position:absolute;top:28px;left:0;right:0;bottom:0;padding:8px 12px 10px;overflow-y:auto;
color:#b6f5c3;font-size:13px;line-height:1.35;scrollbar-width:none}
.ht-body::-webkit-scrollbar{display:none}
.ht-ln{white-space:pre-wrap;word-break:break-all;min-height:1.35em}
.ht-cur{display:inline-block;width:.6em;height:1.15em;vertical-align:text-bottom;background:#39ff7a;
animation:ht-blink 1s steps(1) infinite}
.ht-wrap:not(.ht-on) .ht-cur{animation:none;background:transparent;outline:1px solid #39ff7a;outline-offset:-1px}
@keyframes ht-blink{50%{opacity:0}}
.ht-ok{color:#5dff7a}.ht-info{color:#6fd3ff}.ht-warn{color:#ffd45e}.ht-err{color:#ff6b6b}
.ht-dim{color:#5f8a6c}.ht-cmd{color:#ffffff}
.ht-scan{position:absolute;top:28px;left:0;right:0;bottom:0;pointer-events:none;z-index:2;
background:repeating-linear-gradient(to bottom,rgba(0,0,0,0) 0,rgba(0,0,0,0) 2px,rgba(0,0,0,.16) 3px)}
.ht-shield{position:absolute;top:28px;left:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center;
text-align:center;background:rgba(0,6,2,.62);pointer-events:none;z-index:2;transition:opacity .2s}
.ht-on .ht-shield{opacity:0}
.ht-shield-1{color:#39ff7a;font-size:20px;letter-spacing:.2em;text-shadow:0 0 12px rgba(57,255,122,.7);
animation:ht-pulse 1.6s ease-in-out infinite}
.ht-shield-2{color:#7fbf92;font-size:12px;margin-top:6px}
@keyframes ht-pulse{50%{opacity:.45}}
.ht-over{position:absolute;top:28px;left:0;right:0;bottom:0;z-index:5;display:none;align-items:center;justify-content:center}
.ht-rain{position:absolute;top:0;left:0;width:100%;height:100%;animation:ht-fadein .8s ease-out}
@keyframes ht-fadein{0%{opacity:0}100%{opacity:1}}
.ht-dlg{position:relative;min-width:280px;max-width:90%;padding:18px 28px 20px;text-align:center;
background:rgba(0,18,6,.94);border:2px solid #39ff7a;
box-shadow:0 0 0 4px rgba(57,255,122,.15),0 0 40px rgba(57,255,122,.45);
animation:ht-pop .5s cubic-bezier(.2,1.4,.4,1)}
.ht-dlg-t{color:#7fbf92;font-size:11px;letter-spacing:.25em;margin-bottom:10px}
.ht-granted{color:#39ff7a;font-weight:bold;font-size:clamp(24px,5vw,40px);letter-spacing:.12em;
text-shadow:0 0 14px rgba(57,255,122,.9);animation:ht-flick 2.4s infinite}
.ht-dlg-s{color:#b6f5c3;font-size:13px;margin:10px 0 14px}
.ht-btn{font:inherit;font-size:12px;padding:5px 16px;color:#39ff7a;background:transparent;
border:1px solid #39ff7a;cursor:pointer;letter-spacing:.1em;border-radius:0}
.ht-btn:hover{background:#39ff7a;color:#001a08}
@keyframes ht-pop{0%{transform:scale(.6);opacity:0}100%{transform:scale(1);opacity:1}}
@keyframes ht-flick{0%,100%{opacity:1}92%{opacity:1}93%{opacity:.5}94%{opacity:1}96%{opacity:.7}97%{opacity:1}}
.ht-alert{animation:ht-red .45s 3}
@keyframes ht-red{0%,100%{box-shadow:0 0 0 2px rgba(255,80,80,0)}
50%{box-shadow:0 0 0 3px rgba(255,80,80,.8),0 0 40px rgba(255,60,60,.6) inset;border-color:#ff5a5a}}
</style>
<div class="ht-bar">
<span class="ht-dots"><i></i><i></i><i></i></span>
<span class="ht-title">root@kali: ~ hackershell (all output is fake)</span>
<span class="ht-state">○ IDLE</span>
</div>
<div class="ht-body"></div>
<div class="ht-scan"></div>
<div class="ht-shield">
<div>
<div class="ht-shield-1">CLICK TO FOCUS</div>
<div class="ht-shield-2">then mash any keys to start hacking</div>
</div>
</div>
<div class="ht-over">
<canvas class="ht-rain"></canvas>
<div class="ht-dlg">
<div class="ht-dlg-t">SYSTEM // ROOT SHELL</div>
<div class="ht-granted">ACCESS GRANTED</div>
<div class="ht-dlg-s">root@mainframe.acme-corp.example</div>
<button class="ht-btn" type="button">RESTART</button>
</div>
</div>`;
const q = s => container.querySelector(s);
const body = q(".ht-body"), stateEl = q(".ht-state");
const shield1 = q(".ht-shield-1"), shield2 = q(".ht-shield-2");
const over = q(".ht-over"), rainCanvas = q(".ht-rain"), restartBtn = q(".ht-btn");
const cursor = document.createElement("span");
cursor.className = "ht-cur";
// ---------- Fake pen-test script ----------
function buildScript() {
const pad2 = n => String(n).padStart(2, "0");
const hex = n => Array.from({ length: n }, () => "0123456789abcdef"[(rnd() * 16) | 0]).join("");
const b64 = n => Array.from({ length: n }, () =>
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./"[(rnd() * 64) | 0]).join("");
const now = new Date();
let clock = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
const stamp = (adv = 1) => {
clock += adv;
return pad2(Math.floor(clock / 3600) % 24) + ":" + pad2(Math.floor(clock / 60) % 60) + ":" + pad2(clock % 60);
};
const date = now.getFullYear() + "-" + pad2(now.getMonth() + 1) + "-" + pad2(now.getDate()) +
" " + pad2(now.getHours()) + ":" + pad2(now.getMinutes());
const hhmm = pad2(now.getHours()) + ":" + pad2(now.getMinutes());
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const past = new Date(now.getTime() - 3 * 86400000 + 12345678);
const lastLogin = days[past.getDay()] + " " + months[past.getMonth()] + " " + pad2(past.getDate()) + " " +
pad2(past.getHours()) + ":" + pad2(past.getMinutes()) + ":" + pad2(past.getSeconds()) + " " + past.getFullYear();
const tick = () => stamp(1 + ((rnd() * 2) | 0));
const TGT = "203.0.113.37";
const HOST = "gateway.acme-corp.example";
const kali = { user: "root@kali", path: "~", sym: "#", col: "ht-ok" };
const adminP = { user: "admin@acme-gw", path: "~", sym: "$", col: "ht-warn" };
const rootP = { user: "root@acme-gw", path: "/root", sym: "#", col: "ht-err" };
const cmd = (text, cont) => ({ t: "cmd", text, cont });
const out = (...lines) => ({ t: "out", lines });
const prog = (label, steps) => ({ t: "progress", label, steps });
const prompt = p => ({ t: "prompt", p });
// pings
const times = [1, 2, 3, 4].map(() => 21 + rnd() * 5);
const avg = times.reduce((a, b) => a + b, 0) / 4;
const pings = times.map((t, i) => "64 bytes from " + TGT + ": icmp_seq=" + (i + 1) + " ttl=52 time=" + t.toFixed(1) + " ms");
const probe = [
"cat > probe.sh <<'EOF'",
"#!/bin/bash",
"# confirm the interesting paths found by gobuster",
"for p in admin backup uploads api .git; do",
' code=$(curl -s -o /dev/null -w "%{http_code}" "http://$TARGET/$p/")',
' echo "[$code] /$p/"',
"done",
"EOF"
].join("\n");
return [
prompt(kali),
cmd("# OPERATION NIGHTFALL // target: gateway.acme-corp.example"),
cmd("export TARGET=203.0.113.37"),
cmd("ping -c 4 $TARGET"),
out("PING " + TGT + " (" + TGT + ") 56(84) bytes of data.", ...pings, "",
"--- " + TGT + " ping statistics ---",
"4 packets transmitted, 4 received, 0% packet loss, time 3004ms",
"rtt min/avg/max/mdev = " + Math.min(...times).toFixed(3) + "/" + avg.toFixed(3) + "/" +
Math.max(...times).toFixed(3) + "/0.912 ms"),
cmd("nmap -sS -sV -O -p- -T4 --min-rate 5000 -oN nmap_full.txt $TARGET"),
out("Starting Nmap 7.94SVN ( https://nmap.org ) at " + date + " UTC",
"Initiating SYN Stealth Scan at " + hhmm,
"Scanning " + HOST + " (" + TGT + ") [65535 ports]",
"Discovered open port 80/tcp on " + TGT,
"Discovered open port 22/tcp on " + TGT,
"Discovered open port 443/tcp on " + TGT,
"Discovered open port 3306/tcp on " + TGT,
"Completed SYN Stealth Scan at " + hhmm + ", 11.42s elapsed (65535 total ports)",
"Nmap scan report for " + HOST + " (" + TGT + ")",
"Host is up (0.023s latency).",
"Not shown: 65528 closed tcp ports (reset)",
"PORT STATE SERVICE VERSION",
"22/tcp open ssh OpenSSH 7.4 (protocol 2.0)",
"25/tcp open smtp Postfix smtpd",
"80/tcp open http Apache httpd 2.4.6 ((CentOS) PHP/5.6.40)",
"443/tcp open ssl/http nginx 1.14.0",
"3306/tcp open mysql MySQL 5.5.60",
"8080/tcp open http-proxy Squid http proxy 3.5.20",
"8443/tcp open https-alt?",
"Device type: general purpose",
"Running: Linux 3.X|4.X",
"OS details: Linux 3.10 - 4.11",
"Network Distance: 9 hops",
"",
"Nmap done: 1 IP address (1 host up) scanned in 38.62 seconds"),
cmd("curl -skI https://$TARGET | head -n 9"),
out("HTTP/1.1 200 OK",
"Server: nginx/1.14.0",
"Date: " + days[now.getDay()] + ", " + pad2(now.getDate()) + " " + months[now.getMonth()] + " " + now.getFullYear() + " " + hhmm + ":07 GMT",
"Content-Type: text/html; charset=UTF-8",
"Connection: keep-alive",
"X-Powered-By: PHP/5.6.40",
"Set-Cookie: PHPSESSID=" + hex(26) + "; path=/",
"Expires: Thu, 19 Nov 1981 08:52:00 GMT",
"Cache-Control: no-store, no-cache, must-revalidate"),
cmd("nikto -h http://$TARGET -C all"),
out("- Nikto v2.5.0",
"---------------------------------------------------------------------------",
"+ Target IP: " + TGT,
"+ Target Hostname: " + HOST,
"+ Target Port: 80",
"+ Start Time: " + date + ":00 (GMT0)",
"---------------------------------------------------------------------------",
"+ Server: Apache/2.4.6 (CentOS) PHP/5.6.40",
"+ /: The anti-clickjacking X-Frame-Options header is not present.",
"+ /: The X-Content-Type-Options header is not set.",
"+ /admin/: Directory indexing found.",
"+ /backup/db_dump.sql: Backup file found. VULNERABLE",
"+ /phpinfo.php: Output from the phpinfo() function was found.",
"+ /login.php: Admin login page/section found.",
"+ 8102 requests: 0 error(s) and 7 item(s) reported on remote host",
"+ End Time: " + date + ":23 (GMT0) (23 seconds)"),
cmd("gobuster dir -u http://$TARGET -w /usr/share/wordlists/dirb/common.txt -t 64"),
out("===============================================================",
"Gobuster v3.6",
"===============================================================",
"[+] Url: http://" + TGT,
"[+] Method: GET",
"[+] Threads: 64",
"[+] Wordlist: /usr/share/wordlists/dirb/common.txt",
"[+] Status codes: 200,204,301,302,307,401,403",
"===============================================================",
"Starting gobuster in directory enumeration mode",
"==============================================================="),
prog("Enumerating directories", 20),
out("/admin (Status: 301) [Size: 312] [--> http://" + TGT + "/admin/]",
"/api (Status: 200) [Size: 1043]",
"/backup (Status: 403) [Size: 278]",
"/login.php (Status: 200) [Size: 4417]",
"/uploads (Status: 301) [Size: 314]",
"/.git/HEAD (Status: 200) [Size: 23]",
"===============================================================",
"Finished",
"==============================================================="),
cmd(probe),
cmd("bash probe.sh"),
out("[301] /admin/", "[403] /backup/", "[301] /uploads/", "[200] /api/", "[200] /.git/"),
cmd("curl -s http://$TARGET/.git/HEAD"),
out("ref: refs/heads/master"),
cmd('sqlmap -u "http://$TARGET/item.php?id=1" --batch --dbs --level=3'),
out("[*] starting @ " + stamp(0),
"[" + tick() + "] [INFO] testing connection to the target URL",
"[" + tick() + "] [INFO] checking if the target is protected by some kind of WAF/IPS",
"[" + tick() + "] [WARNING] heuristic (basic) test shows that GET parameter 'id' might be injectable",
"[" + tick() + "] [INFO] GET parameter 'id' appears to be 'boolean-based blind' injectable",
"[" + tick() + "] [INFO] the back-end DBMS is MySQL",
"web application technology: PHP 5.6.40, Apache 2.4.6",
"back-end DBMS: MySQL >= 5.0",
"[" + tick() + "] [INFO] fetching database names",
"available databases [4]:",
"[*] acme_prod",
"[*] information_schema",
"[*] mysql",
"[*] vault_keys"),
cmd("hydra -l admin -P /usr/share/wordlists/rockyou.txt -t 8 ssh://$TARGET"),
out("Hydra v9.5 starting at " + date + ":41",
"[DATA] max 8 tasks per 1 server, overall 8 tasks, 14344399 login tries (l:1/p:14344399)",
"[DATA] attacking ssh://" + TGT + ":22/"),
prog("Guessing credentials", 22),
out(["[22][ssh] host: " + TGT + " login: admin password: Tr0ub4dor&3", "ht-ok"],
"1 of 1 target successfully completed, 1 valid password found"),
cmd("ssh admin@$TARGET"),
out("admin@" + TGT + "'s password: ************",
["[ ACME CORP GATEWAY // AUTHORIZED PERSONNEL ONLY ]", "ht-warn"],
"Last login: " + lastLogin + " from 10.0.0.15"),
prompt(adminP),
cmd("uname -a && id"),
out("Linux acme-gw 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux",
"uid=1001(admin) gid=1001(admin) groups=1001(admin),10(wheel)"),
cmd("./kernel_pwn --target 3.10.0-957.el7 --payload rootshell"),
out("[*] kernel_pwn v0.9 (target: 3.10.0-957.el7.x86_64)",
"[*] mapping kernel symbols ...",
"[*] grooming heap ...",
"[*] race window opened (attempt 14/64)",
"[+] race won! patching credentials ...",
"[+] uid=0(root) gid=0(root) groups=0(root)"),
prompt(rootP),
cmd("cat /etc/shadow | head -n 3"),
out("root:$6$" + b64(8) + "$" + b64(43) + ":19845:0:99999:7:::",
"jdoe:$6$" + b64(8) + "$" + b64(43) + ":19845:0:99999:7:::",
"svc_backup:$6$" + b64(8) + "$" + b64(43) + ":19845:0:99999:7:::"),
cmd("john --wordlist=/usr/share/wordlists/rockyou.txt shadow.txt"),
out("Loaded 3 password hashes with 3 different salts (sha512crypt, crypt(3) $6$ [SHA512 128/128 AVX 2x])",
"Press 'q' or Ctrl-C to abort, almost any other key for status"),
prog("Cracking hashes", 16),
out(["toor2019! (root)", "ht-ok"],
["Summer#2019 (jdoe)", "ht-ok"],
"2g 0:00:00:14 DONE (" + date + ") 0.1428g/s 88192p/s 176384c/s",
"Session completed."),
cmd("./disable_ids.sh --silent --wipe-logs"),
{ t: "alert" },
out("[!] INTRUSION DETECTED src=10.0.0.15 severity=CRITICAL",
"[!] ALERT LEVEL 5 -- SECURITY TEAM NOTIFIED",
"[*] killing watchdog processes ...",
"[*] spoofing MAC address ...",
"[*] wiping /var/log/* ...",
"[+] IDS neutralized. Logs wiped."),
cmd("./decrypt_vault --brute --threads 128 --target mainframe.acme-corp.example"),
out("[*] connecting to mainframe.acme-corp.example:9001 ...",
"[*] handshake complete (AES-256-GCM)",
"[*] launching brute-force ..."),
prog("Decrypting vault key", 26),
out("[+] key space collapsed: shortcut found",
("[+] vault key: " + hex(4) + "-" + hex(4) + "-" + hex(4) + "-" + hex(4)).toUpperCase(),
"[+] firewall bypassed",
"[+] mainframe uplink established",
"[+] root privileges: GRANTED"),
{ t: "access" }
];
}
// ---------- Rendering helpers ----------
const HL = /(\bopen\b|VULNERABLE|\[(?:INFO|WARNING|CRITICAL|ERROR)\]|\[(?:200|301|302|401|403)\]|\(Status: (?:200|301|302|403)\)|\bGRANTED\b|\bDONE\b)/g;
function hlClass(t) {
if (t === "[INFO]") return "ht-info";
if (t === "[WARNING]" || t === "(Status: 403)" || t === "[401]" || t === "[403]") return "ht-warn";
if (t === "[CRITICAL]" || t === "[ERROR]" || t === "VULNERABLE") return "ht-err";
return "ht-ok";
}
function fillHL(el, text) {
let last = 0, m;
HL.lastIndex = 0;
while ((m = HL.exec(text))) {
if (m.index > last) el.append(document.createTextNode(text.slice(last, m.index)));
const s = document.createElement("span");
s.className = hlClass(m[0]);
s.textContent = m[0];
el.append(s);
last = m.index + m[0].length;
}
if (last < text.length) el.append(document.createTextNode(text.slice(last)));
}
function lineClass(t) {
if (t.startsWith("[+]")) return "ht-ok";
if (t.startsWith("[-]")) return "ht-err";
if (t.startsWith("[!]")) return "ht-warn";
if (t.startsWith("[*]")) return "ht-info";
if (t.startsWith("---") || t.startsWith("===")) return "ht-dim";
return "";
}
const span = (cls, text) => {
const s = document.createElement("span");
if (cls) s.className = cls;
s.textContent = text;
return s;
};
function addLine(item) {
const text = Array.isArray(item) ? item[0] : item;
const cls = Array.isArray(item) ? item[1] : lineClass(text);
const line = document.createElement("div");
line.className = "ht-ln" + (cls ? " " + cls : "");
if (text === "") line.textContent = "\u00a0";
else fillHL(line, text);
body.append(line);
line.append(cursor);
while (body.children.length > 700) body.removeChild(body.firstChild);
}
// ---------- Typing state machine ----------
let script = [];
let idx = 0;
let curPrompt = null;
let focused = false, started = false, done = false;
let rainTimer = null, alertTimer = null;
function startCmdLine(it) {
const p = curPrompt;
const line = document.createElement("div");
line.className = "ht-ln";
const tx = span("ht-cmd", "");
line.append(span(p.col, p.user), span("ht-dim", ":"), span("ht-info", p.path), span("", p.sym + " "), tx);
body.append(line);
line.append(cursor);
it.el = tx;
}
function typeInto(it, chunk) {
for (const ch of chunk) {
if (ch === "\n") {
const line = document.createElement("div");
line.className = "ht-ln";
const tx = span("ht-cmd", "");
line.append(span("ht-dim", it.cont || "> "), tx);
body.append(line);
line.append(cursor);
it.el = tx;
} else {
it.el.textContent += ch;
}
}
}
function renderProgress(it) {
const width = 24;
const f = Math.floor(width * it.pos / it.steps);
const finished = it.pos >= it.steps;
const head = f > 0 ? (finished ? "=" : ">") : "";
const bar = "=".repeat(Math.max(0, f - 1)) + head + ".".repeat(width - f);
const pct = Math.round(100 * it.pos / it.steps);
it.el.textContent = it.label.padEnd(26) + " [" + bar + "] " + String(pct).padStart(3) + "%" + (finished ? " done" : "");
}
function startProgress(it) {
const line = document.createElement("div");
line.className = "ht-ln ht-info";
body.append(line);
line.append(cursor);
it.el = line;
line.textContent = "";
line.append(cursor);
const holder = document.createElement("span");
line.insertBefore(holder, cursor);
it.el = holder;
renderProgress(it);
}
function flashAlert() {
container.classList.remove("ht-alert");
void container.offsetWidth;
container.classList.add("ht-alert");
clearTimeout(alertTimer);
alertTimer = setTimeout(() => container.classList.remove("ht-alert"), 1500);
}
function enter(i) {
idx = i;
while (idx < script.length) {
const it = script[idx];
it.pos = 0;
if (it.t === "prompt") { curPrompt = it.p; idx++; continue; }
if (it.t === "alert") { flashAlert(); idx++; continue; }
if (it.t === "access") { showAccess(); return; }
if (it.t === "cmd") { startCmdLine(it); return; }
if (it.t === "progress") { startProgress(it); return; }
return; // "out": lines are added on key presses
}
}
const next = () => enter(idx + 1);
function consume(budget) {
while (budget > 0 && !done && idx < script.length) {
const it = script[idx];
if (it.t === "cmd") {
const take = Math.min(budget, it.text.length - it.pos);
typeInto(it, it.text.slice(it.pos, it.pos + take));
it.pos += take;
budget -= take;
if (it.pos >= it.text.length) next();
} else if (it.t === "out") {
while (budget > 0 && it.pos < it.lines.length) { addLine(it.lines[it.pos++]); budget--; }
if (it.pos >= it.lines.length) next();
} else if (it.t === "progress") {
const take = Math.min(budget, it.steps - it.pos);
it.pos += take;
budget -= take;
renderProgress(it);
if (it.pos >= it.steps) next();
} else break;
}
body.scrollTop = body.scrollHeight;
}
// ---------- "Access Granted" dialog + matrix rain ----------
function startRain() {
const w = rainCanvas.width = container.clientWidth;
const h = rainCanvas.height = container.clientHeight - 28;
const g = rainCanvas.getContext("2d");
const fs = 14;
const cols = Math.ceil(w / fs);
const drops = Array.from({ length: cols }, () => Math.random() * -40);
const chars = "アイウエオカキクケコサシスセソタチツテトナニヌネノ0123456789ABCDEF<>/\\|=+*";
g.fillStyle = "#000a03";
g.fillRect(0, 0, w, h);
clearInterval(rainTimer);
rainTimer = setInterval(() => {
g.fillStyle = "rgba(0,10,3,0.14)";
g.fillRect(0, 0, w, h);
g.font = fs + "px monospace";
for (let i = 0; i < cols; i++) {
const y = drops[i] * fs;
g.fillStyle = "rgba(57,255,122,0.85)";
g.fillText(chars[(Math.random() * chars.length) | 0], i * fs, y - fs);
g.fillStyle = "#d4ffe0";
g.fillText(chars[(Math.random() * chars.length) | 0], i * fs, y);
if (y > h && Math.random() > 0.975) drops[i] = 0;
drops[i]++;
}
}, 50);
}
function stopRain() {
clearInterval(rainTimer);
rainTimer = null;
}
function showAccess() {
done = true;
over.style.display = "flex";
startRain();
}
function restart() {
stopRain();
over.style.display = "none";
clearTimeout(alertTimer);
container.classList.remove("ht-alert");
body.textContent = "";
script = buildScript();
done = false;
started = false;
updateShield();
enter(0);
container.focus({ preventScroll: true });
}
// ---------- Focus handling ----------
function updateShield() {
if (started) {
shield1.textContent = "PAUSED";
shield2.textContent = "click to resume (Esc releases the keyboard)";
} else {
shield1.textContent = "CLICK TO FOCUS";
shield2.textContent = "then mash any keys to start hacking";
}
}
function setFocused(v) {
focused = v;
container.classList.toggle("ht-on", v);
stateEl.textContent = v ? "\u25cf CAPTURING" : "\u25cb IDLE";
updateShield();
}
container.addEventListener("focusin", () => setFocused(true));
container.addEventListener("focusout", e => {
if (!container.contains(e.relatedTarget)) setFocused(false);
});
container.addEventListener("pointerdown", e => {
if (e.target instanceof HTMLButtonElement) return;
container.focus({ preventScroll: true });
});
// switching windows/tabs releases the keyboard; the user must click again
const onWinBlur = () => {
const a = document.activeElement;
if (a && container.contains(a)) a.blur();
};
window.addEventListener("blur", onWinBlur);
const IGNORED = new Set(["Shift", "Control", "Alt", "Meta", "CapsLock", "NumLock", "ScrollLock", "ContextMenu", "AltGraph", "Dead"]);
// Registered on window in the CAPTURE phase so it runs before any page-level shortcut handlers
// (e.g. Quarto's search hotkeys "s", "f" and "/"). While the terminal is focused we swallow the
// event completely; when it is not focused we do nothing, so the site's shortcuts work as usual.
const isOurs = e => focused && container.contains(e.target);
const swallow = e => { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); };
const onKeyDown = e => {
if (!isOurs(e)) return;
if (e.target instanceof HTMLButtonElement) return; // let the restart button work normally
if (e.key === "Escape") { swallow(e); container.blur(); return; }
if (e.key === "Tab") return; // don't trap keyboard users
if (e.ctrlKey || e.metaKey || e.altKey) return; // leave browser shortcuts alone
if (/^F\d+$/.test(e.key) || IGNORED.has(e.key)) return;
swallow(e);
if (done) return;
started = true;
consume(2 + ((rnd() * 4) | 0));
};
// keypress/keyup are swallowed too, in case a site binds its shortcuts to those events
const onKeyOther = e => {
if (!isOurs(e) || e.target instanceof HTMLButtonElement) return;
if (e.ctrlKey || e.metaKey || e.altKey || e.key === "Tab") return;
e.stopPropagation();
e.stopImmediatePropagation();
};
window.addEventListener("keydown", onKeyDown, true);
window.addEventListener("keypress", onKeyOther, true);
window.addEventListener("keyup", onKeyOther, true);
restartBtn.addEventListener("click", restart);
// ---------- Init ----------
script = buildScript();
enter(0);
invalidation.then(() => {
stopRain();
clearTimeout(alertTimer);
window.removeEventListener("blur", onWinBlur);
window.removeEventListener("keydown", onKeyDown, true);
window.removeEventListener("keypress", onKeyOther, true);
window.removeEventListener("keyup", onKeyOther, true);
});
return container;
}AP Cybersecurity 🔥
Greetings, Hacker!
In our interconnected digital world, it is every important to understand risks and learn to detect and mitigate vulnerabilities.
Click in the window below and mash the keyboard to get access to the super secret (simulated) server!
Activities
Unit 1