

渗透技巧——导出Firefox浏览器中保存的密码
source link: https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-%E5%AF%BC%E5%87%BAFirefox%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%AD%E4%BF%9D%E5%AD%98%E7%9A%84%E5%AF%86%E7%A0%81/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

0x00 前言
在之前的文章《渗透技巧——导出Chrome浏览器中保存的密码》介绍了导出Chrome浏览器密码的原理和利用方法,本文将要对导出Firefox浏览器密码的原理和利用方法进行介绍,分析利用思路。
0x01 简介
本文将要介绍以下内容:
- 密码保存方式
- 常用的导出工具
0x02 密码保存方式
正常用户在访问网站时,可选择使用Firefox浏览器保存登录的用户密码,用于下次登录的时候Firefox自动填写登录密码
可以通过选择Logins and Passwords进行查看,如下图

包括以下信息:
- Website address
- Username
- Password
- Created
- Last modified
- Last used
所有记录保存在同一个文件中,具体位置为:%APPDATA%\Mozilla\Firefox\Profiles\xxxxxxxx.default\
注:
xxxxxxxx为8位随机字母和数字的组合
不同版本的Firefox保存记录的文件名称不同,具体区别如下:
- Version大于等于32.0,保存记录的文件为logins.json
- Version大于等于3.5,小于32.0,保存记录的文件为signons.sqlite
更详细的文件说明可参考:
http://kb.mozillazine.org/Profile_folder_-_Firefox
不同版本Firefox的下载地址:
http://ftp.mozilla.org/pub/firefox/releases/
定位logins.json文件的位置可通过cmd命令实现,内容如下:
dir %APPDATA%\Mozilla\Firefox\Profiles\*logins.json /s /b
查看logins.json文件的内容,如下图

其中encryptedUsername
和encryptedPassword
是加密的内容,解密需要获得密钥文件(key和iv)并作3DES-CBC解密
不同版本的Firefox密钥文件的位置不同,具体区别如下:
- Version小于58.0.2,密钥文件为key3.db
- Version大于等于58.0.2,密钥文件为key4.db
注:
key3.db和key4.db的版本区别来源于https://github.com/lclevy/firepwd/blob/master/firepwd.py#L236
我在我的测试系统(Win7x64)下,安装64位Firefox,测试结果有所不同,具体如下:
- 如果Firefox的版本低于58.0,密钥文件为key3.db
- 如果Firefox为更高的版本,密钥文件为key4.db
默认情况下,当前用户的权限可以查看Firefox浏览器中保存的所有密码,为了提高安全性,Firefox浏览器支持为保存的密码添加额外的保护:设置Master Password
具体位置如下图

添加Master Password后,查看保存的密码需要额外输入Master Password
解密流程:
- 读取密钥文件(key4.db或key3.db),获得key和iv
- 读取记录文件(logins.json或signons.sqlite)的内容
- 如果未设置Master Password,使用key和iv对记录文件中的加密内容进行3DES-CBC解密 如果设置Master Password,还需要获得明文形式的Master Password,才能进行解密
0x03 导出工具
1.WebBrowserPassView.exe
下载地址:
https://www.nirsoft.net/utils/web_browser_password.html
注:
这个版本不支持命令行操作
命令行版本需要在另一地址下载:
https://www.nirsoft.net/password_recovery_tools.html
命令行下的使用方法:
WebBrowserPassView.exe /LoadPasswordsFirefox 1 /shtml "c:\test\passwords.html"
结果保存在c:\test\passwords.html
中,内容如下图

能获得完整的信息,包括以下类别:
- Website address
- Username
- Password
- Created
- Last modified
- Last used
不支持使用Master Password解密
2.firepwd.py
地址:https://github.com/lclevy/firepwd
需要安装依赖包:
pip install pyasn1
pip install pycrypto
能获得部分信息,包括以下类别:
- Website address
- Username
- Password
命令示例:
firepwd.py -d C:\Users\a\AppData\Roaming\Mozilla\Firefox\Profiles\5a4gs6zh.default-release\
结果如下图

支持使用Master Password解密
注:
我在自己的测试环境下,firepwd.py只支持key3.db的Master Passwor解密,key4.db的Master Passwor解密存在bug
命令示例:
使用测试文件mozilla_db(key3.db),Master Password为MISC*
,命令如下:
python firepwd.py -p 'MISC*' -d mozilla_db/
结果正常,如下图

我的测试环境(key4.db),Master Password为12345678
,命令如下:
firepwd.py -d C:\Users\a\AppData\Roaming\Mozilla\Firefox\Profiles\5a4gs6zh.default-release\ -p "12345678"
解密存在bug,提示口令失败,如下图

3.Lazagne
https://github.com/AlessandroZ/LaZagne/
导出Firefox浏览器的代码来自https://github.com/lclevy/firepwd
结果同上,如下图

4.firefox_decrypt.py
地址:https://github.com/unode/firefox_decrypt
使用NSS(Network Security Services)进行解密,支持key3.db和key4.db的Master Password解密
能获得部分信息,包括以下类别:
- Website address
- Username
- Password
测试结果如下图

在64位系统下,Python和Firefox的版本需要保持一致(同为32位或者同为64位),否则会提示ERROR - Problems opening 'nss3.dll' required for password decryption
注:
在下一篇文章《通过Network Security Services导出Firefox浏览器中保存的密码》将要详细介绍通过NSS解密的细节
5.Firefox浏览器
通过导出配置文件的方式实现
需要获得记录文件(logins.json或signons.sqlite)和密钥文件(key4.db或key3.db),保存在本地的文件夹C:\test\data1
使用-profile参数启动Firefox:
firefox.exe -profile C:\test\data1
输入正确的Master Password,成功获得Firefox浏览器保存的信息
0x04 利用思路
如果Firefox设置了Master Password,使用以上工具尝试导出密码时,结果会显示为0条结果,所以需要先读取记录文件确认是否存在记录
可以通过查询注册表的方式获得Firefox的版本,这里可以参考之前开源的代码:https://github.com/3gstudent/ListInstalledPrograms/blob/master/ListInstalledPrograms.ps1
不同版本的Firefox对应的记录文件不同,具体区别如下:
- Version大于等于32.0,保存记录的文件为logins.json
- Version大于等于3.5,小于32.0,保存记录的文件为signons.sqlite
定位logins.json文件的命令如下:
dir %APPDATA%\Mozilla\Firefox\Profiles\*logins.json /s /b
定位signons.sqlite文件的命令如下:
dir %APPDATA%\Mozilla\Firefox\Profiles\*signons.sqlite /s /b
如果存在记录,接下来就可以使用工具尝试导出
在离线导出时需要注意以下问题:
1.未设置Master Password
只需要获得记录文件(logins.json或signons.sqlite)和密钥文件(key4.db或key3.db)
使用firepwd.py或者Firefox浏览器导入配置文件即可
2.设置Master Password
(1)只获得记录文件(logins.json或signons.sqlite)和密钥文件(key4.db或key3.db)
本地使用Firefox浏览器导入配置文件,输入Master Password
(2)需要获得完整的配置文件
需要包括以下文件:
- %APPDATA%\Mozilla\Firefox\profiles.ini
- %APPDATA%\Mozilla\Firefox\Profiles\xxxxxxxx.default\中的文件
使用firefox_decrypt.py,命令示例:
firefox_decrypt.py C:\test\data1
0x05 小结
本文介绍了导出Firefox浏览器密码的原理和利用方法,分析了使用Master Password解密时需要注意的细节
对于普通用户来说,为了增加密码的安全性,建议设置Master Password
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK