|
28 | 28 | from impacket.krb5.types import Principal, KerberosException |
29 | 29 | from impacket.ldap import ldap as ldap_impacket |
30 | 30 | from impacket.ldap import ldapasn1 as ldapasn1_impacket |
| 31 | +from impacket.ldap.ldap import LDAPFilterSyntaxError |
31 | 32 | from impacket.smb import SMB_DIALECT |
32 | 33 | from impacket.smbconnection import SMBConnection, SessionError |
33 | 34 |
|
@@ -1054,6 +1055,36 @@ def kerberoasting(self): |
1054 | 1055 | self.logger.highlight("No entries found!") |
1055 | 1056 | self.logger.fail("Error with the LDAP account used") |
1056 | 1057 |
|
| 1058 | + def query(self): |
| 1059 | + """ |
| 1060 | + Query the LDAP server with the specified filter and attributes. |
| 1061 | + Example usage: |
| 1062 | + --query "(sAMAccountName=Administrator)" "sAMAccountName pwdLastSet memberOf" |
| 1063 | + """ |
| 1064 | + search_filter = self.args.query[0] |
| 1065 | + attributes = [attr.strip() for attr in self.args.query[1].split(" ")] |
| 1066 | + if len(attributes) == 1 and attributes[0] == "": |
| 1067 | + attributes = None |
| 1068 | + if not search_filter: |
| 1069 | + self.logger.fail("No filter specified") |
| 1070 | + return |
| 1071 | + self.logger.debug(f"Querying LDAP server with filter: {search_filter} and attributes: {attributes}") |
| 1072 | + try: |
| 1073 | + resp = self.search(search_filter, attributes, 0) |
| 1074 | + except LDAPFilterSyntaxError as e: |
| 1075 | + self.logger.fail(f"LDAP Filter Syntax Error: {e}") |
| 1076 | + return |
| 1077 | + for item in resp: |
| 1078 | + if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: |
| 1079 | + continue |
| 1080 | + self.logger.success(f"Response for object: {item['objectName']}") |
| 1081 | + for attribute in item["attributes"]: |
| 1082 | + attr = f"{attribute['type']}:" |
| 1083 | + vals = str(attribute["vals"]).replace("\n", "") |
| 1084 | + if "SetOf: " in vals: |
| 1085 | + vals = vals.replace("SetOf: ", "") |
| 1086 | + self.logger.highlight(f"{attr:<20} {vals}") |
| 1087 | + |
1057 | 1088 | def trusted_for_delegation(self): |
1058 | 1089 | # Building the search filter |
1059 | 1090 | searchFilter = "(userAccountControl:1.2.840.113556.1.4.803:=524288)" |
|
0 commit comments