De Wiki Clusterlab.com.br
Ir para navegação
Ir para pesquisar
Preparations
$ virtualenv -p $(which python3) kp
$ source kp/bin/activate
$ cd kp
$ touch kp.py
$ chmod +x kp.py
$ pip install pykeepass
$ pip install argparse
Code
#!/usr/bin/env python
from pykeepass import PyKeePass
import argparse
class KeePass:
def __init__(self,dbfile, dbkey):
self.dbfile = dbfile
self.dbkey = dbkey
def extract(self):
with PyKeePass(self.dbfile, password=self.dbkey) as kp:
for entry in kp.entries:
grupo = str(entry.group).replace("\n", "")
path = str(entry.path).replace("\n", "")
title = str(entry.title).replace("\n", "")
notes = str(entry.notes).replace("\n", "")
username = str(entry.username).replace("\n", "")
password = str(entry.password).replace("\n", "")
print("\"" + grupo + "\";\"" + path + "\";\"" + title + "\";\"" + notes + "\";\"" + username + "\";\"" + password + "\"")
parser = argparse.ArgumentParser(description='KeePass extractor, By D´Amato')
parser.add_argument('--dbfile', action='store', help='dbfile to extract')
parser.add_argument('--dbkey', action='store', help='Secret t open dbfile')
parser.parse_args([])
args = parser.parse_args()
if args.dbfile is not None:
if args.dbkey is not None:
mykp = KeePass(dbfile=args.dbfile,dbkey=args.dbkey)
mykp.extract()
else:
print("Error. use --help for more information")
else:
print("Error. use --help for more information")
Running
$ ./kp.py --help
usage: kp.py [-h] [--dbfile DBFILE] [--dbkey DBKEY]
KeePass extractor, By D´Amato
optional arguments:
-h, --help show this help message and exit
--dbfile DBFILE dbfile to extract
--dbkey DBKEY Secret to open dbfile
$ ./kp.py --dbfile all-my-secrets.kdbx --dbkey 'MyVeryStrongP@ssw0rd'