| 1 | """Seed the knowledge graph with archetypes, sink classes, and the P1 impact |
| 2 | families (the severity gate). Idempotent.""" |
| 3 | import os, sys |
| 4 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "memory")) |
| 5 | from memory import Memory |
| 6 | |
| 7 | ARCHETYPES = { |
| 8 | "ml-model-loaders": "Model-file & inference parsers (GGUF/ONNX/safetensors/pickle/joblib) - load-time RCE. Headline.", |
| 9 | "ai-agent-mcp": "Agent/tool-runners & MCP servers - tool-abuse, sandbox escape, SSRF->RCE.", |
| 10 | "devops-infra": "Self-hosted infra (Jenkins/Grafana/Redis/Jupyter/Argo) - unauth RCE, SSRF->metadata.", |
| 11 | "electron-desktop": "Electron apps (Obsidian/Cursor/Discord) - renderer-XSS->node, protocol-handler RCE.", |
| 12 | "cicd-supplychain": "CI/CD & supply chain - workflow injection, runner takeover, dependency confusion.", |
| 13 | "memory-unsafe-parsers": "Image/archive/font/serialization C/C++ libs - fuzz->memory corruption->RCE.", |
| 14 | } |
| 15 | |
| 16 | SINKCLASSES = [ |
| 17 | ("memory-corruption", "CWE-787", "RCE via Memory Corruption"), |
| 18 | ("deserialization", "CWE-502", "RCE via Deserialization"), |
| 19 | ("command-injection", "CWE-78", "RCE via Command Injection"), |
| 20 | ("template-injection", "CWE-1336","RCE via Template Injection"), |
| 21 | ("sql-injection", "CWE-89", "RCE/Data via SQL Injection"), |
| 22 | ("path-traversal", "CWE-22", "Arbitrary File Read/Write -> Secrets/RCE"), |
| 23 | ("ssrf", "CWE-918", "SSRF -> Metadata/Internal/RCE"), |
| 24 | ("xxe", "CWE-611", "XXE -> Internal File Read"), |
| 25 | ("auth-bypass", "CWE-287", "Authentication Bypass / ATO"), |
| 26 | ("electron-rce", "CWE-94", "One-Click/Zero-Click RCE"), |
| 27 | ("container-escape", "CWE-269", "Container/VM/Sandbox Escape"), |
| 28 | ("ssti-upload-rce", "CWE-434", "RCE via File Upload"), |
| 29 | ] |
| 30 | |
| 31 | def main(): |
| 32 | m = Memory() |
| 33 | for name, desc in ARCHETYPES.items(): |
| 34 | m.upsert_archetype(name, desc) |
| 35 | for name, cwe, fam in SINKCLASSES: |
| 36 | m._exec("""MERGE (s:SinkClass {name:$n}) |
| 37 | SET s.cwe=$c, s.impact_family=$f""", |
| 38 | {"n": name, "c": cwe, "f": fam}) |
| 39 | print("seeded archetypes:", len(ARCHETYPES), "sink classes:", len(SINKCLASSES)) |
| 40 | print("graph:", m.stats()) |
| 41 | |
| 42 | if __name__ == "__main__": |
| 43 | main() |