@@ -385,24 +385,30 @@ def extract_password(self, context):
385385 xml_to_dict = parse (to_string )
386386 dump = json .dumps (xml_to_dict )
387387 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
388+
389+ root_entries = root .find ("./Root/Entry" )
390+ if root_entries is not None :
391+ for entry in root_entries :
392+ if entry is not None :
393+ password = entry .find ("./String[Key='Password']/Value" )
394+ self .print_password (context , entry )
395+ else :
396+ context .log .highlight ("" )
397+
398+ objects = root .findall ("./Root/Group" )
399+ while objects :
400+ current_object = objects .pop (0 )
401+ for entry in current_object .findall ("./Entry" ):
402+ self .print_password (context , entry )
403+ for history in entry .findall ("./History" ):
404+ for history_entry in history .findall ("./Entry" ):
405+ self .print_password (context , history_entry )
406+ objects .extend (current_object .findall ("./Group" ))
407+
408+ def print_password (self , context , entry ):
409+ context .log .highlight (str ("-------------------------------------" ))
410+ context .log .highlight (str ("Title" ) + " : " + str (entry .find ("./String[Key='Title']/Value" ).text ))
411+ context .log .highlight (str ("UserName" ) + " : " + str (entry .find ("./String[Key='UserName']/Value" ).text ))
412+ context .log .highlight (str ("URL" ) + " : " + str (entry .find ("./String[Key='URL']/Value" ).text ))
413+ context .log .highlight (str ("Password" ) + " : " + str (entry .find ("./String[Key='Password']/Value" ).text ))
414+ context .log .highlight (str ("Notes" ) + " : " + str (entry .find ("./String[Key='Notes']/Value" ).text ))
0 commit comments