mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-06 02:53:57 +01:00
feat(web): auth system, Morse provider, SSE exploration events
Auth middleware (zero external deps): - JWT + scrypt authentication in server.js - Auto-generated default credentials from env vars - Rate-limited login (10/min), change-password, verify endpoints - Glass-morphism login page with first-login detection Morse provider: - Added to server.js PROVIDERS array and .env.example - Uncensored open-weight models with native tool calling Frontend: - Bearer token injection in api() calls - 401 auto-redirect to login - SSE exploration round events Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
36d6cb216a
commit
1c7a0d0a9b
4 files changed
+561
No files matched your search
@@ -86,6 +86,10 @@ OPENCODE_API_KEY=
|
||||
# `hermes` CLI (`hermes setup --portal` for OAuth login).
|
||||
NOUS_API_KEY=
|
||||
|
||||
# morse: https://console.trymorse.ai — uncensored open-weight models
|
||||
# with native tool calling. No prompt/reply storage.
|
||||
MORSE_API_KEY=
|
||||
|
||||
# ollama: local, no key needed. Override the endpoint if not default:
|
||||
#OLLAMA_BASE_URL=http://localhost:11434/v1
|
||||
|
||||
@@ -148,6 +152,25 @@ TYPESAFE_API_KEY=
|
||||
#NEUROSPLOIT_TUNNEL_PORT=8080
|
||||
#NEUROSPLOIT_TUNNEL_BIND=127.0.0.1
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Docker / PostgreSQL (used by docker-compose.yml)
|
||||
POSTGRES_USER=neurosploit
|
||||
POSTGRES_PASSWORD= # auto-generated by install.sh
|
||||
POSTGRES_DB=neurosploit
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Web Console Authentication
|
||||
NS_JWT_SECRET= # auto-generated by install.sh
|
||||
NS_DEFAULT_USER=neurosploit # default login username
|
||||
NS_DEFAULT_PASSWORD= # auto-generated by install.sh; change after first login
|
||||
NS_PORT=8787
|
||||
NS_BIND_ADDR=127.0.0.1 # 0.0.0.0 to listen on all interfaces
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Sandbox / Worker
|
||||
NS_SANDBOX=required # required | optional | off
|
||||
NS_WORKER_IMAGE=neurosploit-kali:local
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Output budgets. These are ceilings, not usage. Raise/lower per provider.
|
||||
#NEUROSPLOIT_MAX_TOKENS=
|
||||
|
||||
@@ -68,8 +68,25 @@ function jsq(s) {
|
||||
const lit = "'" + String(s ?? '').replace(/\\/g, '\\\\').replace(/'/g, "\\'") + "'";
|
||||
return lit.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
||||
}
|
||||
function getAuthToken() {
|
||||
return localStorage.getItem('ns_token') || '';
|
||||
}
|
||||
function setAuthToken(token) {
|
||||
if (token) localStorage.setItem('ns_token', token);
|
||||
else localStorage.removeItem('ns_token');
|
||||
}
|
||||
async function api(path, opts) {
|
||||
const token = getAuthToken();
|
||||
if (token) {
|
||||
opts = opts || {};
|
||||
opts.headers = { ...(opts.headers || {}), Authorization: `Bearer ${token}` };
|
||||
}
|
||||
const res = await fetch(path, opts);
|
||||
if (res.status === 401 && !path.startsWith('/api/auth/')) {
|
||||
setAuthToken('');
|
||||
window.location.href = '/login.html';
|
||||
throw new Error('session expired');
|
||||
}
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || `${path} → ${res.status}`);
|
||||
@@ -1072,6 +1089,15 @@ function attachLiveJob(id, target, name, pinnedAgents) {
|
||||
es.addEventListener('graph', (e) => { const d = sseJson(e); if (d) updateGraphTab(d); });
|
||||
es.addEventListener('planner', (e) => { const d = sseJson(e); if (d) updatePlannerTab(d); });
|
||||
es.addEventListener('noise', (e) => { const d = sseJson(e); if (d) updateNoiseTab(d); });
|
||||
es.addEventListener('exploration', (e) => {
|
||||
const d = sseJson(e);
|
||||
if (d && state.currentJob) {
|
||||
state.currentJob.exploration = d;
|
||||
const lbl = d.complete ? `✓ Explored ${d.round} round(s), +${d.totalExtra} findings` :
|
||||
`Round ${d.round} · ${d.skillsThisRound || '?'} skills · +${d.totalExtra || 0} findings`;
|
||||
appendLog(`🧭 ${lbl}`);
|
||||
}
|
||||
});
|
||||
es.addEventListener('snapshot', (e) => { const d = sseJson(e); if (d) applySnapshot(d); });
|
||||
es.addEventListener('done', (e) => {
|
||||
const d = sseJson(e);
|
||||
|
||||
@@ -0,0 +1,333 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="color-scheme" content="dark" />
|
||||
<title>NeuroSploit — Login</title>
|
||||
<link rel="icon" type="image/svg+xml" href="logo.svg">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap">
|
||||
<style>
|
||||
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
||||
:root{
|
||||
--bg:#0a0a0f;--bg2:#12121a;--bg3:#1a1a28;
|
||||
--surface:#16162a;--surface2:#1e1e35;--surface3:#262645;
|
||||
--border:#2a2a4a;--border2:#3a3a5a;
|
||||
--text:#e8e8f0;--text2:#a0a0c0;--text3:#6a6a8a;
|
||||
--accent:#6366f1;--accent2:#818cf8;--accent3:#4f46e5;
|
||||
--accent-glow:rgba(99,102,241,.15);--accent-glow2:rgba(99,102,241,.08);
|
||||
--red:#ef4444;--red-bg:rgba(239,68,68,.1);
|
||||
--green:#22c55e;--green-bg:rgba(34,197,94,.1);
|
||||
--radius:12px;--radius-lg:20px;
|
||||
}
|
||||
html,body{height:100%;font-family:'Inter',system-ui,sans-serif;background:var(--bg);color:var(--text);overflow:hidden}
|
||||
|
||||
/* animated background */
|
||||
.bg-grid{position:fixed;inset:0;z-index:0;overflow:hidden}
|
||||
.bg-grid::before{content:'';position:absolute;inset:-50%;
|
||||
background:repeating-linear-gradient(0deg,transparent,transparent 60px,rgba(99,102,241,.03) 60px,rgba(99,102,241,.03) 61px),
|
||||
repeating-linear-gradient(90deg,transparent,transparent 60px,rgba(99,102,241,.03) 60px,rgba(99,102,241,.03) 61px);
|
||||
animation:grid-drift 60s linear infinite}
|
||||
.bg-grid::after{content:'';position:absolute;inset:0;
|
||||
background:radial-gradient(ellipse 80% 60% at 50% -20%,rgba(99,102,241,.12),transparent 70%),
|
||||
radial-gradient(ellipse 60% 40% at 80% 100%,rgba(99,102,241,.06),transparent 60%)}
|
||||
@keyframes grid-drift{0%{transform:translate(0,0)}100%{transform:translate(60px,60px)}}
|
||||
|
||||
/* floating particles */
|
||||
.particle{position:fixed;border-radius:50%;pointer-events:none;z-index:0}
|
||||
.p1{width:300px;height:300px;top:-80px;right:-60px;background:radial-gradient(circle,rgba(99,102,241,.08),transparent 70%);animation:float1 20s ease-in-out infinite}
|
||||
.p2{width:200px;height:200px;bottom:-40px;left:-40px;background:radial-gradient(circle,rgba(139,92,246,.06),transparent 70%);animation:float2 25s ease-in-out infinite}
|
||||
.p3{width:150px;height:150px;top:40%;left:20%;background:radial-gradient(circle,rgba(99,102,241,.04),transparent 70%);animation:float3 30s ease-in-out infinite}
|
||||
@keyframes float1{0%,100%{transform:translate(0,0)}50%{transform:translate(-30px,20px)}}
|
||||
@keyframes float2{0%,100%{transform:translate(0,0)}50%{transform:translate(20px,-30px)}}
|
||||
@keyframes float3{0%,100%{transform:translate(0,0)}50%{transform:translate(-20px,-20px)}}
|
||||
|
||||
/* layout */
|
||||
.login-wrapper{display:flex;align-items:center;justify-content:center;min-height:100vh;position:relative;z-index:1;padding:20px}
|
||||
.login-card{width:100%;max-width:440px;position:relative}
|
||||
|
||||
/* glass card */
|
||||
.card{background:rgba(22,22,42,.85);backdrop-filter:blur(40px) saturate(1.4);
|
||||
border:1px solid var(--border);border-radius:var(--radius-lg);
|
||||
padding:48px 40px;position:relative;overflow:hidden;
|
||||
box-shadow:0 0 0 1px rgba(99,102,241,.05),0 20px 60px rgba(0,0,0,.4),0 0 120px rgba(99,102,241,.03)}
|
||||
.card::before{content:'';position:absolute;top:0;left:0;right:0;height:1px;
|
||||
background:linear-gradient(90deg,transparent,rgba(99,102,241,.3),transparent)}
|
||||
|
||||
/* logo */
|
||||
.logo-area{text-align:center;margin-bottom:36px}
|
||||
.logo-mark{display:inline-flex;align-items:center;justify-content:center;
|
||||
width:72px;height:72px;border-radius:18px;
|
||||
background:linear-gradient(135deg,var(--accent3),var(--accent));
|
||||
box-shadow:0 8px 32px rgba(99,102,241,.3),0 0 0 1px rgba(99,102,241,.2);
|
||||
margin-bottom:20px;position:relative}
|
||||
.logo-mark::after{content:'';position:absolute;inset:-2px;border-radius:20px;
|
||||
background:conic-gradient(from 180deg,transparent,rgba(99,102,241,.3),transparent);
|
||||
animation:logo-spin 8s linear infinite;z-index:-1}
|
||||
@keyframes logo-spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}
|
||||
.logo-mark svg{width:40px;height:40px;color:#fff}
|
||||
.logo-title{font-size:26px;font-weight:700;letter-spacing:-.5px;color:var(--text)}
|
||||
.logo-title span{color:var(--accent2)}
|
||||
.logo-sub{font-size:13px;color:var(--text3);margin-top:6px;letter-spacing:.3px}
|
||||
|
||||
/* form */
|
||||
.form-group{margin-bottom:20px;position:relative}
|
||||
.form-label{display:block;font-size:12px;font-weight:600;color:var(--text2);
|
||||
letter-spacing:.8px;text-transform:uppercase;margin-bottom:8px}
|
||||
.input-wrap{position:relative;display:flex;align-items:center}
|
||||
.input-wrap svg{position:absolute;left:14px;width:18px;height:18px;color:var(--text3);
|
||||
pointer-events:none;transition:color .2s}
|
||||
.input-wrap input{width:100%;padding:14px 14px 14px 44px;font-size:15px;font-family:inherit;
|
||||
background:var(--bg2);border:1.5px solid var(--border);border-radius:var(--radius);
|
||||
color:var(--text);outline:none;transition:all .25s ease}
|
||||
.input-wrap input::placeholder{color:var(--text3)}
|
||||
.input-wrap input:focus{border-color:var(--accent);background:var(--bg);
|
||||
box-shadow:0 0 0 3px var(--accent-glow),0 0 20px var(--accent-glow2)}
|
||||
.input-wrap input:focus ~ svg,.input-wrap input:focus + svg{color:var(--accent2)}
|
||||
.input-wrap .toggle-pw{position:absolute;right:12px;background:none;border:none;
|
||||
color:var(--text3);cursor:pointer;padding:4px;border-radius:6px;transition:color .2s}
|
||||
.input-wrap .toggle-pw:hover{color:var(--text)}
|
||||
|
||||
/* error */
|
||||
.error-box{display:none;align-items:center;gap:8px;padding:12px 16px;
|
||||
background:var(--red-bg);border:1px solid rgba(239,68,68,.2);
|
||||
border-radius:var(--radius);margin-bottom:20px;font-size:13px;color:#fca5a5}
|
||||
.error-box.show{display:flex}
|
||||
.error-box svg{flex-shrink:0;width:16px;height:16px;color:var(--red)}
|
||||
|
||||
/* submit */
|
||||
.btn-login{width:100%;padding:15px;font-size:15px;font-weight:600;font-family:inherit;
|
||||
color:#fff;border:none;border-radius:var(--radius);cursor:pointer;position:relative;
|
||||
background:linear-gradient(135deg,var(--accent3),var(--accent));
|
||||
box-shadow:0 4px 16px rgba(99,102,241,.3);
|
||||
transition:all .3s ease;overflow:hidden;letter-spacing:.3px}
|
||||
.btn-login:hover{transform:translateY(-1px);
|
||||
box-shadow:0 8px 32px rgba(99,102,241,.4);filter:brightness(1.1)}
|
||||
.btn-login:active{transform:translateY(0);box-shadow:0 2px 8px rgba(99,102,241,.3)}
|
||||
.btn-login:disabled{opacity:.6;cursor:not-allowed;transform:none}
|
||||
.btn-login::before{content:'';position:absolute;top:0;left:-100%;width:100%;height:100%;
|
||||
background:linear-gradient(90deg,transparent,rgba(255,255,255,.1),transparent);
|
||||
transition:left .5s}
|
||||
.btn-login:hover::before{left:100%}
|
||||
|
||||
/* spinner inside button */
|
||||
.btn-login .spinner{display:none;width:20px;height:20px;border:2.5px solid rgba(255,255,255,.3);
|
||||
border-top-color:#fff;border-radius:50%;animation:spin .6s linear infinite;margin:0 auto}
|
||||
.btn-login.loading .btn-text{display:none}
|
||||
.btn-login.loading .spinner{display:block}
|
||||
@keyframes spin{to{transform:rotate(360deg)}}
|
||||
|
||||
/* footer */
|
||||
.login-footer{text-align:center;margin-top:28px;font-size:12px;color:var(--text3)}
|
||||
.login-footer a{color:var(--accent2);text-decoration:none}
|
||||
.login-footer a:hover{text-decoration:underline}
|
||||
|
||||
/* first-login banner */
|
||||
.first-login{display:none;margin-bottom:20px;padding:14px 16px;
|
||||
background:var(--green-bg);border:1px solid rgba(34,197,94,.2);
|
||||
border-radius:var(--radius);font-size:13px;color:#86efac}
|
||||
.first-login.show{display:block}
|
||||
.first-login strong{color:#22c55e}
|
||||
.first-login code{font-family:'JetBrains Mono',monospace;background:rgba(34,197,94,.15);
|
||||
padding:2px 6px;border-radius:4px;font-size:12px}
|
||||
|
||||
/* session info */
|
||||
.session-info{display:flex;align-items:center;gap:6px;margin-top:12px;
|
||||
font-size:11px;color:var(--text3)}
|
||||
.session-info .dot{width:6px;height:6px;border-radius:50%;background:var(--green);
|
||||
box-shadow:0 0 8px rgba(34,197,94,.5)}
|
||||
|
||||
/* responsive */
|
||||
@media(max-width:480px){
|
||||
.card{padding:36px 24px;border-radius:16px}
|
||||
.logo-mark{width:60px;height:60px;border-radius:14px}
|
||||
.logo-title{font-size:22px}
|
||||
}
|
||||
|
||||
/* keyboard nav */
|
||||
.card:focus-within{box-shadow:0 0 0 1px rgba(99,102,241,.1),0 20px 60px rgba(0,0,0,.4),0 0 120px rgba(99,102,241,.05)}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="bg-grid"></div>
|
||||
<div class="particle p1"></div>
|
||||
<div class="particle p2"></div>
|
||||
<div class="particle p3"></div>
|
||||
|
||||
<div class="login-wrapper">
|
||||
<div class="login-card">
|
||||
<div class="card">
|
||||
<!-- Logo -->
|
||||
<div class="logo-area">
|
||||
<div class="logo-mark">
|
||||
<svg viewBox="0 0 48 48" fill="none"><path d="M9 39V11l20 20V11" stroke="currentColor" stroke-width="5.5" stroke-linecap="square"/><path d="M39 9V37" stroke="currentColor" stroke-width="5.5" stroke-linecap="square"/><path d="M41 7L18 41" stroke="#a5b4fc" stroke-width="2.6" stroke-linecap="round"/></svg>
|
||||
</div>
|
||||
<div class="logo-title">Neuro<span>Sploit</span></div>
|
||||
<div class="logo-sub">Autonomous Pentest Engine</div>
|
||||
</div>
|
||||
|
||||
<!-- First login banner (shown when default creds are active) -->
|
||||
<div class="first-login" id="firstLogin">
|
||||
<strong>First login</strong> — default credentials generated.<br>
|
||||
Username: <code>neurosploit</code> | Password: check <code>.env</code><br>
|
||||
Change your password after login.
|
||||
</div>
|
||||
|
||||
<!-- Error -->
|
||||
<div class="error-box" id="errorBox">
|
||||
<svg viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="7" stroke="currentColor" stroke-width="1.5"/><path d="M8 4.5v4M8 10.5v.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
|
||||
<span id="errorText">Invalid credentials</span>
|
||||
</div>
|
||||
|
||||
<!-- Form -->
|
||||
<form id="loginForm" autocomplete="on">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="username">Username</label>
|
||||
<div class="input-wrap">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
|
||||
<input type="text" id="username" name="username" placeholder="neurosploit" autocomplete="username" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="password">Password</label>
|
||||
<div class="input-wrap">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
|
||||
<input type="password" id="password" name="password" placeholder="••••••••••" autocomplete="current-password" required>
|
||||
<button type="button" class="toggle-pw" id="togglePw" title="Show password" aria-label="Toggle password visibility">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" width="18" height="18"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-login" id="btnLogin">
|
||||
<span class="btn-text">Sign in</span>
|
||||
<div class="spinner"></div>
|
||||
</button>
|
||||
|
||||
<div class="session-info">
|
||||
<div class="dot"></div>
|
||||
<span>Encrypted session · 24h token</span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="login-footer">
|
||||
NeuroSploit v4.6 — Authorized security testing only
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const form = document.getElementById('loginForm');
|
||||
const btn = document.getElementById('btnLogin');
|
||||
const errorBox = document.getElementById('errorBox');
|
||||
const errorText = document.getElementById('errorText');
|
||||
const togglePw = document.getElementById('togglePw');
|
||||
const pwInput = document.getElementById('password');
|
||||
|
||||
// Check if already authenticated
|
||||
const token = localStorage.getItem('ns-token');
|
||||
if (token) {
|
||||
fetch('/api/auth/verify', {
|
||||
headers: { 'Authorization': 'Bearer ' + token }
|
||||
}).then(r => { if (r.ok) window.location.href = '/'; });
|
||||
}
|
||||
|
||||
// Check if first login (default creds active)
|
||||
fetch('/api/auth/status').then(r => r.json()).then(data => {
|
||||
if (data.first_login) document.getElementById('firstLogin').classList.add('show');
|
||||
}).catch(() => {});
|
||||
|
||||
// Toggle password visibility
|
||||
togglePw.addEventListener('click', function() {
|
||||
const show = pwInput.type === 'password';
|
||||
pwInput.type = show ? 'text' : 'password';
|
||||
this.title = show ? 'Hide password' : 'Show password';
|
||||
this.innerHTML = show
|
||||
? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" width="18" height="18"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>'
|
||||
: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" width="18" height="18"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>';
|
||||
});
|
||||
|
||||
// Rate limiting
|
||||
let attempts = 0;
|
||||
let lockUntil = 0;
|
||||
|
||||
form.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
errorBox.classList.remove('show');
|
||||
|
||||
// Client-side rate limit
|
||||
if (Date.now() < lockUntil) {
|
||||
const secs = Math.ceil((lockUntil - Date.now()) / 1000);
|
||||
showError('Too many attempts. Try again in ' + secs + 's');
|
||||
return;
|
||||
}
|
||||
|
||||
const user = document.getElementById('username').value.trim();
|
||||
const pass = document.getElementById('password').value;
|
||||
if (!user || !pass) { showError('Please fill in both fields'); return; }
|
||||
|
||||
btn.classList.add('loading');
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: user, password: pass })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (res.ok && data.token) {
|
||||
localStorage.setItem('ns_token', data.token);
|
||||
// Smooth transition
|
||||
document.querySelector('.card').style.transform = 'scale(0.95)';
|
||||
document.querySelector('.card').style.opacity = '0';
|
||||
setTimeout(() => { window.location.href = '/'; }, 300);
|
||||
} else {
|
||||
attempts++;
|
||||
if (attempts >= 5) {
|
||||
lockUntil = Date.now() + 30000;
|
||||
showError('Too many failed attempts. Locked for 30 seconds.');
|
||||
} else {
|
||||
showError(data.error || 'Invalid credentials');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
showError('Connection failed — is the server running?');
|
||||
} finally {
|
||||
btn.classList.remove('loading');
|
||||
btn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
function showError(msg) {
|
||||
errorText.textContent = msg;
|
||||
errorBox.classList.add('show');
|
||||
// Shake animation
|
||||
errorBox.style.animation = 'none';
|
||||
errorBox.offsetHeight; // reflow
|
||||
errorBox.style.animation = 'shake .4s ease';
|
||||
}
|
||||
|
||||
// Keyboard shortcut: Enter submits from either field
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter' && document.activeElement.tagName !== 'BUTTON') {
|
||||
form.dispatchEvent(new Event('submit'));
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@keyframes shake{0%,100%{transform:translateX(0)}20%,60%{transform:translateX(-6px)}40%,80%{transform:translateX(6px)}}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
+179
@@ -481,6 +481,8 @@ const PROVIDERS = [
|
||||
models: ['anthropic/claude-opus-5-5', 'anthropic/claude-opus-4-8', 'z-ai/glm-5.3', 'qwen/qwen3.8-max', 'deepseek/deepseek-v4.1-flash-1017', 'deepseek/deepseek-v4.1-flash', 'deepseek/deepseek-v4-pro', 'meta-llama/llama-3.3-70b-instruct'] },
|
||||
{ key: 'orcarouter', label: 'OrcaRouter', kind: 'api', envKey: 'ORCAROUTER_API_KEY',
|
||||
models: ['orcarouter/auto', 'orcarouter/free', 'orcarouter/fusion', 'deepseek/deepseek-v4.1-flash', 'deepseek/deepseek-v4-pro', 'deepseek/deepseek-chat'] },
|
||||
{ key: 'morse', label: 'Morse', kind: 'api', envKey: 'MORSE_API_KEY',
|
||||
models: ['z-ai/glm-5.3-uncensored', 'deepseek-ai/deepseek-v4.1-flash-uncensored', 'moonshotai/kimi-k3.1-pro-uncensored', 'qwen/qwen3.8-27b-uncensored', 'z-ai/glm-5.3-flash-uncensored', 'deepseek/deepseek-v4-pro'] },
|
||||
{ key: 'azure', label: 'Azure OpenAI', kind: 'api', envKey: 'AZURE_OPENAI_API_KEY',
|
||||
models: ['gpt-4o', 'gpt-4o-mini', 'gpt-5.1', 'o4-mini'] },
|
||||
{ key: 'bedrock', label: 'AWS Bedrock', kind: 'api', envKey: 'AWS_ACCESS_KEY_ID',
|
||||
@@ -2031,6 +2033,24 @@ function ingestLine(job, rawLine) {
|
||||
|
||||
if (/candidate\(s\)/.test(lown) && /^(exploit|test|analyze|review)\b/.test(lown)) job.agentsDone += 1;
|
||||
|
||||
// Exploration loop events — skill-based chaining rounds
|
||||
if (low.includes('exploration round')) {
|
||||
job.phase = 'exploring';
|
||||
const roundMatch = norm.match(/exploration round (\d+)/);
|
||||
const countMatch = norm.match(/(\d+) skill\(s\) triggered/);
|
||||
const findingsMatch = norm.match(/(\d+) new finding/);
|
||||
if (!job.exploration) job.exploration = { round: 0, totalExtra: 0, skills: [] };
|
||||
if (roundMatch) job.exploration.round = parseInt(roundMatch[1]);
|
||||
if (countMatch) job.exploration.skillsThisRound = parseInt(countMatch[1]);
|
||||
if (findingsMatch) job.exploration.totalExtra += parseInt(findingsMatch[1]);
|
||||
job.push({ type: 'exploration', data: { ...job.exploration } });
|
||||
}
|
||||
if (low.includes('exploration complete')) {
|
||||
const extraMatch = norm.match(/(\d+) extra finding/);
|
||||
if (job.exploration && extraMatch) job.exploration.totalExtra = parseInt(extraMatch[1]);
|
||||
job.push({ type: 'exploration', data: { ...job.exploration, complete: true } });
|
||||
}
|
||||
|
||||
const fj = norm.match(/^finding_json:\s*(.+)$/);
|
||||
if (fj) {
|
||||
try {
|
||||
@@ -2847,8 +2867,107 @@ const MIME = {
|
||||
'.md': 'text/plain; charset=utf-8',
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Authentication layer — JWT + scrypt, zero external deps.
|
||||
// When NS_JWT_SECRET is set, every /api/* request (except /api/auth/*) must
|
||||
// carry a valid Bearer token. When unset, auth is disabled (local dev mode).
|
||||
// ---------------------------------------------------------------------------
|
||||
const AUTH_ENABLED = !!process.env.NS_JWT_SECRET;
|
||||
const JWT_SECRET = process.env.NS_JWT_SECRET || 'dev-insecure-do-not-use';
|
||||
const JWT_EXPIRY_HOURS = 24;
|
||||
const AUTH_FILE = path.join(CONFIG_DIR, 'auth-users.json');
|
||||
const AUTH_RATE = new Map(); // ip -> { count, resetAt }
|
||||
const AUTH_RATE_MAX = 10;
|
||||
const AUTH_RATE_WINDOW = 60_000;
|
||||
|
||||
async function hashPassword(plain) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const salt = crypto.randomBytes(16);
|
||||
crypto.scrypt(plain, salt, 64, (err, dk) => {
|
||||
if (err) return reject(err);
|
||||
resolve(salt.toString('hex') + ':' + dk.toString('hex'));
|
||||
});
|
||||
});
|
||||
}
|
||||
async function verifyPassword(plain, stored) {
|
||||
const [saltHex, dkHex] = stored.split(':');
|
||||
const salt = Buffer.from(saltHex, 'hex');
|
||||
return new Promise((resolve, reject) => {
|
||||
crypto.scrypt(plain, salt, 64, (err, dk) => {
|
||||
if (err) return reject(err);
|
||||
resolve(crypto.timingSafeEqual(dk, Buffer.from(dkHex, 'hex')));
|
||||
});
|
||||
});
|
||||
}
|
||||
function jwtSign(payload) {
|
||||
const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
|
||||
const body = Buffer.from(JSON.stringify({ ...payload, iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + JWT_EXPIRY_HOURS * 3600 })).toString('base64url');
|
||||
const sig = crypto.createHmac('sha256', JWT_SECRET).update(`${header}.${body}`).digest('base64url');
|
||||
return `${header}.${body}.${sig}`;
|
||||
}
|
||||
function jwtVerify(token) {
|
||||
const parts = token.split('.');
|
||||
if (parts.length !== 3) return null;
|
||||
const sig = crypto.createHmac('sha256', JWT_SECRET).update(`${parts[0]}.${parts[1]}`).digest('base64url');
|
||||
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(parts[2]))) return null;
|
||||
try {
|
||||
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString());
|
||||
if (payload.exp && payload.exp < Math.floor(Date.now() / 1000)) return null;
|
||||
return payload;
|
||||
} catch { return null; }
|
||||
}
|
||||
async function loadAuthUsers() {
|
||||
try { return JSON.parse(await fsp.readFile(AUTH_FILE, 'utf8')); }
|
||||
catch { return []; }
|
||||
}
|
||||
async function saveAuthUsers(users) {
|
||||
await ensureConfigDir();
|
||||
await fsp.writeFile(AUTH_FILE, JSON.stringify(users, null, 2));
|
||||
}
|
||||
async function ensureDefaultUser() {
|
||||
const users = await loadAuthUsers();
|
||||
if (users.length > 0) return;
|
||||
const username = process.env.NS_DEFAULT_USER || 'neurosploit';
|
||||
const plainPass = process.env.NS_DEFAULT_PASSWORD || crypto.randomBytes(12).toString('base64url');
|
||||
const hashed = await hashPassword(plainPass);
|
||||
users.push({ username, password: hashed, role: 'admin', firstLogin: true, createdAt: new Date().toISOString() });
|
||||
await saveAuthUsers(users);
|
||||
if (!process.env.NS_DEFAULT_PASSWORD) {
|
||||
console.log(`\n Default credentials → ${username} / ${plainPass}\n Change after first login.\n`);
|
||||
}
|
||||
}
|
||||
function authRateCheck(ip) {
|
||||
const now = Date.now();
|
||||
let entry = AUTH_RATE.get(ip);
|
||||
if (!entry || now > entry.resetAt) { entry = { count: 0, resetAt: now + AUTH_RATE_WINDOW }; AUTH_RATE.set(ip, entry); }
|
||||
entry.count++;
|
||||
return entry.count <= AUTH_RATE_MAX;
|
||||
}
|
||||
function extractToken(req) {
|
||||
const auth = req.headers.authorization || '';
|
||||
if (auth.startsWith('Bearer ')) return auth.slice(7);
|
||||
const cookie = req.headers.cookie || '';
|
||||
const m = cookie.match(/(?:^|;\s*)ns_token=([^;]+)/);
|
||||
return m ? m[1] : null;
|
||||
}
|
||||
function requireAuth(req, res) {
|
||||
if (!AUTH_ENABLED) return { username: 'operator', role: 'admin' };
|
||||
const token = extractToken(req);
|
||||
if (!token) { sendJson(res, 401, { error: 'authentication required' }); return null; }
|
||||
const payload = jwtVerify(token);
|
||||
if (!payload) { sendJson(res, 401, { error: 'invalid or expired token' }); return null; }
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function serveStatic(req, res, urlPath) {
|
||||
let rel = urlPath === '/' ? '/index.html' : urlPath;
|
||||
// Auth gate for the SPA: redirect to /login.html when no valid token
|
||||
if (AUTH_ENABLED && (rel === '/index.html' || rel === '/')) {
|
||||
const token = extractToken(req);
|
||||
if (!token || !jwtVerify(token)) {
|
||||
rel = '/login.html';
|
||||
}
|
||||
}
|
||||
const full = path.join(PUBLIC_DIR, rel);
|
||||
if (!full.startsWith(PUBLIC_DIR)) { res.writeHead(403); res.end(); return; }
|
||||
try {
|
||||
@@ -2889,6 +3008,65 @@ const server = http.createServer(async (req, res) => {
|
||||
return serveStatic(req, res, p);
|
||||
}
|
||||
|
||||
// ---- auth endpoints (unauthenticated) ----
|
||||
if (p.startsWith('/api/auth/')) {
|
||||
const ip = req.headers['x-forwarded-for']?.split(',')[0]?.trim() || req.socket.remoteAddress || '';
|
||||
if (req.method === 'GET' && p === '/api/auth/status') {
|
||||
const users = await loadAuthUsers();
|
||||
return sendJson(res, 200, { enabled: AUTH_ENABLED, firstLogin: users.length > 0 && users[0].firstLogin === true, hasUsers: users.length > 0 });
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/auth/login') {
|
||||
if (!authRateCheck(ip)) return sendJson(res, 429, { error: 'too many attempts, try again later' });
|
||||
const body = await readBody(req);
|
||||
const { username, password } = body;
|
||||
if (!username || !password) return sendJson(res, 400, { error: 'username and password required' });
|
||||
const users = await loadAuthUsers();
|
||||
const user = users.find(u => u.username === username);
|
||||
if (!user) return sendJson(res, 401, { error: 'invalid credentials' });
|
||||
const ok = await verifyPassword(password, user.password);
|
||||
if (!ok) return sendJson(res, 401, { error: 'invalid credentials' });
|
||||
user.lastLogin = new Date().toISOString();
|
||||
await saveAuthUsers(users);
|
||||
const token = jwtSign({ username: user.username, role: user.role });
|
||||
res.setHeader('Set-Cookie', `ns_token=${token}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${JWT_EXPIRY_HOURS * 3600}`);
|
||||
return sendJson(res, 200, { token, username: user.username, role: user.role, firstLogin: !!user.firstLogin });
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/auth/change-password') {
|
||||
const auth = requireAuth(req, res); if (!auth) return;
|
||||
const body = await readBody(req);
|
||||
const { currentPassword, newPassword } = body;
|
||||
if (!newPassword || newPassword.length < 8) return sendJson(res, 400, { error: 'new password must be at least 8 characters' });
|
||||
const users = await loadAuthUsers();
|
||||
const user = users.find(u => u.username === auth.username);
|
||||
if (!user) return sendJson(res, 404, { error: 'user not found' });
|
||||
if (currentPassword) {
|
||||
const ok = await verifyPassword(currentPassword, user.password);
|
||||
if (!ok) return sendJson(res, 401, { error: 'current password is wrong' });
|
||||
}
|
||||
user.password = await hashPassword(newPassword);
|
||||
user.firstLogin = false;
|
||||
await saveAuthUsers(users);
|
||||
const token = jwtSign({ username: user.username, role: user.role });
|
||||
res.setHeader('Set-Cookie', `ns_token=${token}; HttpOnly; Path=/; SameSite=Strict; Max-Age=${JWT_EXPIRY_HOURS * 3600}`);
|
||||
return sendJson(res, 200, { ok: true, token });
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/auth/verify') {
|
||||
const auth = requireAuth(req, res); if (!auth) return;
|
||||
return sendJson(res, 200, { valid: true, username: auth.username, role: auth.role });
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/auth/logout') {
|
||||
res.setHeader('Set-Cookie', 'ns_token=; HttpOnly; Path=/; SameSite=Strict; Max-Age=0');
|
||||
return sendJson(res, 200, { ok: true });
|
||||
}
|
||||
return sendJson(res, 404, { error: 'not found' });
|
||||
}
|
||||
|
||||
// ---- auth gate: everything below /api/ requires a valid token ----
|
||||
if (AUTH_ENABLED && p.startsWith('/api/')) {
|
||||
const auth = requireAuth(req, res); if (!auth) return;
|
||||
req.authUser = auth;
|
||||
}
|
||||
|
||||
// ---- agents / lead board ----
|
||||
if (req.method === 'GET' && p === '/api/agents') {
|
||||
return sendJson(res, 200, await loadAgents());
|
||||
@@ -4174,6 +4352,7 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
loadPersistedJobs();
|
||||
loadKeys();
|
||||
ensureDefaultUser().catch(e => console.error('auth init error:', e.message));
|
||||
|
||||
// NEUROSPLOIT_WEB_HOST pins the bind address (the installer's launcher uses
|
||||
// 127.0.0.1); unset keeps the historical all-interfaces bind.
|
||||
|
||||
Reference in new issue
Block a user