How tencent/ai-infra-guard works
Based on your review of the file tree and README, this project is an AI infrastructure security assessment tool called “AI Infra Guard.” Its purpose is to scan AI systems for security risks by matching web fingerprints and vulnerabilities using YAML rules. The tool supports both a command-line interface (CLI) and a web user interface (WEBUI), while its core engine processes various rules against target systems.
• Command-Line Interface (CLI): Represented by the “cmd/cli” package. This is the entry point when running in CLI mode.
• Web User Interface: Indicated by “common/websocket” which serves static files (index.html, bundle.js) to provide a web-based scan dashboard.
• Fingerprint & Vulnerability Processing Engine:
• Fingerprint Matching: Found in the “common/fingerprints” directory (with submodules for parsing, preloading, etc.) and the YAML definitions under “data/fingerprints.”
• Vulnerability Matching: Handled in part by the “pkg/vulstruct” package; YAML definitions for vulnerabilities are stored under “data/vuln.”
• Core Scanner & Runner: The “common/runner” package is responsible for scanning, executing HTTP requests, and aggregating results.
• HTTP Client Utilities: Provided by “pkg/httpx” for performing web requests during scan operations.
• External AI Integration: The README mentions AI analysis when using tokens (e.g. hunyuan token, deepseek token). The “pkg/openai” package (and similar integration points) are involved here.
• Logging & Configuration: Internal modules under “internal/gologger” and “internal/options” support logging, banner display, and configuration management.
• Data & YAML Rule Configuration: The “data” directory holds the external fingerprint and vulnerability YAML rules, which form the “knowledge base” that drives the scanner’s behavior.
Relationships and Interactions
• The user interacts either via the CLI (by providing flags like “-target” or “-localscan”) or via the WEBUI.
• In both modes, the system loads rule definitions (fingerprints & vulnerabilities) from the “data” folder.
• The scanning engine (in “common/runner”) uses utilities (in “pkg/httpx”) to send HTTP requests to target services.
• The fingerprint processing modules validate responses using the logic in “common/fingerprints” (parsers, matchers).
• When vulnerability checks are triggered, the “pkg/vulstruct” component processes those outcomes against vulnerability definitions.
• If running in WEBUI mode, the web server component in “common/websocket/server.go” serves static content and might push results via websockets.
• Optionally, if AI-based analysis is triggered, calls might be made through the AI integrations (e.g., “pkg/openai”).
• Logging and configuration are centrally handled by the “internal” packages, making sure that runtime parameters and output are managed cleanly.
Important Architectural Patterns and Technologies
• Modularity: Each major function (UI, fingerprint parsing, vulnerability matching, HTTP communications) is neatly separated across packages.
• YAML-Driven Configuration: The system uses external YAML files to define fingerprints and vulnerability matching rules, which allows for easy updates to security definitions.
• Lightweight and Efficient Design: Emphasized in the README – small binary, cross-platform support.
• Command Design: A clear separation between input interfaces (CLI vs. WEBUI) and the scanning engine.