|
21 | 21 | UF_TRUSTED_FOR_DELEGATION,
|
22 | 22 | UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION,
|
23 | 23 | UF_SERVER_TRUST_ACCOUNT,
|
| 24 | + SAM_MACHINE_ACCOUNT, |
24 | 25 | )
|
25 | 26 | from impacket.krb5 import constants
|
26 | 27 | from impacket.krb5.kerberosv5 import getKerberosTGS, SessionKeyDecryptionError
|
@@ -678,25 +679,47 @@ def users(self):
|
678 | 679 |
|
679 | 680 | def groups(self):
|
680 | 681 | # Building the search filter
|
681 |
| - search_filter = "(objectCategory=group)" |
682 |
| - attributes = ["name"] |
| 682 | + if self.args.groups: |
| 683 | + self.logger.debug(f"Dumping group: {self.args.groups}") |
| 684 | + search_filter = f"(cn={self.args.groups})" |
| 685 | + attributes = ["member"] |
| 686 | + else: |
| 687 | + search_filter = "(objectCategory=group)" |
| 688 | + attributes = ["cn", "member"] |
683 | 689 | resp = self.search(search_filter, attributes, 0)
|
684 |
| - if resp: |
685 |
| - self.logger.debug(f"Total of records returned {len(resp):d}") |
| 690 | + resp_parsed = parse_result_attributes(resp) |
| 691 | + self.logger.debug(f"Total of records returned {len(resp):d}") |
686 | 692 |
|
687 |
| - for item in resp: |
688 |
| - if isinstance(item, ldapasn1_impacket.SearchResultEntry) is not True: |
689 |
| - continue |
690 |
| - name = "" |
| 693 | + if self.args.groups: |
| 694 | + if not resp_parsed: |
| 695 | + self.logger.fail(f"Group {self.args.groups} not found") |
| 696 | + elif not resp_parsed[0]: |
| 697 | + self.logger.fail(f"Group {self.args.groups} has no members") |
| 698 | + else: |
| 699 | + # Fix if group has only one member |
| 700 | + if not isinstance(resp_parsed[0]["member"], list): |
| 701 | + resp_parsed[0]["member"] = [resp_parsed[0]["member"]] |
| 702 | + for user in resp_parsed[0]["member"]: |
| 703 | + self.logger.highlight(user.split(",")[0].split("=")[1]) |
| 704 | + else: |
| 705 | + for item in resp_parsed: |
691 | 706 | try:
|
692 |
| - for attribute in item["attributes"]: |
693 |
| - if str(attribute["type"]) == "name": |
694 |
| - name = str(attribute["vals"][0]) |
695 |
| - self.logger.highlight(f"{name}") |
| 707 | + # Fix if group has only one member |
| 708 | + if not isinstance(item.get("member", []), list): |
| 709 | + item["member"] = [item["member"]] |
| 710 | + self.logger.highlight(f"{item['cn']:<40} membercount: {len(item.get('member', []))}") |
696 | 711 | except Exception as e:
|
697 | 712 | self.logger.debug("Exception:", exc_info=True)
|
698 | 713 | self.logger.debug(f"Skipping item, cannot process due to error {e}")
|
699 |
| - return |
| 714 | + |
| 715 | + def computers(self): |
| 716 | + resp = self.search(f"(sAMAccountType={SAM_MACHINE_ACCOUNT})", ["name"], 0) |
| 717 | + resp_parse = parse_result_attributes(resp) |
| 718 | + |
| 719 | + if resp: |
| 720 | + self.logger.display(f"Total records returned: {len(resp_parse)}") |
| 721 | + for item in resp_parse: |
| 722 | + self.logger.highlight(item["name"] + "$") |
700 | 723 |
|
701 | 724 | def dc_list(self):
|
702 | 725 | # Building the search filter
|
|
0 commit comments