Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Set computer accounts as owned in BloodHound #532

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cme/helpers/bloodhound.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ def add_user_bh(user, domain, logger, config):
with driver.session() as session:
with session.begin_transaction() as tx:
for info in users_owned:
user_owned = info['username'] + "@" + info['domain']
if info['username'][-1] == '$':
user_owned = info['username'][:-1] + "." + info['domain']
account_type = 'Computer'
else:
user_owned = info['username'] + "@" + info['domain']
account_type = 'User'

result = tx.run(
"MATCH (c:User {{name:\"{}\"}}) RETURN c".format(user_owned))
if result.data()[0]['c'].get('owned') == False:
logger.debug("MATCH (c:User {{name:\"{}\"}}) SET c.owned=True RETURN c.name AS name".format(user_owned))
"MATCH (c:{} {{name:\"{}\"}}) RETURN c".format(account_type, user_owned))

if result.data()[0]['c'].get('owned') in (False, None):
logger.debug("MATCH (c:{} {{name:\"{}\"}}) SET c.owned=True RETURN c.name AS name".format(account_type, user_owned))
result = tx.run(
"MATCH (c:User {{name:\"{}\"}}) SET c.owned=True RETURN c.name AS name".format(user_owned))
"MATCH (c:{} {{name:\"{}\"}}) SET c.owned=True RETURN c.name AS name".format(account_type, user_owned))
logger.highlight("Node {} successfully set as owned in BloodHound".format(user_owned))
except AuthError as e:
logger.error(
Expand Down