|
| 1 | +from nxc.parsers.ldap_results import parse_result_attributes |
| 2 | + |
| 3 | + |
| 4 | +class NXCModule: |
| 5 | + """ |
| 6 | + Get the info field of users |
| 7 | + Module by @sepauli |
| 8 | + """ |
| 9 | + name = "get-info-users" |
| 10 | + description = "Get the info field of all users. May contain password" |
| 11 | + supported_protocols = ["ldap"] |
| 12 | + opsec_safe = True |
| 13 | + multiple_hosts = True |
| 14 | + |
| 15 | + def options(self, context, module_options): |
| 16 | + """FILTER Apply the FILTER (grep-like) (default: '')""" |
| 17 | + self.FILTER = "" |
| 18 | + if "FILTER" in module_options: |
| 19 | + self.FILTER = module_options["FILTER"] |
| 20 | + |
| 21 | + def on_login(self, context, connection): |
| 22 | + # Building the search filter |
| 23 | + resp = connection.search( |
| 24 | + searchFilter="(info=*)", |
| 25 | + attributes=["sAMAccountName", "info"] |
| 26 | + ) |
| 27 | + |
| 28 | + context.log.debug(f"Total of records returned {len(resp)}") |
| 29 | + resp_parsed = parse_result_attributes(resp) |
| 30 | + answers = [[x["sAMAccountName"], x["info"]] for x in resp_parsed] |
| 31 | + |
| 32 | + answers = self.filter_answer(context, answers) |
| 33 | + if answers: |
| 34 | + context.log.success("Found following users: ") |
| 35 | + for answer in answers: |
| 36 | + context.log.highlight(f"User: {answer[0]:<20} Info: {answer[1]}") |
| 37 | + |
| 38 | + def filter_answer(self, context, answers): |
| 39 | + # No option to filter |
| 40 | + if not self.FILTER: |
| 41 | + context.log.debug("No filter option enabled") |
| 42 | + return answers |
| 43 | + # Filter |
| 44 | + context.log.debug(f"Filter info field with: {self.FILTER}") |
| 45 | + return [answer for answer in answers if self.FILTER in answer[1]] |
| 46 | + |
0 commit comments