Intel Graph — Neo4j Attack Knowledge Graph
The model writes Cypher directly to Neo4j using the mcp__neo4j__write_cypher and mcp__neo4j__read_cypher MCP tools. The model determines what entities and relationships exist in the data — this is LLM judgment, not scripted extraction.
When to Activate
- Any offensive security engagement (CTF, pentest, lab, red team)
- At the start of every attack session
- After context compaction (recovery read)
Before Any Attack Action (MANDATORY)
Before calling ANY kali MCP tool that targets a service, endpoint, or vulnerability:
- Query disproven attack classes — entire categories ruled out:
MATCH (ac:attack_class)-[:ON_TARGET]->(tgt:target {name: $targetName})
WHERE ac.status = 'disproven'
RETURN ac.key, ac.reason, ac.blocked_techniques
If your planned technique falls within a disproven class, STOP. Choose a different class entirely.
- Query prior attempts on the target:
MATCH (a:attempt)-[:TRIED_ON]->(target)
WHERE target.addr = $targetIp OR target.key CONTAINS $targetIp
RETURN a.technique, a.tool, a.outcome, a.output_summary, a.error_signature
ORDER BY a.created_at DESC
- Query untested edges — credentials or services not yet tried:
MATCH (c:credential)-[r:AUTHENTICATES_TO {status: 'untested'}]->(s:service)
WHERE s.key STARTS WITH $targetIp
RETURN c.key, s.service
-
Decide: If the attack class is disproven, do NOT try any variant — the entire class is dead. If the same technique already failed and nothing has materially changed, do NOT retry. Choose a different technique or gather new intel first.
-
After execution, immediately RECORD:
MERGE (a:attempt {key: 'att:<technique>:<tool>@<target_component>'})
SET a.technique = '<technique>', a.tool = '<tool>',
a.outcome = '<failed|succeeded|partial>',
a.output_summary = '<1-2 sentence summary>',
a.error_signature = '<access_denied|timeout|waf_blocked|...>',
a.created_at = datetime()
A PreToolUse hook (trace.sh) queries Neo4j and surfaces prior attempts, credentials, and strategies as context BEFORE execution. This is a safety net — your own CHECK query above is the primary defense.
A PostToolUse hook (trace.sh) auto-extracts credentials and services from commands and writes them directly to Neo4j:
- Credentials: extracted from
sshpass,nxc/crackmapexec,evil-winrm, impacket tools - Auth status: determined from result (
[+]=confirmed,[-]/Permission denied=failed) - Services: extracted from nmap output (port/service/version)
Auto-extracted intel appears as additionalContext ("Auto-recorded to graph: ..."). You still need to manually write: target nodes (box name), vulnerabilities, shells, strategies, attempts, and flags.
Phase Classification (MANDATORY)
After every kali MCP tool call, the PostToolUse hook prompts you to classify the command's phase. Always include the phase SET in your next write_cypher call — piggyback it on whatever intel you're already writing:
MATCH (cl:command_log {sha256: '<sha256_from_prompt>'}) SET cl.phase = '<phase>'
Use dot-notation: recon.port-scan, enum.dir-brute, enum.web, exploit.sqli, exploit.lfi, privesc.sudo, lateral.cred-reuse, access.login. Create deeper keys freely: exploit.deserialization.java, privesc.service.race.
The PreToolUse vet surfaces phase breakdown — commands grouped by phase with productive counts. This lets you see at a glance which phases are stale (many commands, zero productive) and which are yielding results.
Post-Compaction Recovery (MANDATORY)
After every compaction, before doing ANYTHING else:
- Run the full graph recovery:
MATCH (t:target)-[r*1..3]-(n)
UNWIND r AS rel
RETURN DISTINCT labels(n)[0] AS type, n.key AS key, properties(n) AS props
ORDER BY type, key
- Check what has already been tried and FAILED:
MATCH (a:attempt {outcome: 'failed'})
RETURN a.technique, a.tool, a.error_signature, a.output_summary
ORDER BY a.created_at DESC LIMIT 15
Do NOT proceed with any attack until you have reviewed both results.
How It Works
- Model discovers a finding via Kali MCP
- Model determines what entities and relationships exist
- Model calls
write_cypherwith MERGE statements using ONLY the schema defined below - Model reads graph context with
read_cypherwhen planning next steps
MCP Tools
| Tool | Use |
|---|---|
mcp__neo4j__write_cypher | Create/update nodes and relationships |
mcp__neo4j__read_cypher | Query the graph — returns structured results |
mcp__neo4j__get_schema | Inspect current labels, relationship types, property keys |
Recording Findings
When you discover something, write Cypher immediately. Every finding is a MERGE — never skip, never batch "for later." Unrecorded findings are permanently lost on compaction.
Schema
Use ONLY the node labels and relationship types defined below. Do NOT invent new labels or relationship types. If a finding doesn't fit the schema, store it as properties on existing nodes rather than creating new types.
Node Labels
| Label | Key Property | Key Format | Other Properties |
|---|---|---|---|
| target | name | BoxName | platform, notes, domain |
| ip | addr | 10.0.0.1 | |
| port | key | 10.0.0.1:22/tcp | port, proto |
| service | key | 10.0.0.1:22:ssh | service, version |
| credential | key | admin:P@ssw0rd | username, secret, secret_type |
| user | name | admin | domain, groups |
| vulnerability | key | CVE-2024-1234 or vuln:sqli@/login | name, cve, endpoint, param, tool, exploitation_method, prerequisites, payload_format, confidence, wrong_approaches |
| shell | key | BoxName:www-data:webshell | user, method |
| flag | key | HTB{...} or flag:user.txt | value, location |
| file | key | /etc/config.ini | content_hash |
| endpoint | key | /api/login | method, params |
| strategy | key | strat:ssh-brute-admin | method, category, status, result, target_component |
| attempt | key | att:<technique>:<tool>@<target_component> | technique, tool, command, outcome, output_summary, error_signature, created_at |
| task | key | task:<role>:<subject> | description, status, depth, role, assignee, target, parent_key, findings_summary, spawned_at, completed_at |
| attack_class | key | class:<type>@<component> | status, reason, blocked_techniques, evidence_basis, disproven_at |
Relationship Types
| Relationship | From | To | Properties | Meaning |
|---|---|---|---|---|
| HAS_IP | target | ip | Target resolves to this IP | |
| HAS_PORT | target | port | Port is open on target | |
| RUNS_SERVICE | port | service | Service identified on port | |
| AUTHENTICATES_TO | credential | service | status: untested/confirmed/failed | Credential tested against service |
| BELONGS_TO | credential | user | Credential belongs to this user | |
| FOUND_IN | credential, flag | file, endpoint | Where the finding was discovered | |
| FOUND_ON | credential, vuln | target | Associated with this target | |
| AFFECTS | vulnerability | service, endpoint | Vulnerability affects this component | |
| RUNS_AS | shell | user | Shell executes as this user | |
| ON_TARGET | shell, vuln, strategy | target | Exists on this target | |
| LED_TO | vulnerability | shell | Exploitation of vuln gave shell | |
| TARGETS | strategy | target, service, endpoint | Strategy aims at this component | |
| TRIED_ON | attempt | service, endpoint, target | Attempt targeted this component | |
| HAS_ATTEMPT | strategy | attempt | Strategy spawned this attempt | |
| DISCOVERED | command_log, task | credential, service, vulnerability, shell, flag, attack_class | Work unit produced this finding (auto-created by hook for credentials/services; model creates for vulns/shells/flags/attack_classes) | |
| SPAWNED | task | task | Parent task created child t |