Tuesday, August 11, 2015

I forgot my password, so here's a script...

gnome-keyring is what a lot of Linux / UNIX desktop environments rely upon in order to save passwords. Here's a script that dumps the contents of the gnome-keyring. It requires the gnomekeyring python module.

Special thanks to Michael Schurter for the majority of this code. I added two small improvements and deleted some dependencies.

#!/usr/bin/env python2

import getpass
import gnomekeyring

def dump_pass():
    gnomekeyring.unlock_sync(None, getpass.getpass());
    for keyring in gnomekeyring.list_keyring_names_sync():
        for id in gnomekeyring.list_item_ids_sync(keyring):
            item = gnomekeyring.item_get_info_sync(keyring, id)
            print '[%s] %s = %s' % (
                    keyring, item.get_display_name(), item.get_secret())
        else:
            if len(gnomekeyring.list_item_ids_sync(keyring)) == 0:
                print '[%s] --empty--' % keyring

if __name__ == '__main__':
    dump_pass()

No comments: