Skip to content

Commit

Permalink
Update trusts.py
Browse files Browse the repository at this point in the history
- Fixed the error for "self.flags" with None values and using "bitwise and" operator with it.

- Fixed the error for "self.direction" as a key in "self.trust_dir" which was leading to a KeyError.
  • Loading branch information
nickvourd authored Nov 16, 2023
1 parent bb45168 commit 8c58a1b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bloodhound/ad/trusts.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ def __init__(self, destination, direction, trust_type, flags, domainsid):
self.domainsid = ''

def has_flag(self, flag):
if self.flags is None or self.trust_flags.get(flag) is None:
return False # Handle the case where either self.flags or trust_flags[flag] is None

return self.flags & self.trust_flags[flag] == self.trust_flags[flag]

def to_output(self):
trusttype = 'Unknown'
is_transitive = False
sid_filtering = True

if self.has_flag('WITHIN_FOREST'):
trusttype = 'ParentChild'
is_transitive = True
Expand All @@ -100,15 +107,16 @@ def to_output(self):
is_transitive = False
sid_filtering = True
else:
trusttype = 'Unknown'
is_transitive = not self.has_flag('NON_TRANSITIVE')
sid_filtering = True

# Check if self.direction exists in self.trust_dir before accessing it
trust_direction = self.trust_dir.get(self.direction, 'UnknownTrustDirection')

out = {
"TargetDomainName": self.destination_domain.upper(),
"TargetDomainSid": self.domainsid,
"IsTransitive": is_transitive,
"TrustDirection": self.trust_dir[self.direction],
"TrustDirection": trust_direction,
"TrustType": trusttype,
"SidFilteringEnabled": sid_filtering
}
Expand Down

0 comments on commit 8c58a1b

Please sign in to comment.