GetMasterKey
#340
-
I have a question about the chromium Get Master key function. When building and executing HackBrowserData the function works as expected but when I create a new function only to get the master key value it defaults to the peanuts value. My question is what is the setup required for this function to work? below is my code. package main
import (
"crypto/hmac"
"crypto/sha1"
"fmt"
"hash"
"log/slog"
"github.com/godbus/dbus/v5"
keyring "github.com/ppacher/go-dbus-keyring"
)
type Chromium struct {
name string
storage string
profilePath string
masterKey []byte
}
func main() {
var chromium Chromium
chromium.GetMasterKey()
}
func (c *Chromium) GetMasterKey() ([]byte, error) {
// what is d-bus @https://dbus.freedesktop.org/
// don't need chromium key file for Linux
//defer os.Remove(types.ChromiumKey.TempFilename())
conn, err := dbus.SessionBus()
if err != nil {
return nil, err
}
svc, err := keyring.GetSecretService(conn)
if err != nil {
return nil, err
}
session, err := svc.OpenSession()
if err != nil {
return nil, err
}
defer func() {
if err := session.Close(); err != nil {
slog.Error("close dbus session error", "err", err.Error())
}
}()
collections, err := svc.GetAllCollections()
if err != nil {
return nil, err
}
var secret []byte
for _, col := range collections {
items, err := col.GetAllItems()
if err != nil {
return nil, err
}
for _, i := range items {
label, err := i.GetLabel()
if err != nil {
slog.Warn("get label from dbus", "err", err.Error())
continue
}
if label == c.storage {
se, err := i.GetSecret(session.Path())
if err != nil {
return nil, fmt.Errorf("get storage from dbus: %w", err)
}
secret = se.Value
}
}
}
if len(secret) == 0 {
// set default secret @https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/os_crypt_linux.cc;l=100
secret = []byte("peanuts")
}
salt := []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
fmt.Println(secret, salt, 1, 16, sha1.New())
key := PBKDF2Key(secret, salt, 1, 16, sha1.New)
c.masterKey = key
slog.Info("get master key success", "browser", c.name)
return key, nil
}
func PBKDF2Key(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte {
prf := hmac.New(h, password)
hashLen := prf.Size()
numBlocks := (keyLen + hashLen - 1) / hashLen
var buf [4]byte
dk := make([]byte, 0, numBlocks*hashLen)
u := make([]byte, hashLen)
for block := 1; block <= numBlocks; block++ {
// N.B.: || means concatenation, ^ means XOR
// for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
// U_1 = PRF(password, salt || uint(i))
prf.Reset()
prf.Write(salt)
buf[0] = byte(block >> 24)
buf[1] = byte(block >> 16)
buf[2] = byte(block >> 8)
buf[3] = byte(block)
prf.Write(buf[:4])
dk = prf.Sum(dk)
t := dk[len(dk)-hashLen:]
copy(u, t)
for n := 2; n <= iter; n++ {
prf.Reset()
prf.Write(u)
u = u[:0]
u = prf.Sum(u)
for x := range u {
t[x] ^= u[x]
}
}
}
return dk[:keyLen]
} |
Beta Was this translation helpful? Give feedback.
Answered by
ghost
Jun 5, 2024
Replies: 1 comment
-
Its because c.storage was not set |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
moonD4rk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its because c.storage was not set