Skip to content

Commit da9cb31

Browse files
committed
manage key3 and key4 db in firefox
Former-commit-id: 2eae26e [formerly 2eae26e [formerly 2eae26e [formerly a0d003e]]] Former-commit-id: 094ac1f44463da1a19e865c939213c9775ad78d6 Former-commit-id: 730c8da Former-commit-id: 65c33ca
1 parent fa976d9 commit da9cb31

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

Linux/lazagne/softwares/browsers/mozilla.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,49 +65,53 @@ def get_key(self, profile, master_password=''):
6565
try:
6666
conn = sqlite3.connect(os.path.join(profile, 'key4.db')) # Firefox 58.0.2 / NSS 3.35 with key4.db in SQLite
6767
c = conn.cursor()
68-
68+
6969
# First check password
7070
c.execute("SELECT item1,item2 FROM metadata WHERE id = 'password';")
7171
row = c.next()
7272

7373
(globalSalt, master_password, entrySalt) = self.manage_masterpassword(master_password='', key_data=row)
74-
if not globalSalt:
75-
return None
76-
77-
# Decrypt 3DES key to decrypt "logins.json" content
78-
c.execute("SELECT a11,a102 FROM nssPrivate;")
79-
a11, a102 = c.next()
80-
# a11 : CKA_VALUE
81-
# a102 : f8000000000000000000000000000001, CKA_ID
82-
self.printASN1(a11, len(a11), 0)
83-
"""
84-
SEQUENCE {
74+
if globalSalt:
75+
# Decrypt 3DES key to decrypt "logins.json" content
76+
c.execute("SELECT a11,a102 FROM nssPrivate;")
77+
a11, a102 = c.next()
78+
# a11 : CKA_VALUE
79+
# a102 : f8000000000000000000000000000001, CKA_ID
80+
self.printASN1(a11, len(a11), 0)
81+
"""
8582
SEQUENCE {
86-
OBJECTIDENTIFIER 1.2.840.113549.1.12.5.1.3
8783
SEQUENCE {
88-
OCTETSTRING entry_salt_for_3des_key
89-
INTEGER 01
84+
OBJECTIDENTIFIER 1.2.840.113549.1.12.5.1.3
85+
SEQUENCE {
86+
OCTETSTRING entry_salt_for_3des_key
87+
INTEGER 01
88+
}
9089
}
90+
OCTETSTRING encrypted_3des_key (with 8 bytes of PKCS#7 padding)
9191
}
92-
OCTETSTRING encrypted_3des_key (with 8 bytes of PKCS#7 padding)
93-
}
94-
"""
95-
decodedA11 = decoder.decode( a11 )
96-
entrySalt = decodedA11[0][0][1][0].asOctets()
97-
cipherT = decodedA11[0][1].asOctets()
98-
key = self.decrypt3DES(globalSalt, master_password, entrySalt, cipherT)
92+
"""
93+
decodedA11 = decoder.decode( a11 )
94+
entrySalt = decodedA11[0][0][1][0].asOctets()
95+
cipherT = decodedA11[0][1].asOctets()
96+
key = self.decrypt3DES(globalSalt, master_password, entrySalt, cipherT)
97+
if key:
98+
yield key[:24]
99+
99100
except:
101+
pass
102+
103+
try:
100104
key_data = self.readBsddb(os.path.join(profile, 'key3.db'))
101105

102106
# Check masterpassword
103107
(globalSalt, master_password, entrySalt) = self.manage_masterpassword(master_password='', key_data=key_data, new_version=False)
104-
if not globalSalt:
105-
return None
106-
107-
key = self.extractSecretKey(key_data=key_data, globalSalt=globalSalt, master_password=master_password, entrySalt=entrySalt)
108+
if globalSalt:
109+
key = self.extractSecretKey(key_data=key_data, globalSalt=globalSalt, master_password=master_password, entrySalt=entrySalt)
110+
if key:
111+
yield key[:24]
112+
except:
113+
pass
108114

109-
if not key: return None
110-
return key[:24]
111115

112116
def getShortLE(self, d, a):
113117
return unpack('<H',(d)[a:a+2])[0]
@@ -354,7 +358,7 @@ def found_master_password(self, key_data, new_version=True):
354358
return globalSalt, master_password, entrySalt
355359

356360
print_debug('WARNING', u'No password has been found using the default list')
357-
return ('', '', '')
361+
return False
358362

359363
def remove_padding(self, data):
360364
"""
@@ -387,10 +391,8 @@ def run(self, software_name=None):
387391
for profile in profile_list:
388392
print_debug('INFO', u'Profile path found: {profile}'.format(profile=profile))
389393

390-
key = self.get_key(profile)
391-
if key:
394+
for key in self.get_key(profile):
392395
credentials = self.getLoginData(profile)
393-
394396
for user, passw, url in credentials:
395397
try:
396398
pwdFound.append(
@@ -403,4 +405,4 @@ def run(self, software_name=None):
403405
except Exception, e:
404406
print_debug('DEBUG', u'An error occured decrypting the password: {error}'.format(error=e))
405407

406-
return pwdFound
408+
return pwdFound

Windows/laZagne.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
#!/usr/bin/python
23

34
##############################################################################

0 commit comments

Comments
 (0)