I forgot my Browser’s saved password although a friend of mine tells that I can find it if I know my master key. The problem is I dont even remember that, hopefully you can rock your brain and help me out.
Author: W01f
firefox will rock your world
We’re provided 3 files:
cert9.db
key4.db
logins.json
A little bit of research tells us that these files are typical of a Firefox profile:
cert9.db
stores Firefox certificateskey4.db
stores information regarding the master password, which basically requires the user to input a password to view the saved website passwordslogins.db
stores encrypted website passwords, decrypted using the master password
After backing up my own versions of these files, I copied the challenge files into my local Firefox profile, which can be accessed by navigating to about:support
on Firefox and going to Application Basics -> Profile Folder -> Open Folder
. Opening up Firefox, however, I found that the password manager was protected by a master password (as explained in the challenge statement).
Seeing this, I realized that I likely had to crack the master password. The challenge description gave a hint towards this, saying “hopefully you can rock your brain and help me out.” This is evidently a reference to the rockyou.txt
password wordlist!
tool searching galore yay fun
I started doing some research into tools that could crack the Firefox master password. The first one I stumbled across was FireMaster. However, this tool proved to be way too slow (it would probably take at least a day to process the entire rockyou.txt wordlist!), so I kept looking. I soon realized that hashcat
had a hash mode for this, so I simply needed to extract the password from key4.db
.
Unfortunately, there seemed to be limited resources describing how to do this. Although FireMaster is open-source, I couldn’t seem to find the source code of it, as I would have liked to see how FireMaster extracted the hashed master password. I read through this article, but the method it described for extracting the master password failed for me. I found this tweet linking to a tool called Firepwd.py, which ultimately did not help me extract the master password, and a hashcat commit that added support for the Firefox master password. This commit wasn’t useful for finding out how to extract the passwords, but it did provide some information that would become useful in the future: the code in line 83 of tools/test_modules/m26100.pm showed how the hash should be formatted, based on the two salts, iteration number (which I guessed was just 10000 since that’s what it was on the hash mode example database for Mozilla key4.db
), IV, and ciphertext.
tysm random github user i love you
I, of course, looked at John the Ripper as well, but, unfortunately, it only worked for key3.db
, as written here. I still tried it locally on the key4.db
, but to no avail. Later, however, I found an issue on the Github repo that described the exact same problem. AlbertVeli actually made his own Python program to do exactly that! Well, at least mostly. It didn’t exactly reconstruct the master password hash in the form hashcat wanted it to be in.
FYI, here’s that program:
1 | #!/usr/bin/env python3 |
Fortunately, that hashcat commit from earlier told me the necessary parameters for formatting the hash in the format required by hashcat! Converting from the Python extraction program output to the hashcat commit code variable names:
database salt
=global_salt_bin
decoded salt
=entry_salt_bin
- 10000 =
iter
(remember this was from looking at the hashcat hash mode examples database) reconstructed IV
=iv_bin
decoded AES ciphertext
=ct_bin
Formatting the hash into hashcat’s desired format, we get:$mozilla$*AES*3510a742f59b198e198922f0c9bc43cf8ab52bf3*dadd3df784b946b13619b7f09fdce2e7a34e3e0cd4069263a0517d683d003695*10000*040e6bb3481d3086ee025f5b4b5b0afb*9c55609a7548c032b1bee0a1d948cec5
Run hashcat -a 0 -m 26100 hash ~/rockyou.txt
to get the master password of phoenixthefirebird14
.
Open up Firefox password manager, put in the master password, and get the decrypted password for picoctf.org!
flag{n0_p@ssw0rd_15_s3cur3??}