docs: add key function documents

pull/83/head
moond4rk 4 years ago committed by ᴍᴏᴏɴD4ʀᴋ
parent b5ec1e89e6
commit 24f2ceb6b4
  1. 93
      core/browser.go
  2. 1
      core/browser_linux.go
  3. 5
      core/browser_windows.go
  4. 2
      core/decrypt/decrypt.go
  5. 1
      core/decrypt/decrypt_darwin.go
  6. 3
      core/decrypt/decrypt_linux.go
  7. 3
      core/decrypt/decrypt_windows.go
  8. 33
      utils/utils.go

@ -2,11 +2,12 @@ package core
import ( import (
"errors" "errors"
"fmt"
"path/filepath"
"strings" "strings"
"hack-browser-data/core/common" "hack-browser-data/core/data"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils"
) )
const ( const (
@ -29,10 +30,10 @@ type Browser interface {
GetSecretKey() []byte GetSecretKey() []byte
// GetAllItems return all of items (password|bookmark|cookie|history) // GetAllItems return all of items (password|bookmark|cookie|history)
GetAllItems() ([]common.Item, error) GetAllItems() ([]data.Item, error)
// GetItem return single one from password|bookmark|cookie|history // GetItem return single one from password|bookmark|cookie|history
GetItem(itemName string) (common.Item, error) GetItem(itemName string) (data.Item, error)
} }
const ( const (
@ -52,46 +53,46 @@ var (
var ( var (
chromiumItems = map[string]struct { chromiumItems = map[string]struct {
mainFile string mainFile string
newItem func(mainFile, subFile string) common.Item newItem func(mainFile, subFile string) data.Item
}{ }{
bookmark: { bookmark: {
mainFile: common.ChromeBookmarkFile, mainFile: data.ChromeBookmarkFile,
newItem: common.NewBookmarks, newItem: data.NewBookmarks,
}, },
cookie: { cookie: {
mainFile: common.ChromeCookieFile, mainFile: data.ChromeCookieFile,
newItem: common.NewCookies, newItem: data.NewCookies,
}, },
history: { history: {
mainFile: common.ChromeHistoryFile, mainFile: data.ChromeHistoryFile,
newItem: common.NewHistoryData, newItem: data.NewHistoryData,
}, },
password: { password: {
mainFile: common.ChromePasswordFile, mainFile: data.ChromePasswordFile,
newItem: common.NewCPasswords, newItem: data.NewCPasswords,
}, },
} }
firefoxItems = map[string]struct { firefoxItems = map[string]struct {
mainFile string mainFile string
subFile string subFile string
newItem func(mainFile, subFile string) common.Item newItem func(mainFile, subFile string) data.Item
}{ }{
bookmark: { bookmark: {
mainFile: common.FirefoxDataFile, mainFile: data.FirefoxDataFile,
newItem: common.NewBookmarks, newItem: data.NewBookmarks,
}, },
cookie: { cookie: {
mainFile: common.FirefoxCookieFile, mainFile: data.FirefoxCookieFile,
newItem: common.NewCookies, newItem: data.NewCookies,
}, },
history: { history: {
mainFile: common.FirefoxDataFile, mainFile: data.FirefoxDataFile,
newItem: common.NewHistoryData, newItem: data.NewHistoryData,
}, },
password: { password: {
mainFile: common.FirefoxKey4File, mainFile: data.FirefoxKey4File,
subFile: common.FirefoxLoginFile, subFile: data.FirefoxLoginFile,
newItem: common.NewFPasswords, newItem: data.NewFPasswords,
}, },
} }
) )
@ -104,6 +105,7 @@ type Chromium struct {
secretKey []byte secretKey []byte
} }
// NewChromium return chromium browser interface
func NewChromium(profile, key, name, storage string) (Browser, error) { func NewChromium(profile, key, name, storage string) (Browser, error) {
return &Chromium{profilePath: profile, keyPath: key, name: name, storage: storage}, nil return &Chromium{profilePath: profile, keyPath: key, name: name, storage: storage}, nil
} }
@ -116,10 +118,12 @@ func (c *Chromium) GetSecretKey() []byte {
return c.secretKey return c.secretKey
} }
func (c *Chromium) GetAllItems() (Items []common.Item, err error) { // GetAllItems return all chromium items from browser
var items []common.Item // if can't find item path, log error then continue
func (c *Chromium) GetAllItems() ([]data.Item, error) {
var items []data.Item
for item, choice := range chromiumItems { for item, choice := range chromiumItems {
m, err := utils.GetItemPath(c.profilePath, choice.mainFile) m, err := getItemPath(c.profilePath, choice.mainFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", c.name, item, err) log.Errorf("%s find %s file failed, ERR:%s", c.name, item, err)
continue continue
@ -131,10 +135,11 @@ func (c *Chromium) GetAllItems() (Items []common.Item, err error) {
return items, nil return items, nil
} }
func (c *Chromium) GetItem(itemName string) (common.Item, error) { // GetItem return single item
func (c *Chromium) GetItem(itemName string) (data.Item, error) {
itemName = strings.ToLower(itemName) itemName = strings.ToLower(itemName)
if item, ok := chromiumItems[itemName]; ok { if item, ok := chromiumItems[itemName]; ok {
m, err := utils.GetItemPath(c.profilePath, item.mainFile) m, err := getItemPath(c.profilePath, item.mainFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", c.name, item.mainFile, err) log.Errorf("%s find %s file failed, ERR:%s", c.name, item.mainFile, err)
} }
@ -151,25 +156,27 @@ type Firefox struct {
keyPath string keyPath string
} }
// NewFirefox return firefox browser interface
func NewFirefox(profile, key, name, storage string) (Browser, error) { func NewFirefox(profile, key, name, storage string) (Browser, error) {
return &Firefox{profilePath: profile, keyPath: key, name: name}, nil return &Firefox{profilePath: profile, keyPath: key, name: name}, nil
} }
func (f *Firefox) GetAllItems() ([]common.Item, error) { //
var items []common.Item func (f *Firefox) GetAllItems() ([]data.Item, error) {
var items []data.Item
for item, choice := range firefoxItems { for item, choice := range firefoxItems {
var ( var (
sub, main string sub, main string
err error err error
) )
if choice.subFile != "" { if choice.subFile != "" {
sub, err = utils.GetItemPath(f.profilePath, choice.subFile) sub, err = getItemPath(f.profilePath, choice.subFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err)
continue continue
} }
} }
main, err = utils.GetItemPath(f.profilePath, choice.mainFile) main, err = getItemPath(f.profilePath, choice.mainFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err)
continue continue
@ -181,7 +188,7 @@ func (f *Firefox) GetAllItems() ([]common.Item, error) {
return items, nil return items, nil
} }
func (f *Firefox) GetItem(itemName string) (common.Item, error) { func (f *Firefox) GetItem(itemName string) (data.Item, error) {
itemName = strings.ToLower(itemName) itemName = strings.ToLower(itemName)
if item, ok := firefoxItems[itemName]; ok { if item, ok := firefoxItems[itemName]; ok {
var ( var (
@ -189,12 +196,12 @@ func (f *Firefox) GetItem(itemName string) (common.Item, error) {
err error err error
) )
if item.subFile != "" { if item.subFile != "" {
sub, err = utils.GetItemPath(f.profilePath, item.subFile) sub, err = getItemPath(f.profilePath, item.subFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.subFile, err) log.Errorf("%s find %s file failed, ERR:%s", f.name, item.subFile, err)
} }
} }
main, err = utils.GetItemPath(f.profilePath, item.mainFile) main, err = getItemPath(f.profilePath, item.mainFile)
if err != nil { if err != nil {
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.mainFile, err) log.Errorf("%s find %s file failed, ERR:%s", f.name, item.mainFile, err)
} }
@ -210,14 +217,19 @@ func (f *Firefox) GetName() string {
return f.name return f.name
} }
// GetSecretKey for firefox is always nil
// this method use to implement Browser interface
func (f *Firefox) GetSecretKey() []byte { func (f *Firefox) GetSecretKey() []byte {
return nil return nil
} }
// InitSecretKey for firefox is always nil
// this method use to implement Browser interface
func (f *Firefox) InitSecretKey() error { func (f *Firefox) InitSecretKey() error {
return nil return nil
} }
// PickBrowser return a list of browser interface
func PickBrowser(name string) ([]Browser, error) { func PickBrowser(name string) ([]Browser, error) {
var browsers []Browser var browsers []Browser
name = strings.ToLower(name) name = strings.ToLower(name)
@ -238,6 +250,17 @@ func PickBrowser(name string) ([]Browser, error) {
return nil, errBrowserNotSupported return nil, errBrowserNotSupported
} }
func getItemPath(profilePath, file string) (string, error) {
p, err := filepath.Glob(profilePath + file)
if err != nil {
return "", err
}
if len(p) > 0 {
return p[0], nil
}
return "", fmt.Errorf("find %s failed", file)
}
func ListBrowser() []string { func ListBrowser() []string {
var l []string var l []string
for k := range browserList { for k := range browserList {

@ -2,6 +2,7 @@ package core
import ( import (
"crypto/sha1" "crypto/sha1"
"hack-browser-data/log" "hack-browser-data/log"
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"

@ -3,9 +3,10 @@ package core
import ( import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"os"
"hack-browser-data/core/decrypt" "hack-browser-data/core/decrypt"
"hack-browser-data/utils" "hack-browser-data/utils"
"os"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
@ -70,6 +71,8 @@ var (
errBase64DecodeFailed = errors.New("decode base64 failed") errBase64DecodeFailed = errors.New("decode base64 failed")
) )
// InitSecretKey on windows with win32 DPAPI
// conference from @https://gist.github.com/akamajoris/ed2f14d817d5514e7548
func (c *Chromium) InitSecretKey() error { func (c *Chromium) InitSecretKey() error {
if c.keyPath == "" { if c.keyPath == "" {
return nil return nil

@ -6,6 +6,7 @@ import (
"crypto/des" "crypto/des"
"encoding/asn1" "encoding/asn1"
"errors" "errors"
"hack-browser-data/log" "hack-browser-data/log"
) )
@ -33,6 +34,7 @@ func PKCS5UnPadding(src []byte) []byte {
return src[:(length - unpad)] return src[:(length - unpad)]
} }
// Des3Decrypt use for decrypt firefox PBE
func Des3Decrypt(key, iv []byte, src []byte) ([]byte, error) { func Des3Decrypt(key, iv []byte, src []byte) ([]byte, error) {
block, err := des.NewTripleDESCipher(key) block, err := des.NewTripleDESCipher(key)
if err != nil { if err != nil {

@ -4,6 +4,7 @@ import (
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/asn1" "encoding/asn1"
"hack-browser-data/log" "hack-browser-data/log"
) )

@ -6,6 +6,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/asn1" "encoding/asn1"
"encoding/hex" "encoding/hex"
"hack-browser-data/log" "hack-browser-data/log"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
@ -40,7 +41,6 @@ SEQUENCE (2 elem)
INTEGER 1 INTEGER 1
OCTET STRING (16 byte) OCTET STRING (16 byte)
*/ */
type MetaPBE struct { type MetaPBE struct {
SequenceA SequenceA
Encrypted []byte Encrypted []byte
@ -101,7 +101,6 @@ func DecodeMeta(decodeItem []byte) (pbe MetaPBE, err error) {
} }
func DecodeNss(nssA11Bytes []byte) (pbe NssPBE, err error) { func DecodeNss(nssA11Bytes []byte) (pbe NssPBE, err error) {
log.Debug(hex.EncodeToString(nssA11Bytes))
_, err = asn1.Unmarshal(nssA11Bytes, &pbe) _, err = asn1.Unmarshal(nssA11Bytes, &pbe)
if err != nil { if err != nil {
log.Error(err) log.Error(err)

@ -7,10 +7,11 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/asn1" "encoding/asn1"
"encoding/hex" "encoding/hex"
"hack-browser-data/log"
"syscall" "syscall"
"unsafe" "unsafe"
"hack-browser-data/log"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
) )

@ -7,7 +7,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"time" "time"
@ -16,38 +15,6 @@ import (
const Prefix = "[x]: " const Prefix = "[x]: "
func CopyDB(src, dst string) error {
locals, _ := filepath.Glob("*")
for _, v := range locals {
if v == dst {
err := os.Remove(dst)
if err != nil {
return err
}
}
}
sourceFile, err := ioutil.ReadFile(src)
if err != nil {
log.Debug(err.Error())
}
err = ioutil.WriteFile(dst, sourceFile, 0777)
if err != nil {
log.Debug(err.Error())
}
return err
}
func GetItemPath(profilePath, file string) (string, error) {
p, err := filepath.Glob(profilePath + file)
if err != nil {
return "", err
}
if len(p) > 0 {
return p[0], nil
}
return "", fmt.Errorf("find %s failed", file)
}
func IntToBool(a int) bool { func IntToBool(a int) bool {
switch a { switch a {
case 0, -1: case 0, -1:

Loading…
Cancel
Save