Skip to content
Open
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
30 changes: 30 additions & 0 deletions src/bhcli/cli/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import click
import prettytable
import datetime

from bhcli import cypher
from bhcli.api.from_config import api
Expand Down Expand Up @@ -142,4 +143,33 @@ def audit(domain):
print(f"{n[1]} ({n[0]})")
print()

print("[*] Accounts which have PasswordNotRequired set (enabled)")
query = f"""
MATCH (u:User)
{cypher.where("u", domainsid=domsid, passwordnotreqd=True, enabled=True)}
RETURN u
"""
result = api.cypher(query)["nodes"].values()
count = len(result)
print(f" {count} accounts found")

relations = set()
for n in result:
is_tier0 = False
if n["properties"].get("system_tags") != None and "admin_tier_0" in n["properties"].get("system_tags"):
is_tier0 = True
lastLogonDate = datetime.datetime.fromtimestamp(n["properties"]["lastlogon"]).strftime('%Y-%m-%d %H:%M:%S')
pwLastSetDate = datetime.datetime.fromtimestamp(n["properties"]["pwdlastset"]).strftime('%Y-%m-%d %H:%M:%S')
relations.add((n["properties"]["name"], n["kind"], pwLastSetDate, lastLogonDate, is_tier0))
if count > 0:
table = prettytable.PrettyTable()
table.set_style(prettytable.PLAIN_COLUMNS)
table.align = "l"
table.field_names = ["Name", "Type", "PasswordLastSet", "LastLogin", "Tier-0"]
table.add_rows(sorted(relations))
print(table)
print()



print()