Skip to content

Commit 67da598

Browse files
authored
Merge pull request Pennyw0rth#279 from sepauli/sepauli/fix-keepass_trigger
fix extract_password
2 parents 6858958 + efa0b75 commit 67da598

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

nxc/modules/keepass_trigger.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
22
import sys
3-
import json
4-
from xmltodict import parse
53
from time import sleep
64
from csv import reader
75
from base64 import b64encode
@@ -381,28 +379,30 @@ def extract_password(self, context):
381379
xml_doc_path = os.path.abspath(self.local_export_path + "/" + self.export_name)
382380
xml_tree = ElementTree.parse(xml_doc_path)
383381
root = xml_tree.getroot()
384-
to_string = ElementTree.tostring(root, encoding="UTF-8", method="xml")
385-
xml_to_dict = parse(to_string)
386-
dump = json.dumps(xml_to_dict)
387-
obj = json.loads(dump)
388-
389-
if len(obj["KeePassFile"]["Root"]["Group"]["Entry"]):
390-
for obj2 in obj["KeePassFile"]["Root"]["Group"]["Entry"]:
391-
for password in obj2["String"]:
392-
if password["Key"] == "Password":
393-
context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]["#text"]))
394-
else:
395-
context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]))
396-
context.log.highlight("")
397-
if len(obj["KeePassFile"]["Root"]["Group"]["Group"]):
398-
for obj2 in obj["KeePassFile"]["Root"]["Group"]["Group"]:
399-
try:
400-
for obj3 in obj2["Entry"]:
401-
for password in obj3["String"]:
402-
if password["Key"] == "Password":
403-
context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]["#text"]))
404-
else:
405-
context.log.highlight(str(password["Key"]) + " : " + str(password["Value"]))
406-
context.log.highlight("")
407-
except KeyError:
408-
pass
382+
383+
root_entries = root.find("./Root/Entry")
384+
if root_entries is not None:
385+
for entry in root_entries:
386+
if entry is not None:
387+
self.print_password(context, entry)
388+
else:
389+
context.log.highlight("None")
390+
391+
objects = root.findall("./Root/Group")
392+
while objects:
393+
current_object = objects.pop(0)
394+
for entry in current_object.findall("./Entry"):
395+
self.print_password(context, entry)
396+
for history in entry.findall("./History"):
397+
for history_entry in history.findall("./Entry"):
398+
self.print_password(context, history_entry)
399+
objects.extend(current_object.findall("./Group"))
400+
401+
def print_password(self, context, entries):
402+
for entry in entries.findall("./String"):
403+
key = entry.find("./Key")
404+
value = entry.find("./Value")
405+
key_text = key.text if key is not None else "None"
406+
value_text = value.text if value is not None and value.text is not None else "None"
407+
context.log.highlight(f"{key_text} : {value_text}")
408+
context.log.highlight("-------------------------------------")

0 commit comments

Comments
 (0)