dirkjanm / ldapdomaindump

Active Directory information dumper via LDAP
MIT License
1.19k stars 190 forks source link

Ensure formatString returns a string #45

Open smcgu opened 2 years ago

smcgu commented 2 years ago

In a recent assessment, a multi-line account description was being returned as a list. This broke the generateGrepList method that was attempting to join the account attributes. The root of the issue appears to be that formatString does not guarantee that all returned values will be str. I refactored formatString:

Copy of stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/ldapdomaindump", line 3, in <module>
    ldapdomaindump.main()
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 944, in main
    dd.domainDump()
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 422, in domainDump
    rw.generateUsersReport(self)
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 797, in generateUsersReport
    grepout = self.generateGrepList(dd.users, self.userattributes)
  File "/usr/lib/python3/dist-packages/ldapdomaindump/__init__.py", line 735, in generateGrepList
    out.append(self.config.grepsplitchar.join(eo))
TypeError: sequence item 11: expected str instance, list found 

Redacted output data from pdb:

[snip]
    description: description line one
                 description line two
                 description line three
    displayName: Redacted User
[snip]

entry['description']
description: description line one
                 description line two
                 description line three

self.formatGrepAttribute(entry['description'])
['description line one', 'description line two', 'description line three']

[type(val) for val in eo]
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'list'>]