@@ -55,7 +55,9 @@ class OpenGraphContext:
5555 logger : Optional [Union [Logger , TaskLogger ]]
5656 total_edges_created : int
5757
58- def __init__ (self , graph : OpenGraph , logger : Optional [Union [Logger , TaskLogger ]] = None ):
58+ def __init__ (
59+ self , graph : OpenGraph , logger : Optional [Union [Logger , TaskLogger ]] = None
60+ ):
5961 self .graph = graph
6062 self .host = (None , {})
6163 self .share = (None , {})
@@ -80,7 +82,7 @@ def add_path_to_graph(self) -> None:
8082 self .logger .debug ("[add_path_to_graph] Host is None, skipping" )
8183 return None
8284 self .graph .add_node_without_validation (self .host )
83-
85+
8486 # Add edge [HostsNetworkShare] from BloodHound Computer to NetworkShareHost
8587 # This links the ShareHound graph to existing BloodHound Computer nodes
8688 # by matching the Computer's name property (uppercase) to the NetworkShareHost's id
@@ -95,19 +97,27 @@ def add_path_to_graph(self) -> None:
9597 )
9698 self .total_edges_created += 1
9799 if self .logger :
98- self .logger .debug (f"[add_path_to_graph] Created edge HostsNetworkShare: Computer(name={ self .host .id .upper ()} ) -> NetworkShareHost(id={ self .host .id } )" )
100+ self .logger .debug (
101+ f"[add_path_to_graph] Created edge HostsNetworkShare: Computer(name={ self .host .id .upper ()} ) -> NetworkShareHost(id={ self .host .id } )"
102+ )
99103
100104 share_node , share_rights = self .share
101105 if share_node is None :
102106 if self .logger :
103107 self .logger .debug ("[add_path_to_graph] Share node is None, skipping" )
104108 return None
105109 self .graph .add_node_without_validation (share_node )
106-
110+
107111 if self .logger :
108- rights_count = sum (len (edges ) for edges in share_rights .values ()) if share_rights else 0
109- self .logger .debug (f"[add_path_to_graph] Adding share '{ share_node .id } ' with { len (share_rights )} SID(s) and { rights_count } rights edge(s)" )
110-
112+ rights_count = (
113+ sum (len (edges ) for edges in share_rights .values ())
114+ if share_rights
115+ else 0
116+ )
117+ self .logger .debug (
118+ f"[add_path_to_graph] Adding share '{ share_node .id } ' with { len (share_rights )} SID(s) and { rights_count } rights edge(s)"
119+ )
120+
111121 self .add_rights_to_graph (share_node .id , share_rights , "share" )
112122
113123 # Add edge [HasNetworkShare] from host to share
@@ -120,7 +130,9 @@ def add_path_to_graph(self) -> None:
120130 )
121131 self .total_edges_created += 1
122132 if self .logger :
123- self .logger .debug (f"[add_path_to_graph] Created edge HasNetworkShare: { self .host .id } -> { share_node .id } " )
133+ self .logger .debug (
134+ f"[add_path_to_graph] Created edge HasNetworkShare: { self .host .id } -> { share_node .id } "
135+ )
124136
125137 # At this point we have created
126138 # (Host) --[HasNetworkShare]--> ((NetworkShareSMB|NetworkShareDFS))
@@ -140,7 +152,9 @@ def add_path_to_graph(self) -> None:
140152 )
141153 self .total_edges_created += 1
142154 if self .logger :
143- self .logger .debug (f"[add_path_to_graph] Created edge Contains: { parent_id } -> { directory_node .id } " )
155+ self .logger .debug (
156+ f"[add_path_to_graph] Created edge Contains: { parent_id } -> { directory_node .id } "
157+ )
144158 parent_id = directory_node .id
145159
146160 # At this point we have created
@@ -163,12 +177,16 @@ def add_path_to_graph(self) -> None:
163177 )
164178 self .total_edges_created += 1
165179 if self .logger :
166- self .logger .debug (f"[add_path_to_graph] Created edge Contains: { parent_id } -> { element_node .id } " )
180+ self .logger .debug (
181+ f"[add_path_to_graph] Created edge Contains: { parent_id } -> { element_node .id } "
182+ )
167183
168184 # At this point we have created
169185 # (Host) --[Expose]--> ((NetworkShareSMB|NetworkShareDFS)) --[Contains]--> ((File)|(Directory))* --[Contains]--> ((File)|(Directory))
170186
171- def add_rights_to_graph (self , element_id : str , rights : dict , element_type : str = "element" ) -> None :
187+ def add_rights_to_graph (
188+ self , element_id : str , rights : dict , element_type : str = "element"
189+ ) -> None :
172190 """
173191 Add rights to the graph
174192
@@ -183,12 +201,16 @@ def add_rights_to_graph(self, element_id: str, rights: dict, element_type: str =
183201
184202 if rights is None :
185203 if self .logger :
186- self .logger .warning (f"[add_rights_to_graph] Rights is None for { element_type } : { element_id } " )
204+ self .logger .warning (
205+ f"[add_rights_to_graph] Rights is None for { element_type } : { element_id } "
206+ )
187207 return
188208
189209 if len (rights ) == 0 :
190210 if self .logger :
191- self .logger .debug (f"[add_rights_to_graph] No rights to add for { element_type } : { element_id } " )
211+ self .logger .debug (
212+ f"[add_rights_to_graph] No rights to add for { element_type } : { element_id } "
213+ )
192214 return
193215
194216 edges_created_for_element = 0
@@ -206,10 +228,14 @@ def add_rights_to_graph(self, element_id: str, rights: dict, element_type: str =
206228 self .total_edges_created += 1
207229 edges_created_for_element += 1
208230 if self .logger :
209- self .logger .debug (f"[add_rights_to_graph] Created edge: { sid } --[{ right_edge } ]--> { element_id } " )
231+ self .logger .debug (
232+ f"[add_rights_to_graph] Created edge: { sid } --[{ right_edge } ]--> { element_id } "
233+ )
210234
211235 if self .logger :
212- self .logger .debug (f"[add_rights_to_graph] Created { edges_created_for_element } rights edge(s) for { element_type } : { element_id } " )
236+ self .logger .debug (
237+ f"[add_rights_to_graph] Created { edges_created_for_element } rights edge(s) for { element_type } : { element_id } "
238+ )
213239
214240 def push_path (self , node : Node , rights : dict ):
215241 """
@@ -461,4 +487,6 @@ def log_summary(self) -> None:
461487 None
462488 """
463489 if self .logger :
464- self .logger .debug (f"[OpenGraphContext] Total edges created in this context: { self .total_edges_created } " )
490+ self .logger .debug (
491+ f"[OpenGraphContext] Total edges created in this context: { self .total_edges_created } "
492+ )
0 commit comments