mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-07-06 21:37:47 +02:00
feat: rename browser layout and add generics util function
This commit is contained in:
+5
-5
@@ -23,10 +23,10 @@ var (
|
|||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "hack-browser-data",
|
Name: "hack-browser-browingdata",
|
||||||
Usage: "Export passwords/cookies/history/bookmarks from browser",
|
Usage: "Export passwords/cookies/history/bookmarks from browser",
|
||||||
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\n Get all data(password/cookie/history/bookmark) from chrome",
|
UsageText: "[hack-browser-browingdata -b chrome -f json -dir results -cc]\n Get all browingdata(password/cookie/history/bookmark) from chrome",
|
||||||
Version: "0.3.8",
|
Version: "0.4.0",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
|
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
|
||||||
&cli.BoolFlag{Name: "compress", Aliases: []string{"cc"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
|
&cli.BoolFlag{Name: "compress", Aliases: []string{"cc"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
|
||||||
@@ -88,9 +88,9 @@ func Execute() {
|
|||||||
|
|
||||||
// func Execute() {
|
// func Execute() {
|
||||||
// app := &cli.App{
|
// app := &cli.App{
|
||||||
// Name: "hack-browser-data",
|
// Name: "hack-browser-browingdata",
|
||||||
// Usage: "Export passwords/cookies/history/bookmarks from browser",
|
// Usage: "Export passwords/cookies/history/bookmarks from browser",
|
||||||
// UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\n Get all data(password/cookie/history/bookmark) from chrome",
|
// UsageText: "[hack-browser-browingdata -b chrome -f json -dir results -cc]\n Get all browingdata(password/cookie/history/bookmark) from chrome",
|
||||||
// Version: "0.3.7",
|
// Version: "0.3.7",
|
||||||
// Flags: []cli.Flag{
|
// Flags: []cli.Flag{
|
||||||
// &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
|
// &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
|
||||||
|
|||||||
@@ -6,17 +6,29 @@ require (
|
|||||||
github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9
|
github.com/gocarina/gocsv v0.0.0-20211203214250-4735fba0c1d9
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/mattn/go-sqlite3 v1.14.9
|
github.com/mattn/go-sqlite3 v1.14.9
|
||||||
|
github.com/smallstep/cli v0.18.2
|
||||||
github.com/tidwall/gjson v1.9.3
|
github.com/tidwall/gjson v1.9.3
|
||||||
github.com/urfave/cli/v2 v2.2.0
|
github.com/urfave/cli/v2 v2.2.0
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
|
github.com/manifoldco/promptui v0.9.0 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||||
|
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
github.com/tidwall/match v1.1.1 // indirect
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
github.com/tidwall/pretty v1.2.0 // indirect
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
|
github.com/urfave/cli v1.22.5 // indirect
|
||||||
|
go.step.sm/cli-utils v0.7.2 // indirect
|
||||||
|
go.step.sm/crypto v0.15.0 // indirect
|
||||||
|
golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,25 +1,30 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"hack-browser-data/internal/browser/item"
|
"hack-browser-data/internal/item"
|
||||||
|
|
||||||
item2 "hack-browser-data/internal/item"
|
|
||||||
"hack-browser-data/internal/utils"
|
"hack-browser-data/internal/utils"
|
||||||
|
"hack-browser-data/internal/utils/fileutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ChromiumBookmark struct {
|
type ChromiumBookmark []bookmark
|
||||||
bookmarks []bookmark
|
|
||||||
item item2.Item
|
type bookmark struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
URL string
|
||||||
|
DateAdded time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChromiumBookmark) Parse(masterKey []byte) error {
|
func (c *ChromiumBookmark) Parse(masterKey []byte) error {
|
||||||
bookmarks, err := utils.ReadFile(item.ChromiumBookmarkFilename)
|
bookmarks, err := fileutil.ReadFile("bookmark")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -32,8 +37,8 @@ func (c *ChromiumBookmark) Parse(masterKey []byte) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
// TODO: 使用泛型重构
|
// TODO: 使用泛型重构
|
||||||
sort.Slice(c.bookmarks, func(i, j int) bool {
|
sort.Slice(*c, func(i, j int) bool {
|
||||||
return (c.bookmarks)[i].DateAdded.After((c.bookmarks)[j].DateAdded)
|
return (*c)[i].DateAdded.After((*c)[j].DateAdded)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,58 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hack-browser-data/internal/item"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BrowsingData interface {
|
type BrowsingData struct {
|
||||||
|
sources map[item.Item]Source
|
||||||
|
}
|
||||||
|
|
||||||
|
type Source interface {
|
||||||
Parse(masterKey []byte) error
|
Parse(masterKey []byte) error
|
||||||
|
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New(sources []item.Item) *BrowsingData {
|
||||||
|
bd := &BrowsingData{
|
||||||
|
sources: make(map[item.Item]Source),
|
||||||
|
}
|
||||||
|
bd.addSource(sources)
|
||||||
|
return bd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BrowsingData) addSource(sources []item.Item) {
|
||||||
|
for _, source := range sources {
|
||||||
|
switch source {
|
||||||
|
case item.ChromiumPassword:
|
||||||
|
b.sources[source] = &ChromiumPassword{}
|
||||||
|
case item.ChromiumCookie:
|
||||||
|
b.sources[source] = &ChromiumCookie{}
|
||||||
|
case item.ChromiumBookmark:
|
||||||
|
b.sources[source] = &ChromiumBookmark{}
|
||||||
|
case item.ChromiumHistory:
|
||||||
|
b.sources[source] = &ChromiumHistory{}
|
||||||
|
case item.ChromiumDownload:
|
||||||
|
b.sources[source] = &ChromiumDownload{}
|
||||||
|
case item.ChromiumCreditCard:
|
||||||
|
b.sources[source] = &ChromiumCreditCard{}
|
||||||
|
case item.FirefoxPassword:
|
||||||
|
b.sources[source] = &FirefoxPassword{}
|
||||||
|
case item.FirefoxCookie:
|
||||||
|
b.sources[source] = &FirefoxCookie{}
|
||||||
|
case item.FirefoxBookmark:
|
||||||
|
b.sources[source] = &FirefoxBookmark{}
|
||||||
|
case item.FirefoxHistory:
|
||||||
|
b.sources[source] = &FirefoxHistory{}
|
||||||
|
case item.FirefoxDownload:
|
||||||
|
b.sources[source] = &FirefoxDownload{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards`
|
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards`
|
||||||
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||||||
@@ -34,13 +77,6 @@ type (
|
|||||||
LoginUrl string
|
LoginUrl string
|
||||||
CreateDate time.Time
|
CreateDate time.Time
|
||||||
}
|
}
|
||||||
bookmark struct {
|
|
||||||
ID int64
|
|
||||||
Name string
|
|
||||||
Type string
|
|
||||||
URL string
|
|
||||||
DateAdded time.Time
|
|
||||||
}
|
|
||||||
cookie struct {
|
cookie struct {
|
||||||
Host string
|
Host string
|
||||||
Path string
|
Path string
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package data
|
package browingdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
+13
-22
@@ -4,7 +4,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"hack-browser-data/internal/data"
|
"hack-browser-data/internal/browingdata"
|
||||||
|
"hack-browser-data/internal/browser/chromium"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Browser interface {
|
type Browser interface {
|
||||||
@@ -12,13 +13,13 @@ type Browser interface {
|
|||||||
|
|
||||||
GetMasterKey() ([]byte, error)
|
GetMasterKey() ([]byte, error)
|
||||||
|
|
||||||
GetBrowsingData() []data.BrowsingData
|
GetBrowsingData() []browingdata.Source
|
||||||
|
|
||||||
CopyItemFileToLocal() error
|
CopyItemFileToLocal() error
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// home dir path not for android and ios
|
// home dir path for all platforms
|
||||||
homeDir, _ = os.UserHomeDir()
|
homeDir, _ = os.UserHomeDir()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,8 +44,8 @@ func pickChromium(name string) []Browser {
|
|||||||
var browsers []Browser
|
var browsers []Browser
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
if name == "all" {
|
if name == "all" {
|
||||||
for _, choice := range chromiumList {
|
for _, c := range chromiumList {
|
||||||
if b, err := newChromium(choice.browserInfo, choice.items); err == nil {
|
if b, err := chromium.New(c.name, c.profilePath, c.storage, c.items); err == nil {
|
||||||
browsers = append(browsers, b)
|
browsers = append(browsers, b)
|
||||||
} else {
|
} else {
|
||||||
if strings.Contains(err.Error(), "profile path is not exist") {
|
if strings.Contains(err.Error(), "profile path is not exist") {
|
||||||
@@ -95,30 +96,20 @@ func ListBrowser() []string {
|
|||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func isFileExist(path string) bool {
|
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
type browserInfo struct {
|
type browserInfo struct {
|
||||||
name string
|
masterKey []byte
|
||||||
storage string
|
|
||||||
profilePath string
|
|
||||||
masterKey []byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
chromeName = "Chrome"
|
chromeName = "Chrome"
|
||||||
chromeBetaName = "Chrome Beta"
|
chromeBetaName = "Chrome Beta"
|
||||||
chromiumName = "Chromium"
|
chromiumName = "ChromiumBookmark"
|
||||||
edgeName = "Microsoft Edge"
|
edgeName = "Microsoft Edge"
|
||||||
firefoxName = "Firefox"
|
firefoxName = "FirefoxBookmark"
|
||||||
firefoxBetaName = "Firefox Beta"
|
firefoxBetaName = "FirefoxBookmark Beta"
|
||||||
firefoxDevName = "Firefox Dev"
|
firefoxDevName = "FirefoxBookmark Dev"
|
||||||
firefoxNightlyName = "Firefox Nightly"
|
firefoxNightlyName = "FirefoxBookmark Nightly"
|
||||||
firefoxESRName = "Firefox ESR"
|
firefoxESRName = "FirefoxBookmark ESR"
|
||||||
speed360Name = "360speed"
|
speed360Name = "360speed"
|
||||||
qqBrowserName = "QQ"
|
qqBrowserName = "QQ"
|
||||||
braveName = "Brave"
|
braveName = "Brave"
|
||||||
|
|||||||
@@ -1,121 +1,104 @@
|
|||||||
package browser
|
package browser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"crypto/sha1"
|
|
||||||
"errors"
|
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/pbkdf2"
|
|
||||||
|
|
||||||
"hack-browser-data/internal/item"
|
"hack-browser-data/internal/item"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chromiumList = map[string]struct {
|
chromiumList = map[string]struct {
|
||||||
browserInfo *browserInfo
|
name string
|
||||||
|
storage string
|
||||||
|
profilePath string
|
||||||
items []item.Item
|
items []item.Item
|
||||||
}{
|
}{
|
||||||
"chrome": {
|
"chrome": {
|
||||||
browserInfo: chromeInfo,
|
name: chromeName,
|
||||||
|
storage: chromeStorageName,
|
||||||
|
profilePath: chromeProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"edge": {
|
"edge": {
|
||||||
browserInfo: edgeInfo,
|
name: edgeName,
|
||||||
|
storage: edgeStorageName,
|
||||||
|
profilePath: edgeProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"chromium": {
|
"chromium": {
|
||||||
browserInfo: chromiumInfo,
|
name: chromiumName,
|
||||||
|
storage: chromiumStorageName,
|
||||||
|
profilePath: chromiumProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"chrome-beta": {
|
"chrome-beta": {
|
||||||
browserInfo: chromeBetaInfo,
|
name: chromeBetaName,
|
||||||
|
storage: chromeBetaStorageName,
|
||||||
|
profilePath: chromeBetaProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"opera": {
|
"opera": {
|
||||||
browserInfo: operaInfo,
|
name: operaName,
|
||||||
|
profilePath: operaProfilePath,
|
||||||
|
storage: operaStorageName,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"opera-gx": {
|
"opera-gx": {
|
||||||
browserInfo: operaGXInfo,
|
name: operaGXName,
|
||||||
|
profilePath: operaGXProfilePath,
|
||||||
|
storage: operaStorageName,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"vivaldi": {
|
"vivaldi": {
|
||||||
browserInfo: vivaldiInfo,
|
name: vivaldiName,
|
||||||
|
storage: vivaldiStorageName,
|
||||||
|
profilePath: vivaldiProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"coccoc": {
|
"coccoc": {
|
||||||
browserInfo: coccocInfo,
|
name: coccocName,
|
||||||
|
storage: coccocStorageName,
|
||||||
|
profilePath: coccocProfilePath,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"brave": {
|
"brave": {
|
||||||
browserInfo: braveInfo,
|
name: braveName,
|
||||||
|
profilePath: braveProfilePath,
|
||||||
|
storage: braveStorageName,
|
||||||
items: item.DefaultChromium,
|
items: item.DefaultChromium,
|
||||||
},
|
},
|
||||||
"yandex": {
|
"yandex": {
|
||||||
browserInfo: yandexInfo,
|
name: yandexName,
|
||||||
|
storage: yandexStorageName,
|
||||||
|
profilePath: yandexProfilePath,
|
||||||
items: item.DefaultYandex,
|
items: item.DefaultYandex,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
firefoxList = map[string]struct {
|
firefoxList = map[string]struct {
|
||||||
browserInfo *browserInfo
|
name string
|
||||||
|
storage string
|
||||||
|
profilePath string
|
||||||
items []item.Item
|
items []item.Item
|
||||||
}{
|
}{
|
||||||
"firefox": {
|
"firefox": {
|
||||||
browserInfo: firefoxInfo,
|
name: firefoxName,
|
||||||
items: defaultFirefoxItems,
|
profilePath: firefoxProfilePath,
|
||||||
|
items: item.DefaultFirefox,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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) {
|
firefoxProfilePath = homeDir + "/Library/Application Support/Firefox/Profiles/"
|
||||||
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/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -129,60 +112,3 @@ const (
|
|||||||
coccocStorageName = "CocCoc"
|
coccocStorageName = "CocCoc"
|
||||||
yandexStorageName = "Yandex"
|
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
|
package browser
|
||||||
|
|
||||||
import (
|
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"
|
item2 "hack-browser-data/internal/item"
|
||||||
"hack-browser-data/internal/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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 (
|
var (
|
||||||
chromeInfo = &browserInfo{
|
chromeInfo = &browserInfo{
|
||||||
name: chromeName,
|
name: chromeName,
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"hack-browser-data/internal/data"
|
"hack-browser-data/internal/browingdata"
|
||||||
"hack-browser-data/internal/item"
|
"hack-browser-data/internal/item"
|
||||||
|
"hack-browser-data/internal/utils/fileutil"
|
||||||
|
"hack-browser-data/internal/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type chromium struct {
|
type chromium struct {
|
||||||
@@ -21,24 +22,26 @@ type chromium struct {
|
|||||||
itemPaths map[item.Item]string
|
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) {
|
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{
|
c := &chromium{
|
||||||
name: name,
|
name: name,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
profilePath: profilePath,
|
profilePath: profilePath,
|
||||||
items: items,
|
items: typeutil.Keys(itemsPaths),
|
||||||
|
itemPaths: itemsPaths,
|
||||||
}
|
}
|
||||||
absProfilePath := path.Join(homeDir, filepath.Clean(c.ProfilePath))
|
// new browsing data
|
||||||
// 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
|
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,8 +49,9 @@ func (c *chromium) GetName() string {
|
|||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *chromium) GetBrowsingData() []data.BrowsingData {
|
func (c *chromium) GetBrowsingData() []browingdata.Source {
|
||||||
var browsingData []data.BrowsingData
|
var browsingData []browingdata.Source
|
||||||
|
data := browingdata.New(c.items)
|
||||||
for item := range c.itemPaths {
|
for item := range c.itemPaths {
|
||||||
d := item.NewBrowsingData()
|
d := item.NewBrowsingData()
|
||||||
if d != nil {
|
if d != nil {
|
||||||
@@ -95,9 +99,10 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat
|
|||||||
for _, it := range items {
|
for _, it := range items {
|
||||||
switch {
|
switch {
|
||||||
case it.FileName() == info.Name():
|
case it.FileName() == info.Name():
|
||||||
if it == it.chromiumKey {
|
if it == item.ChromiumKey {
|
||||||
itemPaths[it] = path
|
itemPaths[it] = path
|
||||||
}
|
}
|
||||||
|
// TODO: Handle file path is not in Default folder
|
||||||
if strings.Contains(path, "Default") {
|
if strings.Contains(path, "Default") {
|
||||||
itemPaths[it] = path
|
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"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"hack-browser-data/internal/data"
|
"hack-browser-data/internal/browingdata"
|
||||||
"hack-browser-data/internal/item"
|
"hack-browser-data/internal/item"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,8 +117,8 @@ func (f *firefox) GetName() string {
|
|||||||
return f.name
|
return f.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *firefox) GetBrowsingData() []data.BrowsingData {
|
func (f *firefox) GetBrowsingData() []browingdata.Source {
|
||||||
var browsingData []data.BrowsingData
|
var browsingData []browingdata.Source
|
||||||
for item := range f.itemPaths {
|
for item := range f.itemPaths {
|
||||||
d := item.NewBrowsingData()
|
d := item.NewBrowsingData()
|
||||||
if d != nil {
|
if d != nil {
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import (
|
|||||||
var (
|
var (
|
||||||
errSecurityKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal")
|
errSecurityKeyIsEmpty = errors.New("input [security find-generic-password -wa 'Chrome'] in terminal")
|
||||||
errPasswordIsEmpty = errors.New("password is empty")
|
errPasswordIsEmpty = errors.New("password is empty")
|
||||||
errDecryptFailed = errors.New("decrypter encrypt value failed")
|
errDecryptFailed = errors.New("decrypt encrypted value failed")
|
||||||
errDecodeASN1Failed = errors.New("decode ASN1 data failed")
|
errDecodeASN1Failed = errors.New("decode ASN1 browingdata failed")
|
||||||
errEncryptedLength = errors.New("length of encrypted password less than block size")
|
errEncryptedLength = errors.New("length of encrypted password less than block size")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package item
|
package item
|
||||||
|
|
||||||
import (
|
import (
|
||||||
data2 "hack-browser-data/internal/data"
|
data2 "hack-browser-data/internal/browingdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultFirefox = []Item{
|
var DefaultFirefox = []Item{
|
||||||
@@ -161,7 +161,9 @@ func (i Item) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Item) NewBrowsingData() data2.BrowsingData {
|
// NewBrowsingData returns a new Source instance.
|
||||||
|
// TODO: remove this function
|
||||||
|
func (i Item) NewBrowsingData() data2.Source {
|
||||||
switch i {
|
switch i {
|
||||||
case ChromiumKey:
|
case ChromiumKey:
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/gocarina/gocsv"
|
"github.com/gocarina/gocsv"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
|
||||||
"hack-browser-data/internal/data"
|
"hack-browser-data/internal/browingdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
type outPutter struct {
|
type outPutter struct {
|
||||||
@@ -35,7 +35,7 @@ func (o *outPutter) MakeDir(dir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *outPutter) Write(data data.BrowsingData, writer *os.File) error {
|
func (o *outPutter) Write(data browingdata.Source, writer *os.File) error {
|
||||||
switch o.json {
|
switch o.json {
|
||||||
case true:
|
case true:
|
||||||
encoder := jsoniter.NewEncoder(writer)
|
encoder := jsoniter.NewEncoder(writer)
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package fileutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileExists checks if the file exists in the provided path
|
||||||
|
func FileExists(filename string) bool {
|
||||||
|
info, err := os.Stat(filename)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return !info.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FolderExists checks if the folder exists
|
||||||
|
func FolderExists(foldername string) bool {
|
||||||
|
info, err := os.Stat(foldername)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return info.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadFile reads the file from the provided path
|
||||||
|
func ReadFile(filename string) (string, error) {
|
||||||
|
s, err := ioutil.ReadFile(filename)
|
||||||
|
return string(s), err
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package typeutil
|
||||||
|
|
||||||
|
// Keys returns a slice of the keys of the map. based with go 1.18 generics
|
||||||
|
func Keys[K comparable, V any](m map[K]V) []K {
|
||||||
|
r := make([]K, 0, len(m))
|
||||||
|
for k := range m {
|
||||||
|
r = append(r, k)
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
@@ -53,11 +53,6 @@ func TimeEpochFormat(epoch int64) time.Time {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadFile(filename string) (string, error) {
|
|
||||||
s, err := ioutil.ReadFile(filename)
|
|
||||||
return string(s), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteFile(filename string, data []byte) error {
|
func WriteFile(filename string, data []byte) error {
|
||||||
err := ioutil.WriteFile(filename, data, 0644)
|
err := ioutil.WriteFile(filename, data, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user