fix: decrypt password in firefox

pull/83/head
mirefly 4 years ago committed by ᴍᴏᴏɴD4ʀᴋ
parent 2a86bcf1c9
commit c8bab9db94
  1. 4
      core/data/parse.go
  2. 22
      core/decrypt/decrypt_linux.go

@ -613,11 +613,13 @@ func (p *passwords) FirefoxParse() error {
log.Debug("password-check success") log.Debug("password-check success")
m := bytes.Compare(nssA102, keyLin) m := bytes.Compare(nssA102, keyLin)
if m == 0 { if m == 0 {
nss, err := decrypt.DecodeNss(nssA11) var nss interface{}
nss, err = decrypt.DecodeNss(nssA11)
if err != nil { if err != nil {
log.Error("decode firefox nssA11 bytes failed", err) log.Error("decode firefox nssA11 bytes failed", err)
return err return err
} }
finallyKey, err := decrypt.Nss(globalSalt, masterPwd, nss) finallyKey, err := decrypt.Nss(globalSalt, masterPwd, nss)
finallyKey = finallyKey[:24] finallyKey = finallyKey[:24]
if err != nil { if err != nil {

@ -6,6 +6,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/asn1" "encoding/asn1"
"encoding/hex" "encoding/hex"
"errors"
"hack-browser-data/log" "hack-browser-data/log"
@ -100,21 +101,30 @@ func DecodeMeta(decodeItem []byte) (pbe MetaPBE, err error) {
return return
} }
func DecodeNss(nssA11Bytes []byte) (pbe NssPBE, err error) { func DecodeNss(nssA11Bytes []byte) (nss interface{}, err error) {
var pbe NssPBE
_, err = asn1.Unmarshal(nssA11Bytes, &pbe) _, err = asn1.Unmarshal(nssA11Bytes, &pbe)
if err != nil { if err != nil {
log.Error(err) return DecodeMeta(nssA11Bytes)
return
} }
return
return pbe, err
} }
func Meta(globalSalt, masterPwd []byte, pbe MetaPBE) ([]byte, error) { func Meta(globalSalt, masterPwd []byte, pbe MetaPBE) ([]byte, error) {
return decryptMeta(globalSalt, masterPwd, pbe.EntrySalt, pbe.Encrypted) return decryptMeta(globalSalt, masterPwd, pbe.EntrySalt, pbe.Encrypted)
} }
func Nss(globalSalt, masterPwd []byte, pbe NssPBE) ([]byte, error) { func Nss(globalSalt, masterPwd []byte, pbe interface{}) ([]byte, error) {
return decryptNss(globalSalt, masterPwd, pbe.IV, pbe.EntrySalt, pbe.Encrypted, pbe.IterationCount, pbe.KeySize) switch pbe.(type) {
case NssPBE:
return decryptNss(globalSalt, masterPwd, pbe.(NssPBE).IV, pbe.(NssPBE).EntrySalt, pbe.(NssPBE).Encrypted, pbe.(NssPBE).IterationCount, pbe.(NssPBE).KeySize)
case MetaPBE:
return decryptMeta(globalSalt, masterPwd, pbe.(MetaPBE).EntrySalt, pbe.(MetaPBE).Encrypted)
default:
return nil, errors.New("decrypt nss failed")
}
} }
func decryptMeta(globalSalt, masterPwd, entrySalt, encrypted []byte) ([]byte, error) { func decryptMeta(globalSalt, masterPwd, entrySalt, encrypted []byte) ([]byte, error) {

Loading…
Cancel
Save