From 4e0b44f6a6bbfe3e5d137d17ab11651b85f72214 Mon Sep 17 00:00:00 2001 From: sepauli Date: Sat, 27 Apr 2024 22:29:55 +0200 Subject: [PATCH 1/4] fix extract_password --- nxc/modules/keepass_trigger.py | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/nxc/modules/keepass_trigger.py b/nxc/modules/keepass_trigger.py index 8b17b205..4c83acdd 100644 --- a/nxc/modules/keepass_trigger.py +++ b/nxc/modules/keepass_trigger.py @@ -385,24 +385,30 @@ class NXCModule: xml_to_dict = parse(to_string) dump = json.dumps(xml_to_dict) obj = json.loads(dump) - - if len(obj["KeePassFile"]["Root"]["Group"]["Entry"]): - for obj2 in obj["KeePassFile"]["Root"]["Group"]["Entry"]: - for password in obj2["String"]: - if password["Key"] == "Password": - context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]["#text"])) - else: - context.log.highlight(str(password["Key"]) + " : " + str(password["Value"])) - context.log.highlight("") - if len(obj["KeePassFile"]["Root"]["Group"]["Group"]): - for obj2 in obj["KeePassFile"]["Root"]["Group"]["Group"]: - try: - for obj3 in obj2["Entry"]: - for password in obj3["String"]: - if password["Key"] == "Password": - context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]["#text"])) - else: - context.log.highlight(str(password["Key"]) + " : " + str(password["Value"])) - context.log.highlight("") - except KeyError: - pass + + root_entries = root.find("./Root/Entry") + if root_entries is not None: + for entry in root_entries: + if entry is not None: + password = entry.find("./String[Key='Password']/Value") + self.print_password(context, entry) + else: + context.log.highlight("") + + objects = root.findall("./Root/Group") + while objects: + current_object = objects.pop(0) + for entry in current_object.findall("./Entry"): + self.print_password(context, entry) + for history in entry.findall("./History"): + for history_entry in history.findall("./Entry"): + self.print_password(context, history_entry) + objects.extend(current_object.findall("./Group")) + + def print_password(self, context, entry): + context.log.highlight(str("-------------------------------------")) + context.log.highlight(str("Title") + " : " + str(entry.find("./String[Key='Title']/Value").text)) + context.log.highlight(str("UserName") + " : " + str(entry.find("./String[Key='UserName']/Value").text)) + context.log.highlight(str("URL") + " : " + str(entry.find("./String[Key='URL']/Value").text)) + context.log.highlight(str("Password") + " : " + str(entry.find("./String[Key='Password']/Value").text)) + context.log.highlight(str("Notes") + " : " + str(entry.find("./String[Key='Notes']/Value").text)) \ No newline at end of file From 061ee498bf37e5cd84234c3b91228277e14268de Mon Sep 17 00:00:00 2001 From: sepauli Date: Sat, 25 May 2024 18:35:55 +0200 Subject: [PATCH 2/4] fix output for keepass2 --- nxc/modules/keepass_trigger.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nxc/modules/keepass_trigger.py b/nxc/modules/keepass_trigger.py index 4c83acdd..85419723 100644 --- a/nxc/modules/keepass_trigger.py +++ b/nxc/modules/keepass_trigger.py @@ -390,10 +390,9 @@ class NXCModule: if root_entries is not None: for entry in root_entries: if entry is not None: - password = entry.find("./String[Key='Password']/Value") self.print_password(context, entry) else: - context.log.highlight("") + context.log.highlight("None") objects = root.findall("./Root/Group") while objects: @@ -406,9 +405,10 @@ class NXCModule: objects.extend(current_object.findall("./Group")) def print_password(self, context, entry): - context.log.highlight(str("-------------------------------------")) - context.log.highlight(str("Title") + " : " + str(entry.find("./String[Key='Title']/Value").text)) - context.log.highlight(str("UserName") + " : " + str(entry.find("./String[Key='UserName']/Value").text)) - context.log.highlight(str("URL") + " : " + str(entry.find("./String[Key='URL']/Value").text)) - context.log.highlight(str("Password") + " : " + str(entry.find("./String[Key='Password']/Value").text)) - context.log.highlight(str("Notes") + " : " + str(entry.find("./String[Key='Notes']/Value").text)) \ No newline at end of file + for entry in entries.findall("./String"): + key = entry.find("./Key") + value = entry.find("./Value") + key_text = key.text if key is not None else "None" + value_text = value.text if value is not None and value.text is not None else "None" + context.log.highlight((f"{key_text} : {value_text}")) + context.log.highlight(str("-------------------------------------")) \ No newline at end of file From 94e0ab62eaa6029e23321ac2c279352d5bdf23a3 Mon Sep 17 00:00:00 2001 From: sepauli Date: Sat, 25 May 2024 18:58:29 +0200 Subject: [PATCH 3/4] fix typo --- nxc/modules/keepass_trigger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxc/modules/keepass_trigger.py b/nxc/modules/keepass_trigger.py index 85419723..e7ec876c 100644 --- a/nxc/modules/keepass_trigger.py +++ b/nxc/modules/keepass_trigger.py @@ -404,7 +404,7 @@ class NXCModule: self.print_password(context, history_entry) objects.extend(current_object.findall("./Group")) - def print_password(self, context, entry): + def print_password(self, context, entries): for entry in entries.findall("./String"): key = entry.find("./Key") value = entry.find("./Value") From efa0b75c10bad0d19362b0cba33b61a58bf0f127 Mon Sep 17 00:00:00 2001 From: Alexander Neff Date: Sat, 1 Jun 2024 17:47:07 -0400 Subject: [PATCH 4/4] Fix linting --- nxc/modules/keepass_trigger.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/nxc/modules/keepass_trigger.py b/nxc/modules/keepass_trigger.py index e7ec876c..d9d56d4c 100644 --- a/nxc/modules/keepass_trigger.py +++ b/nxc/modules/keepass_trigger.py @@ -1,7 +1,5 @@ import os import sys -import json -from xmltodict import parse from time import sleep from csv import reader from base64 import b64encode @@ -381,11 +379,7 @@ class NXCModule: xml_doc_path = os.path.abspath(self.local_export_path + "/" + self.export_name) xml_tree = ElementTree.parse(xml_doc_path) root = xml_tree.getroot() - to_string = ElementTree.tostring(root, encoding="UTF-8", method="xml") - xml_to_dict = parse(to_string) - dump = json.dumps(xml_to_dict) - obj = json.loads(dump) - + root_entries = root.find("./Root/Entry") if root_entries is not None: for entry in root_entries: @@ -393,7 +387,7 @@ class NXCModule: self.print_password(context, entry) else: context.log.highlight("None") - + objects = root.findall("./Root/Group") while objects: current_object = objects.pop(0) @@ -403,12 +397,12 @@ class NXCModule: for history_entry in history.findall("./Entry"): self.print_password(context, history_entry) objects.extend(current_object.findall("./Group")) - + def print_password(self, context, entries): for entry in entries.findall("./String"): key = entry.find("./Key") value = entry.find("./Value") key_text = key.text if key is not None else "None" value_text = value.text if value is not None and value.text is not None else "None" - context.log.highlight((f"{key_text} : {value_text}")) - context.log.highlight(str("-------------------------------------")) \ No newline at end of file + context.log.highlight(f"{key_text} : {value_text}") + context.log.highlight("-------------------------------------")