Click thumbnail to download and view the demo video
Quick Start
- Clone & install
git clone https://github.com/ZhuohaoNi/Censys.git cd Censys npm install - Configure environment
cp .env.example .env.local # then edit .env.local OPENAI_API_KEY=sk-your-key OPENAI_MODEL=gpt-5-mini OPENAI_FALLBACK_MODEL=gpt-4o-mini - Run
npm run dev
- Open http://localhost:3000 and upload
docs/hosts_dataset.json.
Key Features (Short Version)
- Feature engineering: ports, CVEs (with severity & KEV flag), malware indicators, cert trust issues.
- Weighted risk scoring (capped factors) -> risk level classification.
- Per-host AI summary (gpt-5-mini) with automatic JSON schema validation & retry; fallback templated summary if model fails.
- Export (JSON + Markdown) and simple system/health endpoints.
- File-based TTL cache (default 1h) for idempotent summarization and analysis reuse.
Assignment Coverage
- Run Instructions: β (Quick Start above)
- Assumptions: β (see Assumptions section)
- Testing Instructions: β (Manual Testing section)
- Brief AI Techniques: β (AI Techniques section)
- Future Enhancements: β (Concise list below)
A security analysis tool for Censys host data that provides risk assessment and insights using AI-powered summaries.
- Host Data Analysis: Upload and analyze Censys JSON host data
- Risk Scoring: Multi-factor risk assessment with weighted scoring
- Observability stack
- Web Interface: View and manage host analyses
- Export Options: Export analyzed data in JSON or Markdown format
- Error Recovery: JSON parsing with automatic retry mechanisms
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- Validation: Zod schemas (runtime type safety)
- AI: Feature engineering (ports/CVEs/KEV/malware/certs) + explainable capped risk scoring + multi-model summaries (gpt-5-mini primary, gpt-4o-mini + template fallback) + schemaβvalidated structured output & retry/recovery
- Architecture: Unified frontend/backend via Route Handlers
- Caching: File-based TTL cache (1h, ephemeral)
Complete documentation is available in the docs/ folder:
- Assignment Brief - Original project requirements
- Technical Specification - Detailed implementation specs
- Dataset Description - Data format information
- Sample Dataset - Test data for the application
- Node.js 18+ and npm
- OpenAI API key (for AI-powered summaries)
- Clone the repository:
git clone https://github.com/ZhuohaoNi/Censys.git
cd Censys- Install dependencies:
npm install- Create
.env.localfile:
OPENAI_API_KEY=your_openai_api_key_here
# Optional: Configure OpenAI settings
OPENAI_MODEL=gpt-5-mini # or gpt-4o-mini
OPENAI_TIMEOUT=30000
OPENAI_MAX_RETRIES=3- Run the development server:
npm run dev- Open http://localhost:3000 in your browser
Navigate to the upload page and either:
- Drag and drop a Censys JSON file
- Click to browse and select a file
- Paste JSON data directly
After upload, you'll be redirected to the hosts list where you can:
- View all analyzed hosts with risk levels
- Click on any host for detailed information
- Generate AI summaries for individual hosts
Export analyzed data in multiple formats:
- JSON: Complete data with all fields
- Markdown: Human-readable report format
Analyze host data and calculate risk scores
Request: { hosts: Host[] }
Response: { hosts: AnalyzedHost[] }List all analyzed hosts
Response: { hosts: HostListItem[] }Get detailed host information
Response: Host & EngineeredFeaturesGenerate AI summaries for hosts
Request: { hostIds: string[] }
Response: { results: SummaryResult[] }Export data in various formats
Request: { hostIds: string[], format: 'json' | 'markdown' }
Response: File downloadThis project implements several AI and ML techniques:
Location: src/lib/feature-engineering.ts
- Risk Scoring: Transforms raw Censys data into engineered features using weighted algorithms
- Vulnerability Analysis: Categorizes CVEs by severity (Critical, High, Medium, Low) with specialized scoring
- Port Risk Assessment: Identifies administrative and high-risk ports (SSH:22, RDP:3389, MySQL:3306, etc.)
- Malware Detection: Binary classification for malware presence across services
- Certificate Analysis: Evaluates SSL/TLS certificates for self-signed and trust issues
Location: src/lib/openai.ts
- Primary: gpt-5-mini (higher quality summaries)
- Fallback: gpt-4o-mini if primary times out/errors
- Final Fallback: Template-based summary (no external API)
- JSON Schema Validation: Ensures consistent AI responses using Zod schemas
- Response Format Enforcement: Uses OpenAI's
json_objectresponse format - JSON Parser: Automatically fixes truncated or malformed JSON responses
-
System Prompts: Specialized cybersecurity analyst persona
-
Cybersecurity analyst persona
-
Context-Aware Prompts: Dynamic prompt generation based on host characteristics function generateUserPrompt(host: Host, features: EngineeredFeatures): string
-
Error Recovery: Automatic retry with feedback loops for invalid responses
Location: src/lib/persistent-cache.ts
- File-Based Persistence: Maintains state across server restarts
- TTL Management: Automatic expiration (1 hour default)
Location: src/lib/feature-engineering.ts
The system uses a multi-factor risk assessment:
| Factor | Weight | Implementation |
|---|---|---|
| Critical CVEs | 40 points max | 10 points per critical vulnerability |
| Malware Detection | 25 points | Binary classification with immediate scoring |
| KEV Vulnerabilities | 24 points max | 8 points per known exploited vulnerability |
| Admin Port Exposure | 8 points max | 2 points per exposed administrative port |
| Certificate Issues | 6 points max | 3 points per self-signed certificate |
| Non-standard SSH | 5 points | Penalty for SSH on non-standard ports |
- Critical (80-100): Immediate action required - malware or multiple critical CVEs
- High (50-79): Significant vulnerabilities present - critical CVEs or KEV
- Medium (25-49): Some concerns identified - multiple medium/high vulnerabilities
- Low (0-24): Minimal risk detected - few or no significant issues
The AI system generates human-readable security reports with:
- Executive Overview: Location, network context, and service purpose analysis
- Security Posture Assessment: Vulnerability analysis with risk contextualization
- Actionable Recommendations: Prioritized remediation steps based on risk factors
- Metrics Dashboard: Key performance indicators for security teams
- Data Quality: Assumes Censys data follows documented schema structure
- API Availability: OpenAI API is available; implements graceful fallback to template summaries
- Network Context: ASN and geographic data is reliable for risk assessment
- Vulnerability Scoring: CVSS scores when available; severity-based fallback
- Malware Classification: Binary detection based on Censys malware indicators
- Certificate Trust: Self-signed certificates are considered security risks
- Administrative Ports: Standard ports (22, 3389, 3306, etc.) are higher risk when exposed
βββ docs/ # π All documentation
β βββ README.md # Documentation index
β βββ assignment_brief.md # Project requirements
β βββ SPEC.md # Technical specifications
β βββ host_dataset_description.md # Data format docs
β βββ hosts_dataset.json # Sample test data
βββ src/
β βββ app/ # Next.js 14 App Router
β β βββ api/ # API route handlers
β β β βββ analyze/ # Risk analysis endpoint
β β β βββ export/ # Data export endpoints
β β β βββ health/ # Health check endpoint
β β β βββ hosts/ # Host CRUD operations
β β β βββ system/ # System utilities (cache, debug)
β β βββ hosts/ # Host listing and detail pages
β β β βββ [id]/ # Dynamic host detail page
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout component
β β βββ page.tsx # Upload page (home)
β βββ schemas/ # Zod validation schemas
β β βββ api.ts # API request/response schemas
β β βββ engineered-features.ts # Risk scoring schemas
β β βββ host.ts # Host data schemas
β β βββ summary.ts # AI summary schemas
β β βββ index.ts # Schema exports
β βββ lib/ # Core business logic
β βββ feature-engineering.ts # AI risk scoring algorithms
β βββ openai.ts # LLM integration & prompt engineering
β βββ persistent-cache.ts # File-based caching system
β βββ utils.ts # Utility functions
βββ .cache/ # Runtime cache (gitignored)
βββ .env.example # Environment variables template
βββ .env.local # Local environment variables (gitignored)
βββ .gitignore # Git ignore rules
βββ .next/ # Next.js build output (gitignored)
βββ next.config.js # Next.js configuration
βββ package.json # Dependencies and scripts
βββ postcss.config.js # PostCSS configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
βββ README.md
All data is validated using Zod schemas:
HostSchema: Validates input Censys dataEngineeredFeaturesSchema: Defines risk scoring outputSummarySchema: Structures AI-generated summaries
-
Upload Test Data:
# Use the provided sample dataset cp docs/hosts_dataset.json test-data.json- Navigate to http://localhost:3000
- Upload the
test-data.jsonfile - Verify successful parsing and redirect to hosts list
-
Risk Scoring Verification:
- Check that hosts are displayed with appropriate risk levels
- Verify risk scores are between 0-100
- Confirm color coding matches risk levels (red=critical, orange=high, etc.)
-
AI Summary Generation:
- Click on any host to view details
- Click "Generate AI Summary" button
- Verify summary contains all required sections:
- Overview (location, network, services)
- Security posture (vulnerabilities, malware)
- Recommendations (actionable steps)
- Key metrics (risk level, counts)
-
Export Functionality:
- From hosts list, select multiple hosts
- Test JSON export - verify complete data structure
- Test Markdown export - verify human-readable format
-
API Endpoint Testing:
# Test health endpoint curl http://localhost:3000/api/health # Test analyze endpoint with sample data curl -X POST http://localhost:3000/api/analyze \ -H "Content-Type: application/json" \ -d @docs/hosts_dataset.json
- Ensemble summarization & agreement scoring (quality lift; pick best of multi-model outputs).
Generate 2β3 candidate summaries (e.g., gpt-5-mini + smaller local + template), score for schema validity & feature coverage, surface best + optionally show disagreements. - Active learning loop (ingest user edits β update weighting / prompt hints).
Capture human edits to recommendations / risk rationale; feed into prompt hint store or lightweight adapter to reduce repeat errors and hallucinations. - Explainability API (/api/explain/[id]: per-factor risk contributions + evidence).
Returns normalized factor weights, raw signals (e.g., critical CVE count, admin ports), and plain-language justification to improve analyst trust. - Unsupervised anomaly detection (cluster/outlier hosts: rare ports, cert anomalies).
Apply clustering (DBSCAN/HDBSCAN) on engineered feature vectors; flag outliers (uncommon port/service combos, unusual cert chains) for prioritized review. - Domain fine-tuned lightweight model (reduced cost, higher remediation precision, fallback chain retained).
LoRA/adapter fine-tune on curated security summaries to cut token cost & increase specificity; retain existing fallback chain for resilience.