Decrypt Firefox Password Database

I want to write a simple utility that extracts passwords from a Firefox password database (the corresponding file is called signons.sqlite in the profile folder).

What I have done so far: an open database using sqlite, an extracted encrypted username, an encrypted password, and a website address (all stored as std::string ).

So, all that remains is to decrypt the username and password strings.

I tried the following ( PK11Decrypt should store the plaintext password in plaintext ):

 void Firefox_Importer::PK11Decrypt(string _cipheredBuffer, char **plaintext) { // declarations needed SECItem * request; SECItem * reply; unsigned int len = (unsigned int)_cipheredBuffer.length(); const char* cipheredBuffer = (const char*)_cipheredBuffer.c_str(); // generate request and reply SECItem; seems to work properly reply = SECITEM_AllocItem(NULL, NULL, 0); if (reply == NULL) cout << "Error allocating SECITEM." << endl; request = NSSBase64_DecodeBuffer(NULL, NULL, cipheredBuffer, len); if (request == NULL) cout << "Error decoding buffer." << endl; // the following is not working SECStatus tmp = PK11SDR_Decrypt(request, reply, NULL); if(tmp != SECSuccess) cout << "Something went wrong during decrypting" << endl; *plaintext = (char*)malloc(reply->len + 1); strncpy(*plaintext, (const char*)reply->data, reply->len); (*plaintext)[reply->len] = '\0'; SECITEM_FreeItem(request, true); SECITEM_FreeItem(reply, true); } 

When PK11Decrypt is PK11Decrypt , it prints Something went wrong during decrypting , indicating that the PK11SDR_Decrypt call PK11SDR_Decrypt not work properly. It always returns SECFailure (which corresponds to -1).

Does anyone have any clues or know what I'm doing wrong?

+4
source share
2 answers

It may happen that calling PK11_Authenticate() is not optional, even if the master password is not set (yes, NSS is very confusing). Therefore, you may need to do the following:

 PK11SlotInfo *slot = PK11_GetInternalKeySlot(); if (!slot) cout << "Error getting internal slot" << endl; SECStatus tmp = PK11_Authenticate(slot, PR_TRUE, NULL); if (tmp != SECSuccess) cout << "Authentication error" << endl; 

Note that I pass NULL as context to PK11_Authenticate() , context is only required if a password prompt is displayed.

Change Nothing, I noticed that PK11SDR_Decrypt() will call both functions internally. Given that you are getting a SECFailure result, it is likely that PK11_GetInternalKeySlot() not working, which indicates that NSS is not initialized properly.

+2
source

Firefox is open source software. You can find the latest source here , it's up to you to find the part where they decrypt the passwords and copy them to your application. Good luck.

+2
source

All Articles