KEEPASS: mudanças entre as edições
Ir para navegação
Ir para pesquisar
(→Code) |
Sem resumo de edição |
||
Linha 1: | Linha 1: | ||
=Preparations= | =Preparations= | ||
<syntaxhighlight lang=bash> | <syntaxhighlight lang=bash> | ||
virtualenv -p $(which python3) kp | $ virtualenv -p $(which python3) kp | ||
source kp/bin/activate | $ source kp/bin/activate | ||
cd kp | $ cd kp | ||
touch kp.py | $ touch kp.py | ||
chmod +x kp.py | $ chmod +x kp.py | ||
pip install pykeepass | $ pip install pykeepass | ||
$ pip install argparse | |||
</syntaxhighlight> | </syntaxhighlight> | ||
=Code= | =Code= | ||
Linha 47: | Linha 48: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Running= | |||
<syntaxhighlight lang=bash> | |||
$ ./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' | |||
</syntaxhighlight > |
Edição das 14h20min de 17 de outubro de 2019
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'