ad-ldap-enum
ad-ldap-enum copied to clipboard
Group Membership CSV Has Inconsistent Number of Columns
When values are not found, ad-ldap-enum sometimes outputs rows with different numbers of columns, instead of outputting a consistent number of columns with empty strings for values that aren't found. This causes problems when passing ad-ldap-enum output files to other tools.
I'm not sure if this applies to just Domain Group Membership, but many (though not all) members of the groups Domain Admins, Domain Computers, Domain Controllers, and Domain Users did not have a Distinguished Name returned. Additionally, all computer account members of Domain Users and Domain Computers were missing both Member Status and Group Distinguished name values.
The problem is not that the values were not present, but the output did not contain empty strings in their place. Instead, entries missing the Distinguished Name contained 3 columns instead of 4. I believe entries missing both Member Status and Group Distinguished Name contained only 2 columns. This problem was limited to the Domain Group Membership file in my case but may also apply to other files, apologies for the lack of detail. Further testing is required.
For the time being I am using the following function to normalize the number of columns in output files, but ideally a fix should be implemented to output empty strings in place of values (such as Group Distinguished Name) ad-ldap-enum can't retrieve.
def normalize_csv(file_path):
"""
Normalize a CSV file by adding empty columns to each row as necessary.
Args:
file_path (str): The path to the CSV file.
Returns:
None
"""
# Read the CSV file
with open(file_path, 'r') as file:
reader = csv.reader(file)
rows = list(reader)
# Find the maximum number of columns in the CSV
max_columns = max(len(row) for row in rows)
# Normalize the rows by adding empty columns
normalized_rows = [row + [''] * (max_columns - len(row)) for row in rows]
# Write the normalized rows back to the CSV file
with open(file_path, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(normalized_rows)