Skip to content

Commit ea9b661

Browse files
committed
Simplify filtering
1 parent f4967a6 commit ea9b661

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

nxc/modules/get-scriptpath.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,20 @@ def on_login(self, context, connection):
3636
)
3737

3838
context.log.debug(f"Total of records returned {len(resp)}")
39-
resp_parsed = parse_result_attributes(resp)
40-
answers = [[x["sAMAccountName"], x["scriptPath"]] for x in resp_parsed]
39+
answers = parse_result_attributes(resp)
40+
context.log.debug(f"Filtering for scriptPath containing: {self.filter}")
41+
filtered_answers = list(filter(lambda x: self.filter in x["scriptPath"], answers))
4142

42-
answers = self.filter_answer(context, answers)
43-
44-
if answers:
43+
if filtered_answers:
4544
context.log.success("Found the following attributes: ")
46-
for answer in answers:
47-
context.log.highlight(f"User: {answer[0]:<20} ScriptPath: {answer[1]}")
45+
for answer in filtered_answers:
46+
context.log.highlight(f"User: {answer['sAMAccountName']:<20} ScriptPath: {answer['scriptPath']}")
4847

4948
# Save the results to a file
5049
if self.outputfile:
51-
self.save_to_file(context, answers)
50+
self.save_to_file(context, filtered_answers)
5251
else:
53-
context.log.warning("No results found after filtering.")
54-
55-
def filter_answer(self, context, answers):
56-
# No filter
57-
if not self.filter:
58-
context.log.debug("No filter option enabled")
59-
return answers
60-
# Filter
61-
context.log.debug(f"Filter info field with: {self.filter}")
62-
return [answer for answer in answers if self.filter in answer[0]]
52+
context.log.fail("No results found after filtering.")
6353

6454
def save_to_file(self, context, answers):
6555
"""Save the results to a JSON file."""

0 commit comments

Comments
 (0)