How ed1s0nz/privhunterai works
Project Type and Purpose
• PrivHunterAI is a Go-based security tool that passively intercepts HTTP(S) traffic (via a built-in MITM proxy), analyzes request/response pairs using AI engines (e.g., GPT, DeepSeek) to detect authorization bypass vulnerabilities, and exposes both a CLI interface and a lightweight web dashboard.
File Structure Analysis
• Top-level files:
• main.go – CLI entrypoint that initializes modules (config, proxy, scanner, web).
• mitmproxy.go – Sets up an HTTP/HTTPS proxy (listening on 9080) to capture traffic.
• scan.go – Core scanning orchestration: feeding intercepted requests to AI logic.
• AIAPIS/aiapis.go – Adapter for different AI providers’ HTTP APIs.
• config/config.go & config.json – Configuration loader for AI model, API keys, headers, filters.
• tools.go – Common utilities (e.g., JSON diff, dynamic-field filtering).
• index.go + index.html + img/ – Web server handlers and static assets (dashboard on port 8222).
• go.mod/go.sum – Module declarations and dependencies.
Key Components
a. Proxy Layer:
• MITM Proxy (mitmproxy.go) intercepts client → server HTTP(S) traffic.
b. Scanner Core:
• scan.go orchestrates preprocessing, invokes tools.go utilities, calls AIAPIS adapter.
c. AI Engine Integration:
• AIAPIS module relays formatted prompts to external AI services (GPT, Kimi, etc.) and returns analysis.
d. Configuration Module:
• config module loads config.json (API keys, filters, header rules).
e. Persistence/State (In-Memory):
• Scanner holds transient request/response records; no external DB is defined.
f. Web Dashboard:
• index.go serves REST endpoints and UI (index.html + img assets) for real-time results on port 8222.
g. CLI Interface:
• main.go CLI flags to start proxy, scan workflows, and optionally launch web server.
Component Interactions & Data Flow
1. User configures config.json → runs privhunterai binary.
2. main.go reads config → starts MITM proxy and scanner loop.
3. Client (e.g., browser or BurpSuite) routes traffic through proxy.
4. mitmproxy captures Request A, forwards to real server, captures Response A; then modifies credentials (Request B) as per headers2, captures Response B.
5. scan.go passes reqA, respA, respB to preprocessing (tools filter dynamic fields, identify read/write) → invokes AIAPIS with a JSON prompt.
6. AIAPIS sends HTTP request to external AI provider → receives analysis JSON.
7. scan.go applies decision tree → constructs result object (res, reason, confidence).
8. Results are stored in memory and forwarded to:
• CLI stdout renderer
• Web server endpoint (index.go)
9. User views results in terminal or navigates to 127.0.0.1:8222 in browser to see dashboard.
Architectural Patterns & Principles
• Modular Separation: proxy, scanner logic, AI adapter, config, web server are cleanly separated.
• Adapter Pattern: AIAPIS abstracts multiple AI providers under a common interface.
• Pipeline/Chain of Responsibility: scan.go steps through preprocessing, quick channel, deep analysis.
• Inversion of Control: main.go wires components based on config.