add try-luks-from-kdbx.py
Signed-off-by: Martin Matous <m@matous.dev>
This commit is contained in:
parent
12bb69a61c
commit
5f17d90c7b
2 changed files with 40 additions and 1 deletions
26
try-luks-from-kdbx.py
Executable file
26
try-luks-from-kdbx.py
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import getpass
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from pykeepass import PyKeePass
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print(f'Usage: {sys.argv[0]} /path/to/kdbx /path/to/block-device\n')
|
||||
|
||||
pwd = getpass.getpass('Enter database password:\n')
|
||||
kp = PyKeePass(sys.argv[1], password=pwd)
|
||||
cmd = ['cryptsetup', 'open', '--test-passphrase', sys.argv[2]]
|
||||
for entry in kp.entries:
|
||||
res = subprocess.run(
|
||||
cmd,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
input=entry.password.encode() # input accepts bytes, not str
|
||||
)
|
||||
if res.returncode == 0:
|
||||
print(f'Password found: {entry.title}\npw: {entry.password}')
|
||||
break
|
||||
else:
|
||||
print(f'Entry "{entry.title}" not a match')
|
||||
Loading…
Add table
Add a link
Reference in a new issue