import crypto from 'node:crypto'; import http from 'node:http'; import https from 'node:https'; const publicURL = process.env.SEA_PUBLIC_TARGET_URL?.trim() || process.env.SEA_CONSOLE_URL?.trim(); const panelURL = process.env.SEA_PANEL_URL?.trim(); const insecureTLS = process.env.SEA_PUBLIC_TLS_INSECURE === 'true' || process.env.SEA_PANEL_TLS_INSECURE === 'true'; if (!publicURL) { console.error('SEA_PUBLIC_TARGET_URL or SEA_CONSOLE_URL is required.'); process.exit(2); } function parseTarget(value, label) { const target = new URL(value); if (!['http:', 'https:'].includes(target.protocol) || target.username || target.password) { throw new Error(`${label} must be an HTTP(S) URL without embedded credentials`); } return target; } const publicTarget = parseTarget(publicURL, 'public target'); const panelTarget = panelURL ? parseTarget(panelURL, 'panel target') : undefined; const probeID = crypto.randomBytes(8).toString('hex'); const attackerHost = `${probeID}.attacker.invalid`; const maxBodyBytes = 512 * 1024; const results = []; function record(level, name, detail) { results.push({ level, name, detail }); } function requestOnce(target, path, { method = 'GET', headers = {}, body } = {}) { const transport = target.protocol === 'https:' ? https : http; const payload = body === undefined ? undefined : Buffer.from(body); const agent = target.protocol === 'https:' ? new https.Agent({ rejectUnauthorized: !insecureTLS }) : undefined; return new Promise((resolve, reject) => { const req = transport.request({ protocol: target.protocol, hostname: target.hostname, port: target.port || undefined, ...(target.protocol === 'https:' ? { servername: target.hostname } : {}), method, path, agent, timeout: 10_000, headers: { Host: target.host, 'User-Agent': 'Sea-vHost-public-security-smoke/1.0', Accept: '*/*', Connection: 'close', ...(payload ? { 'Content-Length': payload.length } : {}), ...headers, }, }, (response) => { const chunks = []; let length = 0; let truncated = false; response.on('data', (chunk) => { if (length >= maxBodyBytes) { truncated = true; return; } const remaining = maxBodyBytes - length; chunks.push(chunk.subarray(0, remaining)); length += Math.min(chunk.length, remaining); if (chunk.length > remaining) truncated = true; }); response.on('end', () => resolve({ status: response.statusCode ?? 0, headers: response.headers, body: Buffer.concat(chunks).toString('utf8'), truncated, })); }); req.on('timeout', () => req.destroy(new Error('request timed out'))); req.on('error', reject); req.end(payload); }); } async function request(target, path, options = {}) { let lastError; for (let attempt = 0; attempt < 2; attempt += 1) { try { return await requestOnce(target, path, options); } catch (error) { lastError = error; if (attempt === 0) await new Promise((resolve) => setTimeout(resolve, 250)); } } throw lastError; } function websocketHandshakeOnce(target, path) { const transport = target.protocol === 'https:' ? https : http; const agent = target.protocol === 'https:' ? new https.Agent({ rejectUnauthorized: !insecureTLS }) : undefined; return new Promise((resolve, reject) => { let settled = false; const finish = (value) => { if (settled) return; settled = true; resolve(value); }; const req = transport.request({ protocol: target.protocol, hostname: target.hostname, port: target.port || undefined, ...(target.protocol === 'https:' ? { servername: target.hostname } : {}), method: 'GET', path, agent, timeout: 10_000, headers: { Host: target.host, Origin: 'https://attacker.invalid', Upgrade: 'websocket', Connection: 'Upgrade', 'Sec-WebSocket-Key': crypto.randomBytes(16).toString('base64'), 'Sec-WebSocket-Version': '13', 'User-Agent': 'Sea-vHost-public-security-smoke/1.0', }, }); req.on('upgrade', (response, socket) => { socket.destroy(); finish({ status: response.statusCode ?? 101, upgraded: true }); }); req.on('response', (response) => { response.resume(); response.on('end', () => finish({ status: response.statusCode ?? 0, upgraded: false })); }); req.on('timeout', () => req.destroy(new Error('WebSocket handshake timed out'))); req.on('error', reject); req.end(); }); } async function websocketHandshake(target, path) { let lastError; for (let attempt = 0; attempt < 2; attempt += 1) { try { return await websocketHandshakeOnce(target, path); } catch (error) { lastError = error; if (attempt === 0) await new Promise((resolve) => setTimeout(resolve, 500)); } } throw lastError; } const digest = (value) => crypto.createHash('sha256').update(value).digest('hex'); const deniedStatus = (status) => [400, 401, 403, 404, 405, 410, 421].includes(status); const disclosureSignatures = [ /root:x:0:0:/i, /\[core\][\s\S]{0,200}repositoryformatversion/i, /(?:DB_PASSWORD|DATABASE_URL|APP_KEY|SEA_PANEL_API_KEY)\s*=/i, /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/, /(?:CREATE TABLE|INSERT INTO)\s+[`"[]/i, /)/i, /PHP Version\s*(?:<|=>)/i, /"(?:propertySources|activeProfiles)"\s*:/i, /"openapi"\s*:\s*"3\./i, ]; async function main() { const baseline = await request(publicTarget, publicTarget.pathname || '/'); if (baseline.status < 200 || baseline.status >= 400) record('warning', 'public baseline', `HTTP ${baseline.status}`); else record('passed', 'public baseline', `HTTP ${baseline.status}`); const baselineDigest = digest(baseline.body); const server = String(baseline.headers.server ?? ''); if (/\d+\.\d+/.test(server)) record('warning', 'server version disclosure', server); else record('passed', 'server version disclosure', server || 'header absent'); if (baseline.headers['x-powered-by']) record('warning', 'framework disclosure', String(baseline.headers['x-powered-by'])); else record('passed', 'framework disclosure', 'X-Powered-By absent'); for (const [header, expected] of [ ['x-content-type-options', /nosniff/i], ['x-frame-options', /deny|sameorigin/i], ['content-security-policy', /default-src/i], ['referrer-policy', /./], ['permissions-policy', /./], ]) { const value = String(baseline.headers[header] ?? ''); record(expected.test(value) ? 'passed' : 'warning', `header ${header}`, value || 'missing'); } if (publicTarget.protocol === 'https:') { const hsts = String(baseline.headers['strict-transport-security'] ?? ''); record(/max-age=\d+/i.test(hsts) ? 'passed' : 'warning', 'HTTPS HSTS', hsts || 'missing'); } else { record('warning', 'transport security', 'target uses plain HTTP; acceptable only for the disposable forwarded test endpoint'); } for (const method of ['TRACE', 'TRACK', 'PUT', 'DELETE', 'PATCH']) { const response = await request(publicTarget, `/sea-vhost-method-probe-${probeID}`, { method }); record(deniedStatus(response.status) ? 'passed' : 'failed', `dangerous method ${method}`, `HTTP ${response.status}`); } const sensitivePaths = [ '/.env', '/.git/config', '/.svn/entries', '/.hg/store/fncache', '/config.json', '/config.yml', '/backup.zip', '/site.tar.gz', '/database.sql', '/composer.json', '/package.json', '/go.mod', '/requirements.txt', '/WEB-INF/web.xml', '/server-status', '/nginx_status', '/phpinfo.php', '/info.php', '/debug/pprof/', '/actuator/env', '/actuator/heapdump', '/swagger/index.html', '/openapi.json', '/api-docs', '/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php', '/cgi-bin/status', ]; let sensitiveDenied = 0; let sensitiveSPAFallback = 0; let sensitiveWarnings = 0; for (const path of sensitivePaths) { const response = await request(publicTarget, path); if (disclosureSignatures.some((pattern) => pattern.test(response.body))) { record('failed', `sensitive path ${path}`, `HTTP ${response.status}, disclosure signature found`); } else if (deniedStatus(response.status) || [301, 302, 307, 308].includes(response.status)) { sensitiveDenied += 1; } else if (response.status === baseline.status && digest(response.body) === baselineDigest) { sensitiveSPAFallback += 1; } else if (response.status >= 200 && response.status < 300) { sensitiveWarnings += 1; record('warning', `sensitive path ${path}`, `distinct HTTP ${response.status} response; inspect manually`); } else { sensitiveDenied += 1; } } record('passed', 'common sensitive and exploit paths', `${sensitiveDenied} denied/redirected, ${sensitiveSPAFallback} SPA fallbacks, ${sensitiveWarnings} manual warnings`); const traversalPaths = [ '/..%2f..%2f..%2fetc%2fpasswd', '/%2e%2e/%2e%2e/%2e%2e/etc/passwd', '/%252e%252e%252f%252e%252e%252fetc%252fpasswd', '/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd', '/api/v1/projects/1/files?path=..%2F..%2Fetc%2Fpasswd', ]; for (const path of traversalPaths) { const response = await request(publicTarget, path); const leaked = /root:x:0:0:/.test(response.body); record(leaked ? 'failed' : 'passed', `path traversal ${path}`, leaked ? 'passwd signature returned' : `HTTP ${response.status}, no passwd signature`); } const unauthenticated = await request(publicTarget, '/api/v1/dashboard', { headers: { Origin: 'https://attacker.invalid' }, }); const allowOrigin = String(unauthenticated.headers['access-control-allow-origin'] ?? ''); if (![401, 403, 404].includes(unauthenticated.status)) record('failed', 'unauthenticated API', `HTTP ${unauthenticated.status}`); else record('passed', 'unauthenticated API', `HTTP ${unauthenticated.status}`); record(allowOrigin === '*' || allowOrigin.includes('attacker.invalid') ? 'failed' : 'passed', 'CORS origin reflection', allowOrigin || 'no permissive ACAO'); const crossOrigin = await request(publicTarget, '/api/v1/auth/login', { method: 'POST', headers: { Origin: 'https://attacker.invalid', 'Content-Type': 'application/json' }, body: JSON.stringify({ identifier: `probe-${probeID}@invalid.test`, password: `invalid-${probeID}` }), }); record(crossOrigin.status === 403 ? 'passed' : 'failed', 'cross-origin state request', `HTTP ${crossOrigin.status}`); const hostProbe = await request(publicTarget, '/api/v1/dashboard', { headers: { Host: attackerHost } }); const hostLocation = String(hostProbe.headers.location ?? ''); const hostReflected = hostLocation.includes(attackerHost) || hostProbe.body.includes(attackerHost); record(!hostReflected && [400, 403, 404, 421].includes(hostProbe.status) ? 'passed' : 'failed', 'Host header boundary', `HTTP ${hostProbe.status}, reflected=${hostReflected}`); const forwardedProbe = await request(publicTarget, '/api/v1/dashboard', { headers: { 'X-Forwarded-Host': attackerHost, 'X-Forwarded-Proto': 'https', Forwarded: `host=${attackerHost};proto=https`, }, }); const forwardedLocation = String(forwardedProbe.headers.location ?? ''); const forwardedReflected = forwardedLocation.includes(attackerHost) || forwardedProbe.body.includes(attackerHost); record(forwardedReflected ? 'failed' : 'passed', 'forwarded Host reflection', `HTTP ${forwardedProbe.status}, reflected=${forwardedReflected}`); for (const path of [ `/?next=https%3A%2F%2F${attackerHost}%2F`, `/login?redirect=%2F%2F${attackerHost}%2F`, `/api/v1/auth/login?returnUrl=https%3A%2F%2F${attackerHost}%2F`, ]) { const response = await request(publicTarget, path); const location = String(response.headers.location ?? ''); let external = false; try { external = Boolean(location) && new URL(location, publicTarget).hostname === attackerHost; } catch { external = true; } record(external ? 'failed' : 'passed', `open redirect ${path.split('?')[0]}`, location || `HTTP ${response.status}, no Location`); } const xssPayload = ``; const xssProbe = await request(publicTarget, `/?q=${encodeURIComponent(xssPayload)}`); record(xssProbe.body.includes(xssPayload) ? 'failed' : 'passed', 'reflected XSS probe', xssProbe.body.includes(probeID) ? 'marker reflected without raw payload' : 'payload not reflected'); const scriptSources = [...baseline.body.matchAll(/]+src=["']([^"']+\.js)["']/gi)].map((match) => match[1]).slice(0, 12); let exposedMaps = 0; for (const source of scriptSources) { const sourceURL = new URL(source, publicTarget); const response = await request(publicTarget, `${sourceURL.pathname}.map`); if (response.status === 200 && /"sources"\s*:/.test(response.body) && /"mappings"\s*:/.test(response.body)) exposedMaps += 1; } record(exposedMaps ? 'warning' : 'passed', 'JavaScript source maps', exposedMaps ? `${exposedMaps} source map(s) exposed` : 'none exposed'); if (panelTarget) { const panelEndpoints = [ ['/crontab', 'action=GetCrontab'], ['/site', 'action=get_site_types'], ['/database', 'action=GetList'], ['/ftp', 'action=get_list'], ['/system', 'action=GetSystemTotal'], ]; for (const [path, body] of panelEndpoints) { const response = await request(panelTarget, path, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body, }); let privileged = false; try { const payload = JSON.parse(response.body); privileged = payload?.status === true || Array.isArray(payload?.data) || Array.isArray(payload); } catch { /* login/security-entry HTML is not privileged API data */ } record(privileged ? 'failed' : 'passed', `aaPanel unauthenticated ${path}`, `HTTP ${response.status}, privileged_data=${privileged}`); } const forgedToken = new URLSearchParams({ action: 'GetCrontab', request_time: Math.floor(Date.now() / 1000).toString(), request_token: crypto.randomBytes(16).toString('hex'), }).toString(); const forgedResponse = await request(panelTarget, '/crontab', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: forgedToken, }); let forgedPrivileged = false; try { const payload = JSON.parse(forgedResponse.body); forgedPrivileged = payload?.status === true || Array.isArray(payload?.data) || Array.isArray(payload); } catch { /* login/security-entry HTML is not privileged API data */ } record(forgedPrivileged ? 'failed' : 'passed', 'aaPanel forged API signature', `HTTP ${forgedResponse.status}, privileged_data=${forgedPrivileged}`); for (const path of [ '/sock_shell', '/webssh', '/ws_panel', '/ws_home', '/ws_project', '/ws_model', '/workorder_client', '/v2/sock_shell', '/v2/webssh', '/v2/ws_panel', '/v2/ws_home', '/v2/ws_project', '/v2/ws_model', ]) { const handshake = await websocketHandshake(panelTarget, path); record(handshake.upgraded ? 'failed' : 'passed', `aaPanel cross-origin WebSocket ${path}`, `HTTP ${handshake.status}, upgraded=${handshake.upgraded}`); } for (const path of ['/.env', '/config/config.json', '/data/default.db', '/www/server/panel/data/default.db']) { const response = await request(panelTarget, path); const leaked = disclosureSignatures.some((pattern) => pattern.test(response.body)) || response.body.startsWith('SQLite format 3'); record(leaked ? 'failed' : 'passed', `aaPanel sensitive path ${path}`, leaked ? 'disclosure signature found' : `HTTP ${response.status}, no disclosure signature`); } } const failed = results.filter((item) => item.level === 'failed'); const warnings = results.filter((item) => item.level === 'warning'); console.log(JSON.stringify({ status: failed.length ? 'failed' : 'passed', target: publicTarget.origin, panelTarget: panelTarget?.origin, probeID, summary: { passed: results.filter((item) => item.level === 'passed').length, warnings: warnings.length, failed: failed.length, }, warnings, failed, }, null, 2)); if (failed.length) process.exitCode = 1; } main().catch((error) => { console.error(`Public vulnerability smoke failed: ${error instanceof Error ? error.message : 'unknown error'}`); process.exitCode = 1; });