2022-06-05 06:51:37 +00:00
|
|
|
//go:build windows
|
|
|
|
|
2022-04-08 11:06:04 +00:00
|
|
|
package chromium
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"errors"
|
2022-04-13 07:30:30 +00:00
|
|
|
"os"
|
2022-04-08 11:06:04 +00:00
|
|
|
|
|
|
|
"github.com/tidwall/gjson"
|
2022-04-11 07:53:19 +00:00
|
|
|
|
2023-06-04 05:47:43 +00:00
|
|
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
2024-10-22 03:13:06 +00:00
|
|
|
"github.com/moond4rk/hackbrowserdata/log"
|
2024-04-12 11:10:41 +00:00
|
|
|
"github.com/moond4rk/hackbrowserdata/types"
|
2023-06-04 05:47:43 +00:00
|
|
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
2022-04-08 11:06:04 +00:00
|
|
|
)
|
|
|
|
|
2022-06-05 06:51:37 +00:00
|
|
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
2022-04-08 11:06:04 +00:00
|
|
|
|
2023-03-10 06:52:26 +00:00
|
|
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
2024-04-12 11:10:41 +00:00
|
|
|
b, err := fileutil.ReadFile(types.ChromiumKey.TempFilename())
|
2022-04-08 11:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-04-12 11:10:41 +00:00
|
|
|
defer os.Remove(types.ChromiumKey.TempFilename())
|
2023-03-11 12:09:10 +00:00
|
|
|
|
|
|
|
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
|
2022-08-14 13:22:34 +00:00
|
|
|
if !encryptedKey.Exists() {
|
|
|
|
return nil, nil
|
2022-04-08 11:06:04 +00:00
|
|
|
}
|
2023-03-11 12:09:10 +00:00
|
|
|
|
|
|
|
key, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
2022-08-14 13:22:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errDecodeMasterKeyFailed
|
|
|
|
}
|
2024-01-27 14:30:28 +00:00
|
|
|
c.masterKey, err = crypto.DecryptWithDPAPI(key[5:])
|
2024-01-04 10:54:15 +00:00
|
|
|
if err != nil {
|
2024-10-22 03:13:06 +00:00
|
|
|
log.Errorf("decrypt master key failed, err %v", err)
|
2024-01-04 10:54:15 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-22 03:13:06 +00:00
|
|
|
log.Debugf("get master key success, browser %s", c.name)
|
2024-01-04 10:54:15 +00:00
|
|
|
return c.masterKey, nil
|
2022-04-08 11:06:04 +00:00
|
|
|
}
|