Listing All Passwords Stored in Gnome Keyring

I was toying with writing my first desktop application in years and got distracted by how cool Gnome Keyring is. Of course storing and retrieving passwords is pretty mundane, so here’s a fun example that dumps all of the current user’s passwords:

#!/usr/bin/env python
 
import pygtk
pygtk.require('2.0')
import gtk # sets app name
import gnomekeyring
 
def hack():
    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__':
    hack()

Sample output with the interesting bits removed:

[default] Local password for user root = *******
[login] michael.schurter@Work = *******
[login] Google Account = *******
[login] Passphrase for wireless network 2WIRE939 = *******
[login] Unlock password for default keyring = *******
[login] schmichael@twitter.com = *******
[session] --empty--

Its not meant to be any sort of real hacking tool. After all you can view all of this information via Seahorse anyway.

But what fun is a GUI tool? ;-)

This entry was posted in Open Source, Python, Technology and tagged , , , . Bookmark the permalink.
  • http://www.thok.org/bloggery _Mark_

    Hmm, that looks like would be easy enough to add to gcalcli, which could use something better than a dotfile for password storage (and is also in python already.)

  • johannes

    thanks, very helpful – especially because the seahorse GUI application doesn’t allow copy & paste!

  • Kamil Páral

    I have created a small project for accessing gnome-keyring from Python. It can be used as a Python module or from shell:
    https://launchpad.net/gkeyring

  • guest

    thanks – managed to retrieve a lost email account pw with this.

  • http://profiles.google.com/mattgatto Matthew Gatto

    I made the following changes to your script to get it to output usernames (as stored by chromium) if there any, for each password:

    — seahorse-password-list.py~ 2012-07-29 06:55:14.000000000 -0700
    +++ seahorse-password-list.py 2012-07-29 07:34:27.000000000 -0700
    @@ -9,7 +9,13 @@
    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’ % (
    + attr = gnomekeyring.item_get_attributes_sync(keyring, id)
    + if attr and attr.has_key(‘username_value’):
    + print ‘[%s] %s: %s = %s’ % (
    + keyring, item.get_display_name(),
    + attr['username_value'], item.get_secret())
    + else:
    + print ‘[%s] %s: %s’ % (
    keyring, item.get_display_name(), item.get_secret())
    else:
    if len(gnomekeyring.list_item_ids_sync(keyring)) == 0:

  • nailor
  • Tharaka Manawardhana

    Worked like a charm. You saved me. Thanks!

  • Tharaka Manawardhana

    Thanks! It worked!