mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: rename browser layout and add generics util function
This commit is contained in:
+13
-22
@@ -4,7 +4,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/data"
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/browser/chromium"
|
||||
)
|
||||
|
||||
type Browser interface {
|
||||
@@ -12,13 +13,13 @@ type Browser interface {
|
||||
|
||||
GetMasterKey() ([]byte, error)
|
||||
|
||||
GetBrowsingData() []data.BrowsingData
|
||||
GetBrowsingData() []browingdata.Source
|
||||
|
||||
CopyItemFileToLocal() error
|
||||
}
|
||||
|
||||
var (
|
||||
// home dir path not for android and ios
|
||||
// home dir path for all platforms
|
||||
homeDir, _ = os.UserHomeDir()
|
||||
)
|
||||
|
||||
@@ -43,8 +44,8 @@ func pickChromium(name string) []Browser {
|
||||
var browsers []Browser
|
||||
name = strings.ToLower(name)
|
||||
if name == "all" {
|
||||
for _, choice := range chromiumList {
|
||||
if b, err := newChromium(choice.browserInfo, choice.items); err == nil {
|
||||
for _, c := range chromiumList {
|
||||
if b, err := chromium.New(c.name, c.profilePath, c.storage, c.items); err == nil {
|
||||
browsers = append(browsers, b)
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "profile path is not exist") {
|
||||
@@ -95,30 +96,20 @@ func ListBrowser() []string {
|
||||
return l
|
||||
}
|
||||
|
||||
func isFileExist(path string) bool {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type browserInfo struct {
|
||||
name string
|
||||
storage string
|
||||
profilePath string
|
||||
masterKey []byte
|
||||
masterKey []byte
|
||||
}
|
||||
|
||||
const (
|
||||
chromeName = "Chrome"
|
||||
chromeBetaName = "Chrome Beta"
|
||||
chromiumName = "Chromium"
|
||||
chromiumName = "ChromiumBookmark"
|
||||
edgeName = "Microsoft Edge"
|
||||
firefoxName = "Firefox"
|
||||
firefoxBetaName = "Firefox Beta"
|
||||
firefoxDevName = "Firefox Dev"
|
||||
firefoxNightlyName = "Firefox Nightly"
|
||||
firefoxESRName = "Firefox ESR"
|
||||
firefoxName = "FirefoxBookmark"
|
||||
firefoxBetaName = "FirefoxBookmark Beta"
|
||||
firefoxDevName = "FirefoxBookmark Dev"
|
||||
firefoxNightlyName = "FirefoxBookmark Nightly"
|
||||
firefoxESRName = "FirefoxBookmark ESR"
|
||||
speed360Name = "360speed"
|
||||
qqBrowserName = "QQ"
|
||||
braveName = "Brave"
|
||||
|
||||
@@ -1,121 +1,104 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"os/exec"
|
||||
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
|
||||
"hack-browser-data/internal/item"
|
||||
)
|
||||
|
||||
var (
|
||||
chromiumList = map[string]struct {
|
||||
browserInfo *browserInfo
|
||||
name string
|
||||
storage string
|
||||
profilePath string
|
||||
items []item.Item
|
||||
}{
|
||||
"chrome": {
|
||||
browserInfo: chromeInfo,
|
||||
name: chromeName,
|
||||
storage: chromeStorageName,
|
||||
profilePath: chromeProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"edge": {
|
||||
browserInfo: edgeInfo,
|
||||
name: edgeName,
|
||||
storage: edgeStorageName,
|
||||
profilePath: edgeProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"chromium": {
|
||||
browserInfo: chromiumInfo,
|
||||
name: chromiumName,
|
||||
storage: chromiumStorageName,
|
||||
profilePath: chromiumProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"chrome-beta": {
|
||||
browserInfo: chromeBetaInfo,
|
||||
name: chromeBetaName,
|
||||
storage: chromeBetaStorageName,
|
||||
profilePath: chromeBetaProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"opera": {
|
||||
browserInfo: operaInfo,
|
||||
name: operaName,
|
||||
profilePath: operaProfilePath,
|
||||
storage: operaStorageName,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"opera-gx": {
|
||||
browserInfo: operaGXInfo,
|
||||
name: operaGXName,
|
||||
profilePath: operaGXProfilePath,
|
||||
storage: operaStorageName,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"vivaldi": {
|
||||
browserInfo: vivaldiInfo,
|
||||
name: vivaldiName,
|
||||
storage: vivaldiStorageName,
|
||||
profilePath: vivaldiProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"coccoc": {
|
||||
browserInfo: coccocInfo,
|
||||
name: coccocName,
|
||||
storage: coccocStorageName,
|
||||
profilePath: coccocProfilePath,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"brave": {
|
||||
browserInfo: braveInfo,
|
||||
name: braveName,
|
||||
profilePath: braveProfilePath,
|
||||
storage: braveStorageName,
|
||||
items: item.DefaultChromium,
|
||||
},
|
||||
"yandex": {
|
||||
browserInfo: yandexInfo,
|
||||
name: yandexName,
|
||||
storage: yandexStorageName,
|
||||
profilePath: yandexProfilePath,
|
||||
items: item.DefaultYandex,
|
||||
},
|
||||
}
|
||||
firefoxList = map[string]struct {
|
||||
browserInfo *browserInfo
|
||||
name string
|
||||
storage string
|
||||
profilePath string
|
||||
items []item.Item
|
||||
}{
|
||||
"firefox": {
|
||||
browserInfo: firefoxInfo,
|
||||
items: defaultFirefoxItems,
|
||||
name: firefoxName,
|
||||
profilePath: firefoxProfilePath,
|
||||
items: item.DefaultFirefox,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
|
||||
)
|
||||
chromeProfilePath = homeDir + "/Library/Application Support/Google/Chrome/"
|
||||
chromeBetaProfilePath = homeDir + "/Library/Application Support/Google/Chrome Beta/"
|
||||
chromiumProfilePath = homeDir + "/Library/Application Support/Chromium/"
|
||||
edgeProfilePath = homeDir + "/Library/Application Support/Microsoft Edge/"
|
||||
braveProfilePath = homeDir + "/Library/Application Support/BraveSoftware/Brave-Browser/"
|
||||
operaProfilePath = homeDir + "/Library/Application Support/com.operasoftware.Opera/"
|
||||
operaGXProfilePath = homeDir + "/Library/Application Support/com.operasoftware.OperaGX/"
|
||||
vivaldiProfilePath = homeDir + "/Library/Application Support/Vivaldi/"
|
||||
coccocProfilePath = homeDir + "/Library/Application Support/Coccoc/"
|
||||
yandexProfilePath = homeDir + "/Library/Application Support/Yandex/YandexBrowser/"
|
||||
|
||||
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
var (
|
||||
cmd *exec.Cmd
|
||||
stdout, stderr bytes.Buffer
|
||||
)
|
||||
// $ security find-generic-password -wa 'Chrome'
|
||||
cmd = exec.Command("security", "find-generic-password", "-wa", c.browserInfo.storage)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
return nil, errors.New(stderr.String())
|
||||
}
|
||||
temp := stdout.Bytes()
|
||||
chromeSecret := temp[:len(temp)-1]
|
||||
if chromeSecret == nil {
|
||||
return nil, ErrWrongSecurityCommand
|
||||
}
|
||||
var chromeSalt = []byte("saltysalt")
|
||||
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
|
||||
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
|
||||
if key != nil {
|
||||
c.browserInfo.masterKey = key
|
||||
return key, nil
|
||||
}
|
||||
return nil, errors.New("macOS wrong security command")
|
||||
}
|
||||
|
||||
const (
|
||||
chromeProfilePath = "/Library/Application Support/Google/Chrome/"
|
||||
chromeBetaProfilePath = "/Library/Application Support/Google/Chrome Beta/"
|
||||
chromiumProfilePath = "/Library/Application Support/Chromium/"
|
||||
edgeProfilePath = "/Library/Application Support/Microsoft Edge/"
|
||||
braveProfilePath = "/Library/Application Support/BraveSoftware/Brave-Browser/"
|
||||
operaProfilePath = "/Library/Application Support/com.operasoftware.Opera/"
|
||||
operaGXProfilePath = "/Library/Application Support/com.operasoftware.OperaGX/"
|
||||
vivaldiProfilePath = "/Library/Application Support/Vivaldi/"
|
||||
coccocProfilePath = "/Library/Application Support/Coccoc/"
|
||||
yandexProfilePath = "/Library/Application Support/Yandex/YandexBrowser/"
|
||||
|
||||
firefoxProfilePath = "/Library/Application Support/Firefox/Profiles/"
|
||||
firefoxProfilePath = homeDir + "/Library/Application Support/Firefox/Profiles/"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -129,60 +112,3 @@ const (
|
||||
coccocStorageName = "CocCoc"
|
||||
yandexStorageName = "Yandex"
|
||||
)
|
||||
|
||||
var (
|
||||
chromeInfo = &browserInfo{
|
||||
name: chromeName,
|
||||
storage: chromeStorageName,
|
||||
profilePath: chromeProfilePath,
|
||||
}
|
||||
chromiumInfo = &browserInfo{
|
||||
name: chromiumName,
|
||||
storage: chromiumStorageName,
|
||||
profilePath: chromiumProfilePath,
|
||||
}
|
||||
chromeBetaInfo = &browserInfo{
|
||||
name: chromeBetaName,
|
||||
storage: chromeBetaStorageName,
|
||||
profilePath: chromeBetaProfilePath,
|
||||
}
|
||||
operaInfo = &browserInfo{
|
||||
name: operaName,
|
||||
profilePath: operaProfilePath,
|
||||
storage: operaStorageName,
|
||||
}
|
||||
operaGXInfo = &browserInfo{
|
||||
name: operaGXName,
|
||||
profilePath: operaGXProfilePath,
|
||||
storage: operaStorageName,
|
||||
}
|
||||
edgeInfo = &browserInfo{
|
||||
name: edgeName,
|
||||
storage: edgeStorageName,
|
||||
profilePath: edgeProfilePath,
|
||||
}
|
||||
braveInfo = &browserInfo{
|
||||
name: braveName,
|
||||
profilePath: braveProfilePath,
|
||||
storage: braveStorageName,
|
||||
}
|
||||
vivaldiInfo = &browserInfo{
|
||||
name: vivaldiName,
|
||||
storage: vivaldiStorageName,
|
||||
profilePath: vivaldiProfilePath,
|
||||
}
|
||||
coccocInfo = &browserInfo{
|
||||
name: coccocName,
|
||||
storage: coccocStorageName,
|
||||
profilePath: coccocProfilePath,
|
||||
}
|
||||
yandexInfo = &browserInfo{
|
||||
name: yandexName,
|
||||
storage: yandexStorageName,
|
||||
profilePath: yandexProfilePath,
|
||||
}
|
||||
firefoxInfo = &browserInfo{
|
||||
name: firefoxName,
|
||||
profilePath: firefoxProfilePath,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"hack-browser-data/internal/browser/item"
|
||||
|
||||
"hack-browser-data/internal/decrypter"
|
||||
item2 "hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,27 +33,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||||
)
|
||||
|
||||
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
keyFile, err := utils.ReadFile(item.TempChromiumKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
|
||||
if encryptedKey.Exists() {
|
||||
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
||||
if err != nil {
|
||||
return nil, errDecodeMasterKeyFailed
|
||||
}
|
||||
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:])
|
||||
return c.browserInfo.masterKey, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
chromeInfo = &browserInfo{
|
||||
name: chromeName,
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/data"
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
"hack-browser-data/internal/utils/typeutil"
|
||||
)
|
||||
|
||||
type chromium struct {
|
||||
@@ -21,24 +22,26 @@ type chromium struct {
|
||||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
// New 根据浏览器信息生成 Browser Interface
|
||||
// New creates a new instance of chromium browser, fill item's path if item is exist.
|
||||
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
|
||||
|
||||
// TODO: Handle file path is not exist
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
|
||||
}
|
||||
itemsPaths, err := getChromiumItemPath(profilePath, items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := &chromium{
|
||||
name: name,
|
||||
storage: storage,
|
||||
profilePath: profilePath,
|
||||
items: items,
|
||||
items: typeutil.Keys(itemsPaths),
|
||||
itemPaths: itemsPaths,
|
||||
}
|
||||
absProfilePath := path.Join(homeDir, filepath.Clean(c.ProfilePath))
|
||||
// TODO: Handle file path is not exist
|
||||
if !isFileExist(absProfilePath) {
|
||||
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
|
||||
}
|
||||
itemsPaths, err := getChromiumItemPath(absProfilePath, c.items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.itemPaths = itemsPaths
|
||||
// new browsing data
|
||||
return c, err
|
||||
}
|
||||
|
||||
@@ -46,8 +49,9 @@ func (c *chromium) GetName() string {
|
||||
return c.name
|
||||
}
|
||||
|
||||
func (c *chromium) GetBrowsingData() []data.BrowsingData {
|
||||
var browsingData []data.BrowsingData
|
||||
func (c *chromium) GetBrowsingData() []browingdata.Source {
|
||||
var browsingData []browingdata.Source
|
||||
data := browingdata.New(c.items)
|
||||
for item := range c.itemPaths {
|
||||
d := item.NewBrowsingData()
|
||||
if d != nil {
|
||||
@@ -95,9 +99,10 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat
|
||||
for _, it := range items {
|
||||
switch {
|
||||
case it.FileName() == info.Name():
|
||||
if it == it.chromiumKey {
|
||||
if it == item.ChromiumKey {
|
||||
itemPaths[it] = path
|
||||
}
|
||||
// TODO: Handle file path is not in Default folder
|
||||
if strings.Contains(path, "Default") {
|
||||
itemPaths[it] = path
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package chromium
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"errors"
|
||||
"os/exec"
|
||||
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
|
||||
)
|
||||
|
||||
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
var (
|
||||
cmd *exec.Cmd
|
||||
stdout, stderr bytes.Buffer
|
||||
)
|
||||
// $ security find-generic-password -wa 'Chrome'
|
||||
cmd = exec.Command("security", "find-generic-password", "-wa", c.storage)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if stderr.Len() > 0 {
|
||||
return nil, errors.New(stderr.String())
|
||||
}
|
||||
temp := stdout.Bytes()
|
||||
chromeSecret := temp[:len(temp)-1]
|
||||
if chromeSecret == nil {
|
||||
return nil, ErrWrongSecurityCommand
|
||||
}
|
||||
var chromeSalt = []byte("saltysalt")
|
||||
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
|
||||
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
|
||||
if key != nil {
|
||||
c.browserInfo.masterKey = key
|
||||
return key, nil
|
||||
}
|
||||
return nil, errors.New("macOS wrong security command")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package chromium
|
||||
@@ -0,0 +1,30 @@
|
||||
package chromium
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
|
||||
"github.com/smallstep/cli/utils"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var (
|
||||
errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||||
)
|
||||
|
||||
func (c *chromium) GetMasterKey() ([]byte, error) {
|
||||
keyFile, err := utils.ReadFile(item.TempChromiumKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encryptedKey := gjson.Get(keyFile, "os_crypt.encrypted_key")
|
||||
if encryptedKey.Exists() {
|
||||
pureKey, err := base64.StdEncoding.DecodeString(encryptedKey.String())
|
||||
if err != nil {
|
||||
return nil, errDecodeMasterKeyFailed
|
||||
}
|
||||
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:])
|
||||
return c.browserInfo.masterKey, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/data"
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/item"
|
||||
)
|
||||
|
||||
@@ -117,8 +117,8 @@ func (f *firefox) GetName() string {
|
||||
return f.name
|
||||
}
|
||||
|
||||
func (f *firefox) GetBrowsingData() []data.BrowsingData {
|
||||
var browsingData []data.BrowsingData
|
||||
func (f *firefox) GetBrowsingData() []browingdata.Source {
|
||||
var browsingData []browingdata.Source
|
||||
for item := range f.itemPaths {
|
||||
d := item.NewBrowsingData()
|
||||
if d != nil {
|
||||
|
||||
Reference in New Issue
Block a user