Skip to content

Commit b3c34a9

Browse files
committed
Update dump-computers.py
added samaccountname fallback
1 parent 800bc5e commit b3c34a9

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

nxc/modules/dump-computers.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,39 @@ def options(self, context, module_options):
3535
def on_login(self, context, connection):
3636
resp = connection.search(
3737
searchFilter="(objectCategory=computer)",
38-
attributes=["dNSHostName", "operatingSystem"]
38+
attributes=["dNSHostName", "operatingSystem", "sAMAccountName"]
3939
)
4040
resp_parsed = parse_result_attributes(resp)
4141

4242
answers = []
4343
context.log.debug(f"Total number of records returned: {len(resp_parsed)}")
4444

45+
# detect domain suffix from any valid dnshostname
46+
domain = None
47+
for entry in resp_parsed:
48+
dn = entry.get("dNSHostName")
49+
if dn and "." in dn:
50+
domain = dn.split(".", 1)[1]
51+
break
52+
4553
for item in resp_parsed:
46-
dns_host_name = item["dNSHostName"]
47-
operating_system = item.get("operatingSystem", "Unknown OS")
54+
dns_host_name = item.get("dNSHostName") or item.get("sAMAccountName")
55+
56+
# handle machine accounts with only samaccountname
57+
if "." not in dns_host_name:
58+
dns_host_name = dns_host_name.rstrip("$")
59+
if domain:
60+
dns_host_name = f"{dns_host_name}.{domain}"
61+
62+
operating_system = item.get("operatingSystem") or "Unknown OS"
4863

4964
if self.netbios_only:
50-
netbios_name = dns_host_name.split(".")[0]
51-
answer = netbios_name
65+
answer = dns_host_name.split(".")[0]
5266
elif self.fqdn_only:
5367
answer = dns_host_name
5468
else:
5569
answer = f"{dns_host_name} ({operating_system})"
70+
5671
answers.append(answer)
5772

5873
context.log.success("Found the following computers:")

0 commit comments

Comments
 (0)