|
1 | 1 | import binascii |
2 | | -import codecs |
3 | 2 | import json |
4 | 3 | import datetime |
5 | 4 | from enum import Enum |
@@ -278,11 +277,9 @@ def options(self, context, module_options): |
278 | 277 | self.rights_guid = None |
279 | 278 |
|
280 | 279 | def on_login(self, context, connection): |
281 | | - self.context = context |
282 | 280 | """On a successful LDAP login we perform a search for the targets' SID, their Security Descriptors and the principal's SID if there is one specified""" |
283 | 281 | context.log.highlight("Be careful, this module cannot read the DACLS recursively.") |
284 | | - self.baseDN = connection.ldap_connection._baseDN |
285 | | - self.ldap_session = connection.ldap_connection |
| 282 | + self.context = context |
286 | 283 | self.connection = connection |
287 | 284 |
|
288 | 285 | # Searching for the principal SID |
@@ -339,11 +336,9 @@ def backup(self, target, target_principal_dn, principal_raw_security_descriptor) |
339 | 336 | backup["sd"] = binascii.hexlify(principal_raw_security_descriptor).decode("latin-1") |
340 | 337 | backup["dn"] = str(target_principal_dn) |
341 | 338 |
|
342 | | - filename = "dacledit-{}-{}.bak".format( |
343 | | - datetime.datetime.now().strftime("%Y%m%d-%H%M%S"), |
344 | | - target, |
345 | | - ) |
346 | | - with codecs.open(filename, "w", "latin-1") as outfile: |
| 339 | + timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") |
| 340 | + filename = f"dacledit-{timestamp}-{target}.bak" |
| 341 | + with open(filename, "w", encoding="latin-1") as outfile: |
347 | 342 | json.dump(backup, outfile) |
348 | 343 | self.context.log.highlight(f"DACL backed up to {filename}") |
349 | 344 |
|
@@ -427,10 +422,7 @@ def parse_ace(self, ace): |
427 | 422 | except KeyError: |
428 | 423 | parsed_ace["Inherited type (GUID)"] = f"UNKNOWN ({inh_obj_type})" |
429 | 424 | # Extract the Trustee SID (the object that has the right over the DACL bearer) |
430 | | - parsed_ace["Trustee (SID)"] = "{} ({})".format( |
431 | | - self.resolveSID(ace["Ace"]["Sid"].formatCanonical()) or "UNKNOWN", |
432 | | - ace["Ace"]["Sid"].formatCanonical(), |
433 | | - ) |
| 425 | + parsed_ace["Trustee (SID)"] = f"{self.resolveSID(ace['Ace']['Sid'].formatCanonical()) or 'UNKNOWN'} ({ace['Ace']['Sid'].formatCanonical()})" |
434 | 426 | else: # if the ACE is not an access allowed |
435 | 427 | self.context.log.debug(f"ACE Type ({ace['TypeName']}) unsupported for parsing yet, feel free to contribute") |
436 | 428 | _ace_flags = [FLAG.name for FLAG in ACE_FLAGS if ace.hasFlag(FLAG.value)] |
|
0 commit comments