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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# VulnGraph
|
| 2 |
+
|
| 3 |
+
**AI-powered Application Security Posture Management (ASPM) platform.** Scans codebases for vulnerabilities and secrets, models attack paths as a graph, and generates LLM-powered explanations and code patches.
|
| 4 |
+
|
| 5 |
+
> β οΈ **For full functionality, run locally.** The deployed demo runs in static mode β scans, LLM explanations, and agent patches require a local environment with Neo4j and Ollama.
|
| 6 |
+
|
| 7 |
+
**Live Demo**
|
| 8 |
+
- Dashboard: https://vulngraph-dashboard.onrender.com
|
| 9 |
+
- API: https://vulngraph-api.onrender.com
|
| 10 |
+
- API Docs: https://vulngraph-api.onrender.com/docs
|
| 11 |
+
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
## What It Does
|
| 15 |
+
|
| 16 |
+
- **Scans** codebases using Gitleaks (secrets), Trivy (CVEs), and Bandit (SAST)
|
| 17 |
+
- **Models** findings as a Neo4j attack graph β files connected to vulnerabilities and secrets
|
| 18 |
+
- **Explains** each finding using a local LLM (llama3.2:3b via Ollama) augmented with RAG retrieval from a CWE/OWASP/Bandit knowledge base
|
| 19 |
+
- **Patches** vulnerabilities using a deterministic 5-step agentic pipeline
|
| 20 |
+
- **Exposes** tools over MCP so Claude Desktop and other AI clients can query your attack graph
|
| 21 |
+
- **Evaluates** LLM explanation quality using a custom RAGAS harness (relevancy, faithfulness, CWE accuracy)
|
| 22 |
+
- **Generates** SBOMs in CycloneDX and SPDX formats
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## Architecture
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
Scanners Graph DB AI Layer
|
| 30 |
+
βββββββββββββββββ ββββββββββ ββββββββββββββββββββββββββ
|
| 31 |
+
Gitleaks (secrets) βββΊ Neo4j βββΊ LLM explanations (Ollama)
|
| 32 |
+
Trivy (CVEs) βββΊ Attack graph βββΊ RAG pipeline (ChromaDB)
|
| 33 |
+
Bandit (SAST) βββΊ File nodes βββΊ Agent + patch generation
|
| 34 |
+
MCP server
|
| 35 |
+
FastAPI βββΊ Streamlit Dashboard
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## Real Findings
|
| 41 |
+
|
| 42 |
+
Tested against four codebases:
|
| 43 |
+
|
| 44 |
+
| Target | Gitleaks | Trivy | Bandit | Notable |
|
| 45 |
+
|--------|----------|-------|--------|---------|
|
| 46 |
+
| VulnGraph itself | HF token, AWS key | 2 CVEs | 11 findings | Own codebase |
|
| 47 |
+
| dvpwa (vulnerable Python app) | 0 | 48 CVEs | 2 findings | SQL injection (B608), MD5 (B324), PyYAML CRITICAL (CVE-2017-18342) |
|
| 48 |
+
| secretsandstuff | AWS key, GitHub token | 2 findings | 0 | Secret detection demo |
|
| 49 |
+
| Juice Shop | 11 secrets | 9 findings | 0 | JWT tokens, private keys, Docker misconfigs |
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## Local Setup
|
| 54 |
+
|
| 55 |
+
### Prerequisites
|
| 56 |
+
|
| 57 |
+
- Python 3.12
|
| 58 |
+
- Docker
|
| 59 |
+
- [Ollama](https://ollama.ai)
|
| 60 |
+
- Gitleaks and Trivy executables in `tools/`
|
| 61 |
+
|
| 62 |
+
### 1. Clone and install
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
git clone https://github.com/your-username/VulnGraph
|
| 66 |
+
cd VulnGraph
|
| 67 |
+
python -m venv .venv
|
| 68 |
+
.venv\Scripts\activate # Windows
|
| 69 |
+
pip install -r requirements.txt
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### 2. Start Neo4j
|
| 73 |
+
|
| 74 |
+
```bash
|
| 75 |
+
docker run -d \
|
| 76 |
+
--name vulngraph-neo4j \
|
| 77 |
+
-p 7474:7474 -p 7687:7687 \
|
| 78 |
+
-e NEO4J_AUTH=neo4j/vulngraph123 \
|
| 79 |
+
neo4j:5.25-community
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### 3. Start Ollama and pull model
|
| 83 |
+
|
| 84 |
+
```bash
|
| 85 |
+
ollama serve
|
| 86 |
+
ollama pull llama3.2:3b
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### 4. Configure environment
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
cp .env.example .env
|
| 93 |
+
# Edit .env with your values
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
`.env`:
|
| 97 |
+
```
|
| 98 |
+
NEO4J_URI=bolt://localhost:7687
|
| 99 |
+
NEO4J_USER=PLACEHOLDER
|
| 100 |
+
NEO4J_PASSWORD=PLACEHOLDER
|
| 101 |
+
OLLAMA_URL=http://localhost:11434
|
| 102 |
+
OLLAMA_MODEL=llama3.2:3b
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
### 5. Seed knowledge base
|
| 106 |
+
|
| 107 |
+
```bash
|
| 108 |
+
cd app
|
| 109 |
+
python rag.py
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### 6. Run
|
| 113 |
+
|
| 114 |
+
```bash
|
| 115 |
+
# Dashboard
|
| 116 |
+
streamlit run app/main.py
|
| 117 |
+
|
| 118 |
+
# API (separate terminal)
|
| 119 |
+
uvicorn app.api:app --reload --port 8000
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
---
|
| 123 |
+
|
| 124 |
+
## Scanning
|
| 125 |
+
|
| 126 |
+
### Scan your own codebase
|
| 127 |
+
|
| 128 |
+
Click **Run Full Scan** in the dashboard, or:
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
cd app
|
| 132 |
+
python scanner.py
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
### Scan an external repo (local)
|
| 136 |
+
|
| 137 |
+
```python
|
| 138 |
+
from scanner import scan_all
|
| 139 |
+
results = scan_all(target_dir="/path/to/repo")
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
### Scan via API (Git URL)
|
| 143 |
+
|
| 144 |
+
```bash
|
| 145 |
+
curl -X POST https://vulngraph-api.onrender.com/scan/repo \
|
| 146 |
+
-H "Content-Type: application/json" \
|
| 147 |
+
-d '{"repo_url": "https://github.com/anxolerd/dvpwa"}'
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
> Note: The `/scan/repo` endpoint clones and scans the repo but does not store results in Neo4j on the deployed version. For full pipeline including LLM explanations and graph visualization, run locally.
|
| 151 |
+
|
| 152 |
+
### Generate LLM explanations
|
| 153 |
+
|
| 154 |
+
```bash
|
| 155 |
+
python app/llm.py
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
### Generate patch for a finding
|
| 159 |
+
|
| 160 |
+
```bash
|
| 161 |
+
python app/agent.py --finding B404
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
---
|
| 165 |
+
|
| 166 |
+
## MCP Server (Claude Desktop)
|
| 167 |
+
|
| 168 |
+
Exposes VulnGraph tools over the Model Context Protocol so Claude Desktop can query your attack graph, retrieve security context, and generate patches.
|
| 169 |
+
|
| 170 |
+
Add to `%APPDATA%\Claude\claude_desktop_config.json`:
|
| 171 |
+
|
| 172 |
+
```json
|
| 173 |
+
{
|
| 174 |
+
"mcpServers": {
|
| 175 |
+
"vulngraph": {
|
| 176 |
+
"command": "C:\\path\\to\\VulnGraph\\.venv\\Scripts\\python.exe",
|
| 177 |
+
"args": ["C:\\path\\to\\VulnGraph\\app\\mcp_server.py"]
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
Available tools: `query_attack_graph`, `search_knowledge_base`, `get_file_context`, `generate_patch`, `get_finding_explanation`
|
| 184 |
+
|
| 185 |
+
---
|
| 186 |
+
|
| 187 |
+
## API Endpoints
|
| 188 |
+
|
| 189 |
+
| Method | Path | Description |
|
| 190 |
+
|--------|------|-------------|
|
| 191 |
+
| GET | `/health` | Service health check |
|
| 192 |
+
| GET | `/stats` | Scan metrics |
|
| 193 |
+
| GET | `/findings` | All findings (filterable by severity, source) |
|
| 194 |
+
| GET | `/findings/{id}` | Single finding with LLM explanation |
|
| 195 |
+
| GET | `/graph` | Attack path graph as JSON |
|
| 196 |
+
| GET | `/sbom` | SBOM in CycloneDX or SPDX format |
|
| 197 |
+
| POST | `/scan` | Trigger full scan |
|
| 198 |
+
| POST | `/scan/repo` | Scan a public GitHub repo by URL |
|
| 199 |
+
| POST | `/explain` | Generate LLM explanations |
|
| 200 |
+
| POST | `/agent/fix` | Run agent to generate code patch |
|
| 201 |
+
|
| 202 |
+
---
|
| 203 |
+
|
| 204 |
+
## LLM Evaluation
|
| 205 |
+
|
| 206 |
+
Measures explanation quality against a ground truth dataset using three metrics:
|
| 207 |
+
|
| 208 |
+
- **Relevancy (50%)** β does the explanation address the actual vulnerability?
|
| 209 |
+
- **Faithfulness (30%)** β does it align with RAG-retrieved context?
|
| 210 |
+
- **CWE Accuracy (20%)** β was the correct CWE identified?
|
| 211 |
+
|
| 212 |
+
```bash
|
| 213 |
+
python app/eval.py
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
Model comparison results:
|
| 217 |
+
|
| 218 |
+
| Model | Pass Rate | Avg Overall |
|
| 219 |
+
|-------|-----------|-------------|
|
| 220 |
+
| llama3.2:3b | 66.7% | 0.600 |
|
| 221 |
+
| phi3 | 33.3% | 0.547 |
|
| 222 |
+
| gemma2:2b | 33.3% | 0.563 |
|
| 223 |
+
| qwen2.5:1.5b | 16.7% | 0.538 |
|
| 224 |
+
|
| 225 |
+
---
|
| 226 |
+
|
| 227 |
+
## Tech Stack
|
| 228 |
+
|
| 229 |
+
| Layer | Technology |
|
| 230 |
+
|-------|-----------|
|
| 231 |
+
| Scanners | Gitleaks, Trivy, Bandit |
|
| 232 |
+
| Graph DB | Neo4j 5.25 |
|
| 233 |
+
| LLM | llama3.2:3b via Ollama |
|
| 234 |
+
| RAG | ChromaDB + sentence-transformers + BM25 hybrid |
|
| 235 |
+
| Backend | FastAPI |
|
| 236 |
+
| Frontend | Streamlit |
|
| 237 |
+
| Agent | Deterministic 5-step pipeline |
|
| 238 |
+
| MCP | Model Context Protocol (Anthropic) |
|
| 239 |
+
| CI/CD | GitHub Actions |
|
| 240 |
+
| Deployment | Render |
|
| 241 |
+
|
| 242 |
+
---
|
| 243 |
+
|
| 244 |
+
## Project Structure
|
| 245 |
+
|
| 246 |
+
```
|
| 247 |
+
VulnGraph/
|
| 248 |
+
βββ app/
|
| 249 |
+
β βββ main.py # Streamlit dashboard
|
| 250 |
+
β βββ api.py # FastAPI backend
|
| 251 |
+
β βββ scanner.py # Gitleaks + Trivy + Bandit pipeline
|
| 252 |
+
β βββ llm.py # LLM explanation generation
|
| 253 |
+
β βββ rag.py # ChromaDB RAG + BM25 hybrid retrieval
|
| 254 |
+
β βββ schemas.py # Pydantic validation models
|
| 255 |
+
β βββ eval.py # LLM evaluation harness
|
| 256 |
+
β βββ agent.py # Deterministic agentic pipeline
|
| 257 |
+
β βββ tools.py # Agent tool implementations
|
| 258 |
+
β βββ mcp_server.py # MCP server
|
| 259 |
+
β βββ pages/
|
| 260 |
+
β βββ 2_π_Eval_Dashboard.py
|
| 261 |
+
βββ .github/workflows/
|
| 262 |
+
β βββ scan.yml # Security scan CI
|
| 263 |
+
β βββ eval.yml # LLM eval CI
|
| 264 |
+
βββ data/
|
| 265 |
+
β βββ chroma/ # ChromaDB vector store
|
| 266 |
+
βββ tools/ # Gitleaks and Trivy executables
|
| 267 |
+
βββ gitleaks.toml # Custom secret detection rules
|
| 268 |
+
```
|
| 269 |
+
## RAG Pipeline
|
| 270 |
+
|
| 271 |
+
VulnGraph uses a hybrid retrieval system combining vector search and BM25 keyword search for accurate security context retrieval.
|
| 272 |
+
|
| 273 |
+
### How it works
|
| 274 |
+
|
| 275 |
+
1. **Query expansion** β finding IDs are expanded with domain-specific terms (e.g. `B404` β `B404 subprocess import command injection OS command CWE-78`)
|
| 276 |
+
2. **Metadata filtering** β Bandit findings only search Bandit + OWASP docs, CVE findings only search CWE + OWASP docs, preventing cross-source contamination
|
| 277 |
+
3. **Vector search** β ChromaDB with `all-MiniLM-L6-v2` embeddings retrieves semantically similar documents
|
| 278 |
+
4. **BM25 search** β keyword search finds exact rule ID matches that vector search misses
|
| 279 |
+
5. **Fusion scoring** β results combined with weighted score: Vector (60%) + BM25 (40%)
|
| 280 |
+
|
| 281 |
+
### Impact
|
| 282 |
+
|
| 283 |
+
Before hybrid RAG, B404 retrieval returned unrelated crypto documents (B304 at 34.6%). After:
|
| 284 |
+
|
| 285 |
+
| Finding | Before | After |
|
| 286 |
+
|---------|--------|-------|
|
| 287 |
+
| B404 | B304 weak cipher (34.6%) | B404 subprocess (74.0%) |
|
| 288 |
+
| B105 | Unknown | B105 hardcoded password (80.0%) |
|
| 289 |
+
|
| 290 |
+
Knowledge base: 120 documents β 26 CWE definitions, 10 OWASP Top 10 (2025), 84 Bandit rules
|