Merge pull request #199 from moonD4rk/feat/layout

feat/layout: format project layout
pull/202/head
ᴍᴏᴏɴD4ʀᴋ 2 years ago committed by GitHub
commit 1214bf8342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 4
      .golangci.yml
  3. 10
      browingdata/bookmark/bookmark.go
  4. 22
      browingdata/browsingdata.go
  5. 14
      browingdata/cookie/cookie.go
  6. 16
      browingdata/creditcard/creditcard.go
  7. 8
      browingdata/download/download.go
  8. 8
      browingdata/extension/extension.go
  9. 8
      browingdata/history/history.go
  10. 8
      browingdata/localstorage/localstorage.go
  11. 0
      browingdata/outputter.go
  12. 0
      browingdata/outputter_test.go
  13. 26
      browingdata/password/password.go
  14. 57
      browser/browser.go
  15. 4
      browser/browser_darwin.go
  16. 4
      browser/browser_linux.go
  17. 20
      browser/browser_windows.go
  18. 29
      browser/chromium/chromium.go
  19. 6
      browser/chromium/chromium_darwin.go
  20. 6
      browser/chromium/chromium_linux.go
  21. 11
      browser/chromium/chromium_windows.go
  22. 26
      browser/consts.go
  23. 33
      browser/firefox/firefox.go
  24. 15
      cmd/hack-browser-data/main.go
  25. 2
      crypto/crypto.go
  26. 2
      crypto/crypto_darwin.go
  27. 2
      crypto/crypto_linux.go
  28. 2
      crypto/crypto_windows.go
  29. 2
      go.mod
  30. 12
      internal/browser/browser.go
  31. 0
      item/filename.go
  32. 0
      item/item.go
  33. 0
      log/log.go
  34. 0
      utils/fileutil/filetutil.go
  35. 0
      utils/typeutil/typeutil.go
  36. 0
      utils/typeutil/typeutil_test.go

3
.gitignore vendored

@ -191,3 +191,6 @@ results/
hack-browser-data hack-browser-data
!/cmd/hack-browser-data !/cmd/hack-browser-data
!/browingdata/history
!/browingdata/history/history.go
!/browingdata/history/history_test.go

@ -30,7 +30,7 @@ linters:
- 'unconvert' - 'unconvert'
- 'whitespace' - 'whitespace'
disable: disable:
# unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649 # unsupported lint with golang 1.18+ ref: https://github.com/golangci/golangci-lint/issues/2649
- 'bodyclose' - 'bodyclose'
- 'gosimple' - 'gosimple'
- 'noctx' - 'noctx'
@ -60,7 +60,7 @@ issues:
- G502 - G502
- G505 - G505
exclude-rules: exclude-rules:
- path: internal/provider/provider\.go - path: browser/browser\.go
linters: linters:
- 'unused' - 'unused'
max-issues-per-linter: 0 max-issues-per-linter: 0

@ -6,14 +6,14 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/fileutil"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumBookmark []bookmark type ChromiumBookmark []bookmark

@ -3,17 +3,17 @@ package browingdata
import ( import (
"path" "path"
"hack-browser-data/internal/browingdata/bookmark" "github.com/moond4rk/HackBrowserData/browingdata/bookmark"
"hack-browser-data/internal/browingdata/cookie" "github.com/moond4rk/HackBrowserData/browingdata/cookie"
"hack-browser-data/internal/browingdata/creditcard" "github.com/moond4rk/HackBrowserData/browingdata/creditcard"
"hack-browser-data/internal/browingdata/download" "github.com/moond4rk/HackBrowserData/browingdata/download"
"hack-browser-data/internal/browingdata/extension" "github.com/moond4rk/HackBrowserData/browingdata/extension"
"hack-browser-data/internal/browingdata/history" "github.com/moond4rk/HackBrowserData/browingdata/history"
"hack-browser-data/internal/browingdata/localstorage" "github.com/moond4rk/HackBrowserData/browingdata/localstorage"
"hack-browser-data/internal/browingdata/password" "github.com/moond4rk/HackBrowserData/browingdata/password"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/log" "github.com/moond4rk/HackBrowserData/log"
"hack-browser-data/internal/utils/fileutil" "github.com/moond4rk/HackBrowserData/utils/fileutil"
) )
type Data struct { type Data struct {

@ -6,13 +6,13 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/moond4rk/HackBrowserData/crypto"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumCookie []cookie type ChromiumCookie []cookie
@ -73,9 +73,9 @@ func (c *ChromiumCookie) Parse(masterKey []byte) error {
if len(encryptValue) > 0 { if len(encryptValue) > 0 {
var err error var err error
if masterKey == nil { if masterKey == nil {
value, err = decrypter.DPAPI(encryptValue) value, err = crypto.DPAPI(encryptValue)
} else { } else {
value, err = decrypter.Chromium(masterKey, encryptValue) value, err = crypto.Chromium(masterKey, encryptValue)
} }
if err != nil { if err != nil {
log.Error(err) log.Error(err)

@ -4,12 +4,12 @@ import (
"database/sql" "database/sql"
"os" "os"
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/moond4rk/HackBrowserData/crypto"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
) )
type ChromiumCreditCard []card type ChromiumCreditCard []card
@ -57,12 +57,12 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
NickName: nickname, NickName: nickname,
} }
if masterKey == nil { if masterKey == nil {
value, err = decrypter.DPAPI(encryptValue) value, err = crypto.DPAPI(encryptValue)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
value, err = decrypter.Chromium(masterKey, encryptValue) value, err = crypto.Chromium(masterKey, encryptValue)
if err != nil { if err != nil {
return err return err
} }
@ -113,12 +113,12 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
NickName: nickname, NickName: nickname,
} }
if masterKey == nil { if masterKey == nil {
value, err = decrypter.DPAPI(encryptValue) value, err = crypto.DPAPI(encryptValue)
if err != nil { if err != nil {
return err return err
} }
} else { } else {
value, err = decrypter.Chromium(masterKey, encryptValue) value, err = crypto.Chromium(masterKey, encryptValue)
if err != nil { if err != nil {
return err return err
} }

@ -7,13 +7,13 @@ import (
"strings" "strings"
"time" "time"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumDownload []download type ChromiumDownload []download

@ -3,11 +3,11 @@ package extension
import ( import (
"os" "os"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/fileutil"
) )
type ChromiumExtension []*extension type ChromiumExtension []*extension

@ -6,12 +6,12 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumHistory []history type ChromiumHistory []history

@ -7,11 +7,11 @@ import (
"os" "os"
"strings" "strings"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumLocalStorage []storage type ChromiumLocalStorage []storage

@ -8,14 +8,14 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/utils/typeutil"
// import sqlite3 driver // import sqlite3 driver
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/moond4rk/HackBrowserData/crypto"
"github.com/moond4rk/HackBrowserData/item"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
type ChromiumPassword []loginData type ChromiumPassword []loginData
@ -63,9 +63,9 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error {
if len(pwd) > 0 { if len(pwd) > 0 {
var err error var err error
if masterKey == nil { if masterKey == nil {
password, err = decrypter.DPAPI(pwd) password, err = crypto.DPAPI(pwd)
} else { } else {
password, err = decrypter.Chromium(masterKey, pwd) password, err = crypto.Chromium(masterKey, pwd)
} }
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -131,9 +131,9 @@ func (c *YandexPassword) Parse(masterKey []byte) error {
if len(pwd) > 0 { if len(pwd) > 0 {
var err error var err error
if masterKey == nil { if masterKey == nil {
password, err = decrypter.DPAPI(pwd) password, err = crypto.DPAPI(pwd)
} else { } else {
password, err = decrypter.Chromium(masterKey, pwd) password, err = crypto.Chromium(masterKey, pwd)
} }
if err != nil { if err != nil {
log.Errorf("decrypt yandex password error %s", err) log.Errorf("decrypt yandex password error %s", err)
@ -174,7 +174,7 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
if err != nil { if err != nil {
return err return err
} }
metaPBE, err := decrypter.NewASN1PBE(metaBytes) metaPBE, err := crypto.NewASN1PBE(metaBytes)
if err != nil { if err != nil {
return err return err
} }
@ -187,7 +187,7 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
if bytes.Contains(k, []byte("password-check")) { if bytes.Contains(k, []byte("password-check")) {
m := bytes.Compare(nssA102, keyLin) m := bytes.Compare(nssA102, keyLin)
if m == 0 { if m == 0 {
nssPBE, err := decrypter.NewASN1PBE(nssA11) nssPBE, err := crypto.NewASN1PBE(nssA11)
if err != nil { if err != nil {
return err return err
} }
@ -201,11 +201,11 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
return err return err
} }
for _, v := range allLogin { for _, v := range allLogin {
userPBE, err := decrypter.NewASN1PBE(v.encryptUser) userPBE, err := crypto.NewASN1PBE(v.encryptUser)
if err != nil { if err != nil {
return err return err
} }
pwdPBE, err := decrypter.NewASN1PBE(v.encryptPass) pwdPBE, err := crypto.NewASN1PBE(v.encryptPass)
if err != nil { if err != nil {
return err return err
} }

@ -1,21 +1,27 @@
package provider package browser
import ( import (
"os"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"hack-browser-data/internal/browser" "github.com/moond4rk/HackBrowserData/browingdata"
"hack-browser-data/internal/log" "github.com/moond4rk/HackBrowserData/browser/chromium"
"hack-browser-data/internal/provider/chromium" "github.com/moond4rk/HackBrowserData/browser/firefox"
"hack-browser-data/internal/provider/firefox" "github.com/moond4rk/HackBrowserData/log"
"hack-browser-data/internal/utils/fileutil" "github.com/moond4rk/HackBrowserData/utils/fileutil"
"hack-browser-data/internal/utils/typeutil" "github.com/moond4rk/HackBrowserData/utils/typeutil"
) )
func PickBrowsers(name, profile string) ([]browser.Browser, error) { type Browser interface {
var browsers []browser.Browser // Name is browser's name
Name() string
// BrowsingData returns all browsing data in the browser.
BrowsingData() (*browingdata.Data, error)
}
func PickBrowsers(name, profile string) ([]Browser, error) {
var browsers []Browser
clist := pickChromium(name, profile) clist := pickChromium(name, profile)
for _, b := range clist { for _, b := range clist {
if b != nil { if b != nil {
@ -31,8 +37,8 @@ func PickBrowsers(name, profile string) ([]browser.Browser, error) {
return browsers, nil return browsers, nil
} }
func pickChromium(name, profile string) []browser.Browser { func pickChromium(name, profile string) []Browser {
var browsers []browser.Browser var browsers []Browser
name = strings.ToLower(name) name = strings.ToLower(name)
if name == "all" { if name == "all" {
for _, v := range chromiumList { for _, v := range chromiumList {
@ -70,8 +76,8 @@ func pickChromium(name, profile string) []browser.Browser {
return browsers return browsers
} }
func pickFirefox(name, profile string) []browser.Browser { func pickFirefox(name, profile string) []Browser {
var browsers []browser.Browser var browsers []Browser
name = strings.ToLower(name) name = strings.ToLower(name)
if name == "all" || name == "firefox" { if name == "all" || name == "firefox" {
for _, v := range firefoxList { for _, v := range firefoxList {
@ -106,23 +112,6 @@ func ListBrowsers() []string {
return l return l
} }
// home dir path for all platforms func Names() string {
var homeDir, _ = os.UserHomeDir() return strings.Join(ListBrowsers(), "|")
}
const (
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "Chromium"
edgeName = "Microsoft Edge"
braveName = "Brave"
operaName = "Opera"
operaGXName = "OperaGX"
vivaldiName = "Vivaldi"
coccocName = "CocCoc"
yandexName = "Yandex"
firefoxName = "Firefox"
speed360Name = "360speed"
qqBrowserName = "QQ"
dcbrowserName = "dcbrowser"
sougouName = "Sougou"
)

@ -1,9 +1,9 @@
//go:build darwin //go:build darwin
package provider package browser
import ( import (
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
) )
var ( var (

@ -1,9 +1,9 @@
//go:build linux //go:build linux
package provider package browser
import ( import (
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
) )
var ( var (

@ -1,9 +1,9 @@
//go:build windows //go:build windows
package provider package browser
import ( import (
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
) )
var ( var (
@ -73,14 +73,14 @@ var (
profilePath: qqBrowserProfilePath, profilePath: qqBrowserProfilePath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
"dcbrowser": { "dc": {
name: dcbrowserName, name: dcBrowserName,
profilePath: dcbrowserUserDataPath, profilePath: dcBrowserProfilePath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
"sougou": { "sogou": {
name: sougouName, name: sogouName,
profilePath: dcbrowserUserDataPath, profilePath: sogouProfilePath,
items: item.DefaultChromium, items: item.DefaultChromium,
}, },
} }
@ -111,8 +111,8 @@ var (
vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/Default/" vivaldiProfilePath = homeDir + "/AppData/Local/Vivaldi/User Data/Default/"
coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/Default/" coccocProfilePath = homeDir + "/AppData/Local/CocCoc/Browser/User Data/Default/"
yandexProfilePath = homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data/Default/" yandexProfilePath = homeDir + "/AppData/Local/Yandex/YandexBrowser/User Data/Default/"
dcbrowserUserDataPath = homeDir + "/AppData/Local/DCBrowser/User Data/Default/" dcBrowserProfilePath = homeDir + "/AppData/Local/DCBrowser/User Data/Default/"
sougouUserDataPath = homeDir + "/AppData/Roaming/SogouExplorer/Webkit/Default/" sogouProfilePath = homeDir + "/AppData/Roaming/SogouExplorer/Webkit/Default/"
firefoxProfilePath = homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles/" firefoxProfilePath = homeDir + "/AppData/Roaming/Mozilla/Firefox/Profiles/"
) )

@ -5,14 +5,13 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"hack-browser-data/internal/browingdata" "github.com/moond4rk/HackBrowserData/browingdata"
"hack-browser-data/internal/browser" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/utils/fileutil"
"hack-browser-data/internal/utils/fileutil" "github.com/moond4rk/HackBrowserData/utils/typeutil"
"hack-browser-data/internal/utils/typeutil"
) )
type chromium struct { type Chromium struct {
name string name string
storage string storage string
profilePath string profilePath string
@ -21,9 +20,9 @@ type chromium struct {
itemPaths map[item.Item]string itemPaths map[item.Item]string
} }
// New create instance of chromium browser, fill item's path if item is existed. // New create instance of Chromium browser, fill item's path if item is existed.
func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { func New(name, storage, profilePath string, items []item.Item) ([]*Chromium, error) {
c := &chromium{ c := &Chromium{
name: name, name: name,
storage: storage, storage: storage,
profilePath: profilePath, profilePath: profilePath,
@ -33,9 +32,9 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse
if err != nil { if err != nil {
return nil, err return nil, err
} }
chromiumList := make([]browser.Browser, 0, len(multiItemPaths)) chromiumList := make([]*Chromium, 0, len(multiItemPaths))
for user, itemPaths := range multiItemPaths { for user, itemPaths := range multiItemPaths {
chromiumList = append(chromiumList, &chromium{ chromiumList = append(chromiumList, &Chromium{
name: fileutil.BrowserName(name, user), name: fileutil.BrowserName(name, user),
items: typeutil.Keys(itemPaths), items: typeutil.Keys(itemPaths),
itemPaths: itemPaths, itemPaths: itemPaths,
@ -45,11 +44,11 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse
return chromiumList, nil return chromiumList, nil
} }
func (c *chromium) Name() string { func (c *Chromium) Name() string {
return c.name return c.name
} }
func (c *chromium) BrowsingData() (*browingdata.Data, error) { func (c *Chromium) BrowsingData() (*browingdata.Data, error) {
b := browingdata.New(c.items) b := browingdata.New(c.items)
if err := c.copyItemToLocal(); err != nil { if err := c.copyItemToLocal(); err != nil {
@ -68,7 +67,7 @@ func (c *chromium) BrowsingData() (*browingdata.Data, error) {
return b, nil return b, nil
} }
func (c *chromium) copyItemToLocal() error { func (c *Chromium) copyItemToLocal() error {
for i, path := range c.itemPaths { for i, path := range c.itemPaths {
filename := i.String() filename := i.String()
var err error var err error
@ -90,7 +89,7 @@ func (c *chromium) copyItemToLocal() error {
return nil return nil
} }
func (c *chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { func (c *Chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
// multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair] // multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair]
multiItemPaths := make(map[string]map[item.Item]string) multiItemPaths := make(map[string]map[item.Item]string)
parentDir := fileutil.ParentDir(profilePath) parentDir := fileutil.ParentDir(profilePath)

@ -12,8 +12,8 @@ import (
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/log" "github.com/moond4rk/HackBrowserData/log"
) )
var ( var (
@ -21,7 +21,7 @@ var (
errCouldNotFindInKeychain = errors.New("could not be find in keychain") errCouldNotFindInKeychain = errors.New("could not be find in keychain")
) )
func (c *chromium) GetMasterKey() ([]byte, error) { func (c *Chromium) GetMasterKey() ([]byte, error) {
var ( var (
cmd *exec.Cmd cmd *exec.Cmd
stdout, stderr bytes.Buffer stdout, stderr bytes.Buffer

@ -11,11 +11,11 @@ import (
keyring "github.com/ppacher/go-dbus-keyring" keyring "github.com/ppacher/go-dbus-keyring"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/log" "github.com/moond4rk/HackBrowserData/log"
) )
func (c *chromium) GetMasterKey() ([]byte, error) { func (c *Chromium) GetMasterKey() ([]byte, error) {
// what is d-bus @https://dbus.freedesktop.org/ // what is d-bus @https://dbus.freedesktop.org/
var chromiumSecret []byte var chromiumSecret []byte
conn, err := dbus.SessionBus() conn, err := dbus.SessionBus()

@ -9,15 +9,14 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/internal/decrypter" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/log"
"hack-browser-data/internal/log" "github.com/moond4rk/HackBrowserData/utils/fileutil"
"hack-browser-data/internal/utils/fileutil"
) )
var errDecodeMasterKeyFailed = errors.New("decode master key failed") var errDecodeMasterKeyFailed = errors.New("decode master key failed")
func (c *chromium) GetMasterKey() ([]byte, error) { func (c *Chromium) GetMasterKey() ([]byte, error) {
keyFile, err := fileutil.ReadFile(item.TempChromiumKey) keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
if err != nil { if err != nil {
return nil, err return nil, err
@ -31,7 +30,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
if err != nil { if err != nil {
return nil, errDecodeMasterKeyFailed return nil, errDecodeMasterKeyFailed
} }
c.masterKey, err = decrypter.DPAPI(pureKey[5:]) c.masterKey, err = crypto.DPAPI(pureKey[5:])
log.Infof("%s initialized master key success", c.name) log.Infof("%s initialized master key success", c.name)
return c.masterKey, err return c.masterKey, err
} }

@ -0,0 +1,26 @@
package browser
import (
"os"
)
// home dir path for all platforms
var homeDir, _ = os.UserHomeDir()
const (
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "Chromium"
edgeName = "Microsoft Edge"
braveName = "Brave"
operaName = "Opera"
operaGXName = "OperaGX"
vivaldiName = "Vivaldi"
coccocName = "CocCoc"
yandexName = "Yandex"
firefoxName = "Firefox"
speed360Name = "360speed"
qqBrowserName = "QQ"
dcBrowserName = "DC"
sogouName = "Sogou"
)

@ -6,14 +6,13 @@ import (
"io/fs" "io/fs"
"path/filepath" "path/filepath"
"hack-browser-data/internal/browingdata" "github.com/moond4rk/HackBrowserData/browingdata"
"hack-browser-data/internal/browser" "github.com/moond4rk/HackBrowserData/item"
"hack-browser-data/internal/item" "github.com/moond4rk/HackBrowserData/utils/fileutil"
"hack-browser-data/internal/utils/fileutil" "github.com/moond4rk/HackBrowserData/utils/typeutil"
"hack-browser-data/internal/utils/typeutil"
) )
type firefox struct { type Firefox struct {
name string name string
storage string storage string
profilePath string profilePath string
@ -24,9 +23,9 @@ type firefox struct {
var ErrProfilePathNotFound = errors.New("profile path not found") var ErrProfilePathNotFound = errors.New("profile path not found")
// New returns a new firefox instance. // New returns a new Firefox instance.
func New(name, storage, profilePath string, items []item.Item) ([]browser.Browser, error) { func New(name, storage, profilePath string, items []item.Item) ([]*Firefox, error) {
f := &firefox{ f := &Firefox{
name: name, name: name,
storage: storage, storage: storage,
profilePath: profilePath, profilePath: profilePath,
@ -37,10 +36,10 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse
return nil, err return nil, err
} }
firefoxList := make([]browser.Browser, 0, len(multiItemPaths)) firefoxList := make([]*Firefox, 0, len(multiItemPaths))
for name, itemPaths := range multiItemPaths { for name, itemPaths := range multiItemPaths {
firefoxList = append(firefoxList, &firefox{ firefoxList = append(firefoxList, &Firefox{
name: fmt.Sprintf("firefox-%s", name), name: fmt.Sprintf("Firefox-%s", name),
items: typeutil.Keys(itemPaths), items: typeutil.Keys(itemPaths),
itemPaths: itemPaths, itemPaths: itemPaths,
}) })
@ -48,13 +47,13 @@ func New(name, storage, profilePath string, items []item.Item) ([]browser.Browse
return firefoxList, nil return firefoxList, nil
} }
func (f *firefox) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { func (f *Firefox) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
multiItemPaths := make(map[string]map[item.Item]string) multiItemPaths := make(map[string]map[item.Item]string)
err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths)) err := filepath.Walk(profilePath, firefoxWalkFunc(items, multiItemPaths))
return multiItemPaths, err return multiItemPaths, err
} }
func (f *firefox) copyItemToLocal() error { func (f *Firefox) copyItemToLocal() error {
for i, path := range f.itemPaths { for i, path := range f.itemPaths {
filename := i.String() filename := i.String()
if err := fileutil.CopyFile(path, filename); err != nil { if err := fileutil.CopyFile(path, filename); err != nil {
@ -80,15 +79,15 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
} }
} }
func (f *firefox) GetMasterKey() ([]byte, error) { func (f *Firefox) GetMasterKey() ([]byte, error) {
return f.masterKey, nil return f.masterKey, nil
} }
func (f *firefox) Name() string { func (f *Firefox) Name() string {
return f.name return f.name
} }
func (f *firefox) BrowsingData() (*browingdata.Data, error) { func (f *Firefox) BrowsingData() (*browingdata.Data, error) {
b := browingdata.New(f.items) b := browingdata.New(f.items)
if err := f.copyItemToLocal(); err != nil { if err := f.copyItemToLocal(); err != nil {

@ -2,13 +2,12 @@ package main
import ( import (
"os" "os"
"strings"
"hack-browser-data/internal/log"
"hack-browser-data/internal/provider"
"hack-browser-data/internal/utils/fileutil"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.com/moond4rk/HackBrowserData/browser"
"github.com/moond4rk/HackBrowserData/log"
"github.com/moond4rk/HackBrowserData/utils/fileutil"
) )
var ( var (
@ -29,11 +28,11 @@ func Execute() {
Name: "hack-browser-data", Name: "hack-browser-data",
Usage: "Export password|bookmark|cookie|history|credit card|download|localStorage|extension from browser", Usage: "Export password|bookmark|cookie|history|credit card|download|localStorage|extension from browser",
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData", UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData",
Version: "0.4.4", Version: "0.5.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{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"}, &cli.BoolFlag{Name: "compress", Aliases: []string{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(provider.ListBrowsers(), "|")}, &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + browser.Names()},
&cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &outputDir, Value: "results", Usage: "export dir"}, &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &outputDir, Value: "results", Usage: "export dir"},
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "file name csv|json"}, &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "file name csv|json"},
&cli.StringFlag{Name: "profile-path", Aliases: []string{"p"}, Destination: &profilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"}, &cli.StringFlag{Name: "profile-path", Aliases: []string{"p"}, Destination: &profilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"},
@ -46,7 +45,7 @@ func Execute() {
log.Init("notice") log.Init("notice")
} }
browsers, err := provider.PickBrowsers(browserName, profilePath) browsers, err := browser.PickBrowsers(browserName, profilePath)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }

@ -1,4 +1,4 @@
package decrypter package crypto
import ( import (
"crypto/aes" "crypto/aes"

@ -1,6 +1,6 @@
//go:build darwin //go:build darwin
package decrypter package crypto
func Chromium(key, encryptPass []byte) ([]byte, error) { func Chromium(key, encryptPass []byte) ([]byte, error) {
if len(encryptPass) <= 3 { if len(encryptPass) <= 3 {

@ -1,6 +1,6 @@
//go:build linux //go:build linux
package decrypter package crypto
func Chromium(key, encryptPass []byte) ([]byte, error) { func Chromium(key, encryptPass []byte) ([]byte, error) {
if len(encryptPass) < 3 { if len(encryptPass) < 3 {

@ -1,6 +1,6 @@
//go:build windows //go:build windows
package decrypter package crypto
import ( import (
"crypto/aes" "crypto/aes"

@ -1,4 +1,4 @@
module hack-browser-data module github.com/moond4rk/HackBrowserData
go 1.19 go 1.19

@ -1,12 +0,0 @@
package browser
import (
"hack-browser-data/internal/browingdata"
)
type Browser interface {
// Name is browser's name
Name() string
// BrowsingData returns all browsing data in the browser.
BrowsingData() (*browingdata.Data, error)
}
Loading…
Cancel
Save