Skip to content

Commit

Permalink
Update obsolete.py
Browse files Browse the repository at this point in the history
Signed-off-by: Shad0wC0ntr0ller <90877534+Shad0wC0ntr0ller@users.noreply.github.com>
  • Loading branch information
Shad0wC0ntr0ller authored and Marshall-Hallenbeck committed Mar 9, 2024
1 parent 08d4049 commit 45258c5
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions nxc/modules/obsolete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from datetime import datetime, timedelta
from pathlib import Path
Expand All @@ -18,25 +17,18 @@ class NXCModule:
multiple_hosts = True

def ldap_time_to_datetime(self, ldap_time):
"""
Convert an LDAP timestamp to a datetime object.
LDAP timestamp is the number of 100-nanosecond intervals since January 1, 1601.
"""
"""Convert an LDAP timestamp to a datetime object."""
if ldap_time == "0": # Account for never-set passwords
return "Never"
try:
# Remove the last 7 digits (fractional seconds) and convert to seconds
epoch = datetime(1601, 1, 1) + timedelta(seconds=int(ldap_time) / 10000000)
return epoch.strftime("%Y-%m-%d %H:%M:%S")
except Exception as e:
except Exception:
return "Conversion Error"

def options(self, context, module_options):
"""
No module-specific options required.
"""
pass

"""No module-specific options required."""

def on_login(self, context, connection):
search_filter = ("(&(objectclass=computer)(!(userAccountControl:1.2.840.113556.1.4.803:=2))"
"(|(operatingSystem=*Windows 6*)(operatingSystem=*Windows 2000*)"
Expand All @@ -49,7 +41,7 @@ def on_login(self, context, connection):
try:
context.log.debug(f"Search Filter={search_filter}")
resp = connection.ldapConnection.search(searchFilter=search_filter, attributes=attributes, sizeLimit=0)
except Exception as e:
except Exception:
context.log.error("LDAP search error:", exc_info=True)
return False

Expand All @@ -59,12 +51,10 @@ def on_login(self, context, connection):
for item in resp:
if "attributes" not in item:
continue
name, os, dns_hostname, pwd_last_set = "", "", "", "0" # Default "0" for pwdLastSet
dns_hostname, pwd_last_set = "", "0" # Default '0' for pwdLastSet
for attribute in item["attributes"]:
attr_type = str(attribute["type"])
if attr_type == "name":
name = str(attribute["vals"][0])
elif attr_type == "operatingSystem":
if attr_type == "operatingSystem":
os = str(attribute["vals"][0])
elif attr_type == "dNSHostName":
dns_hostname = str(attribute["vals"][0])
Expand Down

0 comments on commit 45258c5

Please sign in to comment.