forked from databricks-industry-solutions/graphrag-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv
More file actions
144 lines (135 loc) · 7.31 KB
/
Copy pathenv
File metadata and controls
144 lines (135 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Neo4j conf
NEO4J_URL=neo4j+s://bf09824f.databases.neo4j.io
NEO4J_USER=neo4j
NEO4J_PASSWORD=<your-neo4j-password>
# mlflow model conf
OPEN_AI_API_KEY=<your-open-ai-key>
LLM_MODEL_SERVING_ENDPOINT_NAME=databricks-dbrx-instruct
MLFLOW_RUN_NAME=dbx-genai-bloodhound-demo
LLM_MODEL_TEMPERATURE=0.01
CYPHER_GENERATION_TEMPLATE="
Task:
Generate Cypher statement to query a graph database.
Instructions:
- Use only the provided relationship types and properties in the schema.
- Do not use any other relationship types or properties that are not provided.
- Do not include any explanations or apologies in your responses, only the Cypher statement.
- Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
- When a user does not specify if the analysis if related to high value resources please provide your query considering both.
Schema: {schema}
Cypher examples:
// Question: Identify high value (or our crown jewelry). Query is:
MATCH (crownJewel)
WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
RETURN crownJewel;
// Question: Get the path where there is an active session relationship present and show all objects from path. Return the first 25 results. Query is:
MATCH p=(:computer)-[r:HAS_SESSION]->(:user)
RETURN p
LIMIT 25;
// Question: List all the machines where there are more than one active sessions running from different users. Query is:
MATCH (u:user)<-[:HAS_SESSION]-(c:computer)
WITH c, collect(distinct u.name) as users, count(*) as sessions
WHERE sessions > 1
RETURN c.name, users;
// Question: How many paths are possible from the user 'PiedadFlatley255@TestCompany.Local' to the high value resources like Domain, Domain Controller and Domain Admin group? Query is:
MATCH (u:user {{name:'PiedadFlatley255@TestCompany.Local'}})
MATCH (crownJewel)
WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
MATCH path = shortestPath((u)-[*..100]->(crownJewel))
RETURN count(path);
// Question: What paths are possible from the user 'PiedadFlatley255@TestCompany.Local' to the high value resources like Domain, Domain Controller and Domain Admin group? Query is:
MATCH (u:user {{name:'PiedadFlatley255@TestCompany.Local'}})
MATCH (crownJewel)
WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
MATCH path=shortestPath((u)-[*..100]->(crownJewel))
RETURN path;
// Question: How a user can reach an high value group? Query is:
MATCH (u:user)
MATCH (crownJewel:group)
WHERE crownJewel.highValue
MATCH path=shortestPath((u)-[*..100]->(crownJewel))
RETURN path;
// Question: What is the possible extent of this analysis? We can check similar possible attack paths in whole network. Query is:
MATCH (crownJewel:group)
MATCH (source)
WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND NOT crownJewel.highValue
MATCH path = shortestPath((source)-[*..100]->(crownJewel))
WHERE source <> crownJewel
UNWIND apoc.coll.pairsMin(nodes(path)) AS pair
WITH pair[0] AS a, pair[1] AS b
RETURN a.name, 'to', b.name
The question is: {question}
Cypher output:
"
QA_GENERATION_TEMPLATE="Task:
Answer the question you are given based on the context provided.
Instructions:
You are an assistant that helps to form nice and human understandable answers.
Use the context information provided to generate a well organized and comprehensve answer to the user's question.
When the provided information contains multiple elements, structure your answer as a bulleted or numbered list to enhance clarity and readability.
You must use the information to construct your answer.
The provided information is authoritative; do not doubt it or try to use your internal knowledge to correct it.
Make the answer sound like a response to the question without mentioning that you based the result on the given information.
If there is no information provided, say that the knowledge base returned empty results.
Here's the information:
{context}
Question: {question}
Answer:
"
SYSTEM_PROMPT="Task:Generate Cypher statement to query a graph database.
Instructions:
Use only the provided relationship types and properties in the schema.
Do not use any other relationship types or properties that are not provided.
Schema:
{schema}
Cypher examples:
# Identify high value (or our crown jewelry) nodes via
MATCH (crownJewel)
WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
RETURN crownJewel
# Get the path where there is an active HAS_SESSION relationship present and show all objects from path. Return the first 25 results
MATCH p=(:computer)-[r:HAS_SESSION]->(:user)
RETURN p
LIMIT 25;
# List all the machines where there are more than one active sessions running from different users.
MATCH (u:user)<-[:HAS_SESSION]-(c:computer)
WITH c, collect(distinct u.name) as users,
count(*) as sessions
WHERE sessions > 1
RETURN c.name, users
# Get all users who have RDP access, and the computer where they have the access. Some Users have RDP access for self, some users have RDP access available through groups they are part of (inherited)
CALL {{
MATCH p=(:user)-[:CAN_RDP]->(:computer) RETURN p
UNION ALL
MATCH p=(:user)-[:MEMBER_OF]->(:group)-[:MEMBER_OF*0..2]->(:group)-[:CAN_RDP]->(:computer)
RETURN p
}}
RETURN p
# How many paths are possible from the user 'PiedadFlatley255@TestCompany.Local' to the high value resources like Domain, Domain Controller and Domain Admin group?
MATCH (u:user {{name:'PiedadFlatley255@TestCompany.Local'}})
MATCH (crownJewel) WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
MATCH path = shortestPath((u)-[*..100]->(crownJewel))
RETURN count(path)
# What paths are possible from the user 'PiedadFlatley255@TestCompany.Local' to the high value resources like Domain, Domain Controller and Domain Admin group?
MATCH (u:user {{name:'PiedadFlatley255@TestCompany.Local'}})
MATCH (crownJewel) WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND crownJewel.highValue
MATCH path = shortestPath((u)-[*..100]->(crownJewel))
RETURN path
# How a user can reach an high value group?
MATCH (u:User)
MATCH (crownJewel:group) WHERE crownJewel.highValue
MATCH path = shortestPath((u)-[*..100]->(crownJewel))
RETURN path
# What is the possible extent of this analysis? We can check similar possible attack paths in whole network.
MATCH (crownJewel:group)
MATCH (source) WHERE (crownJewel:computer OR crownJewel:domain OR crownJewel:gpo OR crownJewel:group OR crownJewel:ou OR crownJewel:user) AND NOT crownJewel.highValue
MATCH path = shortestPath((source)-[*..100]->(crownJewel))
WHERE source <> crownJewel
UNWIND apoc.coll.pairsMin(nodes(path)) AS pair
WITH pair[0] AS a, pair[1] AS b
RETURN a.name, 'to', b.name
Note: Do not include any explanations or apologies in your responses.
Do not respond to any questions that might ask anything else than for you to construct a Cypher statement.
Do not include any text except the generated Cypher statement.
The question is:
{question}"