refactor: format project layout

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 4d444891ab
commit f8b1de4666
  1. 12
      cmd/cmd.go
  2. 2
      core/browser.go
  3. 2
      core/browser_linux.go
  4. 2
      core/browser_windows.go
  5. 4
      core/data/output.go
  6. 4
      core/data/parse.go
  7. 66
      internal/browser/browser.go
  8. 114
      internal/browser/browser_darwin.go
  9. 0
      internal/browser/browser_linux.go
  10. 14
      internal/browser/browser_test.go
  11. 6
      internal/browser/browser_windows.go
  12. 0
      internal/browser/consts/filename.go
  13. 0
      internal/browser/consts/sql.go
  14. 4
      internal/browser/data/bookmark.go
  15. 0
      internal/browser/data/browsingdata.go
  16. 6
      internal/browser/data/cookie.go
  17. 6
      internal/browser/data/creditcard.go
  18. 4
      internal/browser/data/download.go
  19. 4
      internal/browser/data/history.go
  20. 22
      internal/browser/data/password.go
  21. 32
      internal/browser/item.go
  22. 2
      internal/browser/outputter/outputter.go
  23. 0
      internal/decrypter/decrypter.go
  24. 0
      internal/decrypter/decrypter_darwin.go
  25. 0
      internal/decrypter/decrypter_linux.go
  26. 0
      internal/decrypter/decrypter_windows.go
  27. 0
      internal/log/log.go
  28. 2
      internal/utils/utils.go

@ -5,11 +5,11 @@ import (
"os" "os"
"strings" "strings"
"hack-browser-data/pkg/browser"
"hack-browser-data/pkg/browser/outputter"
"hack-browser-data/pkg/log"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"hack-browser-data/internal/browser"
"hack-browser-data/internal/browser/outputter"
"hack-browser-data/internal/log"
) )
var ( var (
@ -26,7 +26,7 @@ func Execute() {
Name: "hack-browser-data", Name: "hack-browser-data",
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-data -b chrome -f json -dir results -cc]\n Get all data(password/cookie/history/bookmark) from chrome",
Version: "0.3.7", Version: "0.3.8",
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"},
@ -46,7 +46,7 @@ func Execute() {
} else { } else {
log.InitLog("error") log.InitLog("error")
} }
browsers = browser.PickBrowsers(browserName) browsers = browser.PickBrowser(browserName)
output := outputter.NewOutPutter(outputFormat) output := outputter.NewOutPutter(outputFormat)
if err := output.MakeDir(exportDir); err != nil { if err := output.MakeDir(exportDir); err != nil {

@ -8,7 +8,7 @@ import (
"strings" "strings"
"hack-browser-data/core/data" "hack-browser-data/core/data"
"hack-browser-data/pkg/log" "hack-browser-data/internal/log"
) )
const ( const (

@ -7,7 +7,7 @@ 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/pkg/log" "hack-browser-data/internal/log"
) )
const ( const (

@ -7,7 +7,7 @@ import (
"os" "os"
"hack-browser-data/core/decrypt" "hack-browser-data/core/decrypt"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )

@ -7,9 +7,9 @@ import (
"os" "os"
"sort" "sort"
"hack-browser-data/utils"
"github.com/jszwec/csvutil" "github.com/jszwec/csvutil"
"hack-browser-data/internal/utils"
) )
var ( var (

@ -12,8 +12,8 @@ import (
"time" "time"
"hack-browser-data/core/decrypt" "hack-browser-data/core/decrypt"
"hack-browser-data/pkg/log" "hack-browser-data/internal/log"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"

@ -9,7 +9,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"hack-browser-data/pkg/browser/data" "hack-browser-data/internal/browser/data"
) )
type Browser interface { type Browser interface {
@ -27,16 +27,16 @@ var (
homeDir, _ = os.UserHomeDir() homeDir, _ = os.UserHomeDir()
) )
func PickBrowsers(name string) []Browser { func PickBrowser(name string) []Browser {
var browsers []Browser var browsers []Browser
chromiumList := pickChromium(name) clist := pickChromium(name)
for _, b := range chromiumList { for _, b := range clist {
if b != nil { if b != nil {
browsers = append(browsers, b) browsers = append(browsers, b)
} }
} }
firefoxList := pickFirefox(name) flist := pickFirefox(name)
for _, b := range firefoxList { for _, b := range flist {
if b != nil { if b != nil {
browsers = append(browsers, b) browsers = append(browsers, b)
} }
@ -49,11 +49,14 @@ func pickChromium(name string) []Browser {
name = strings.ToLower(name) name = strings.ToLower(name)
if name == "all" { if name == "all" {
for _, choice := range chromiumList { for _, choice := range chromiumList {
b, err := newChromium(choice.browserInfo, choice.items) if b, err := newChromium(choice.browserInfo, choice.items); err == nil {
if err != nil { browsers = append(browsers, b)
} else {
if strings.Contains(err.Error(), "profile path is not exist") {
continue
}
panic(err) panic(err)
} }
browsers = append(browsers, b)
} }
return browsers return browsers
} }
@ -72,8 +75,8 @@ func pickFirefox(name string) []Browser {
var browsers []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 _, b := range firefoxList {
multiFirefox, err := newMultiFirefox(v.browserInfo, v.items) multiFirefox, err := newMultiFirefox(b.browserInfo, b.items)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -163,6 +166,10 @@ func newMultiFirefox(info *browserInfo, items []item) ([]*firefox, error) {
} }
multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items) multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "profile path is not exist") {
fmt.Println(err)
return nil, nil
}
panic(err) panic(err)
} }
var firefoxList []*firefox var firefoxList []*firefox
@ -182,6 +189,10 @@ func newMultiFirefox(info *browserInfo, items []item) ([]*firefox, error) {
func getFirefoxItemAbsPath(profilePath string, items []item) (map[string]map[item]string, error) { func getFirefoxItemAbsPath(profilePath string, items []item) (map[string]map[item]string, error) {
var multiItemPaths = make(map[string]map[item]string) var multiItemPaths = make(map[string]map[item]string)
absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) absProfilePath := path.Join(homeDir, filepath.Clean(profilePath))
// TODO: Handle read file error
if !isFileExist(absProfilePath) {
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
}
err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths)) err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths))
return multiItemPaths, err return multiItemPaths, err
} }
@ -250,6 +261,10 @@ func chromiumWalkFunc(items []item, itemPaths map[item]string) filepath.WalkFunc
func getChromiumItemAbsPath(profilePath string, items []item) (map[item]string, error) { func getChromiumItemAbsPath(profilePath string, items []item) (map[item]string, error) {
var itemPaths = make(map[item]string) var itemPaths = make(map[item]string)
absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) absProfilePath := path.Join(homeDir, filepath.Clean(profilePath))
// TODO: Handle file path is not exist
if !isFileExist(absProfilePath) {
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
}
err := filepath.Walk(absProfilePath, chromiumWalkFunc(items, itemPaths)) err := filepath.Walk(absProfilePath, chromiumWalkFunc(items, itemPaths))
return itemPaths, err return itemPaths, err
} }
@ -272,6 +287,7 @@ func (f *firefox) GetBrowsingData() []data.BrowsingData {
} }
return browsingData return browsingData
} }
func ListBrowser() []string { func ListBrowser() []string {
var l []string var l []string
for c := range chromiumList { for c := range chromiumList {
@ -283,6 +299,13 @@ 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 name string
storage string storage string
@ -291,10 +314,23 @@ type browserInfo struct {
} }
const ( const (
chromeName = "Chrome" chromeName = "Chrome"
edgeName = "Edge" chromeBetaName = "Chrome Beta"
firefoxName = "Firefox" chromiumName = "Chromium"
yandexName = "Yandex" edgeName = "Microsoft Edge"
firefoxName = "Firefox"
firefoxBetaName = "Firefox Beta"
firefoxDevName = "Firefox Dev"
firefoxNightlyName = "Firefox Nightly"
firefoxESRName = "Firefox ESR"
speed360Name = "360speed"
qqBrowserName = "QQ"
braveName = "Brave"
operaName = "Opera"
operaGXName = "OperaGX"
vivaldiName = "Vivaldi"
coccocName = "CocCoc"
yandexName = "Yandex"
) )
var defaultFirefoxItems = []item{ var defaultFirefoxItems = []item{

@ -13,7 +13,6 @@ var (
chromiumList = map[string]struct { chromiumList = map[string]struct {
browserInfo *browserInfo browserInfo *browserInfo
items []item items []item
// New func(browser *browserInfo, items []item) *firefox
}{ }{
"chrome": { "chrome": {
browserInfo: chromeInfo, browserInfo: chromeInfo,
@ -23,6 +22,38 @@ var (
browserInfo: edgeInfo, browserInfo: edgeInfo,
items: defaultChromiumItems, items: defaultChromiumItems,
}, },
"chromium": {
browserInfo: chromiumInfo,
items: defaultChromiumItems,
},
"chrome-beta": {
browserInfo: chromeBetaInfo,
items: defaultChromiumItems,
},
"opera": {
browserInfo: operaInfo,
items: defaultChromiumItems,
},
"opera-gx": {
browserInfo: operaGXInfo,
items: defaultChromiumItems,
},
"vivaldi": {
browserInfo: vivaldiInfo,
items: defaultChromiumItems,
},
"coccoc": {
browserInfo: coccocInfo,
items: defaultChromiumItems,
},
"brave": {
browserInfo: braveInfo,
items: defaultChromiumItems,
},
"yandex": {
browserInfo: yandexInfo,
items: defaultYandexItems,
},
} }
firefoxList = map[string]struct { firefoxList = map[string]struct {
browserInfo *browserInfo browserInfo *browserInfo
@ -63,26 +94,12 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
var chromeSalt = []byte("saltysalt") var chromeSalt = []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157 // @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) key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
c.browserInfo.masterKey = key if key != nil {
return key, nil c.browserInfo.masterKey = key
} return key, nil
var (
chromeInfo = &browserInfo{
name: chromeName,
storage: chromeStorageName,
profilePath: chromeProfilePath,
}
edgeInfo = &browserInfo{
name: edgeName,
storage: edgeStorageName,
profilePath: edgeProfilePath,
}
firefoxInfo = &browserInfo{
name: firefoxName,
profilePath: firefoxProfilePath,
} }
) return nil, errors.New("macOS wrong security command")
}
const ( const (
chromeProfilePath = "/Library/Application Support/Google/Chrome/" chromeProfilePath = "/Library/Application Support/Google/Chrome/"
@ -110,3 +127,60 @@ 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,
}
)

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"hack-browser-data/pkg/browser/outputter" "hack-browser-data/internal/browser/outputter"
"hack-browser-data/pkg/log" "hack-browser-data/internal/log"
) )
func TestPickChromium(t *testing.T) { func TestPickChromium(t *testing.T) {
@ -44,6 +44,16 @@ func TestPickChromium(t *testing.T) {
} }
} }
func TestPickBrowsers(t *testing.T) {
browsers := PickBrowser("all")
for _, v := range browsers {
fmt.Println(v.GetName())
}
// filetype := "json"
// dir := "result"
// output := outputter.NewOutPutter(filetype)
}
func TestPickFirefox(t *testing.T) { func TestPickFirefox(t *testing.T) {
browsers := pickFirefox("all") browsers := pickFirefox("all")
filetype := "json" filetype := "json"

@ -6,9 +6,9 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/pkg/decrypter" "hack-browser-data/internal/decrypter"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
) )
var ( var (

@ -7,8 +7,8 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
) )
type ChromiumBookmark []bookmark type ChromiumBookmark []bookmark

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"sort" "sort"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/pkg/decrypter" "hack-browser-data/internal/decrypter"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

@ -4,10 +4,10 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"hack-browser-data/pkg/browser/consts"
"hack-browser-data/pkg/decrypter"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"hack-browser-data/internal/browser/consts"
"hack-browser-data/internal/decrypter"
) )
type ChromiumCreditCard []card type ChromiumCreditCard []card

@ -8,8 +8,8 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"sort" "sort"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )

@ -9,9 +9,9 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/pkg/decrypter" decrypter2 "hack-browser-data/internal/decrypter"
"hack-browser-data/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
@ -47,12 +47,12 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error {
} }
if len(pwd) > 0 { if len(pwd) > 0 {
if masterKey == nil { if masterKey == nil {
password, err = decrypter.DPApi(pwd) password, err = decrypter2.DPApi(pwd)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
} else { } else {
password, err = decrypter.ChromePass(masterKey, pwd) password, err = decrypter2.ChromePass(masterKey, pwd)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -84,7 +84,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 := decrypter2.NewASN1PBE(metaBytes)
if err != nil { if err != nil {
return err return err
} }
@ -97,7 +97,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 := decrypter2.NewASN1PBE(nssA11)
if err != nil { if err != nil {
return err return err
} }
@ -111,11 +111,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 := decrypter2.NewASN1PBE(v.encryptUser)
if err != nil { if err != nil {
return err return err
} }
pwdPBE, err := decrypter.NewASN1PBE(v.encryptPass) pwdPBE, err := decrypter2.NewASN1PBE(v.encryptPass)
if err != nil { if err != nil {
return err return err
} }
@ -129,8 +129,8 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
} }
*f = append(*f, loginData{ *f = append(*f, loginData{
LoginUrl: v.LoginUrl, LoginUrl: v.LoginUrl,
UserName: string(decrypter.PKCS5UnPadding(user)), UserName: string(decrypter2.PKCS5UnPadding(user)),
Password: string(decrypter.PKCS5UnPadding(pwd)), Password: string(decrypter2.PKCS5UnPadding(pwd)),
CreateDate: v.CreateDate, CreateDate: v.CreateDate,
}) })
} }

@ -1,8 +1,8 @@
package browser package browser
import ( import (
"hack-browser-data/pkg/browser/consts" "hack-browser-data/internal/browser/consts"
"hack-browser-data/pkg/browser/data" data2 "hack-browser-data/internal/browser/data"
) )
type item int type item int
@ -126,40 +126,40 @@ func (i item) FileName() string {
} }
} }
func (i item) NewBrowsingData() data.BrowsingData { func (i item) NewBrowsingData() data2.BrowsingData {
switch i { switch i {
case chromiumKey: case chromiumKey:
return nil return nil
case chromiumPassword: case chromiumPassword:
return &data.ChromiumPassword{} return &data2.ChromiumPassword{}
case chromiumCookie: case chromiumCookie:
return &data.ChromiumCookie{} return &data2.ChromiumCookie{}
case chromiumBookmark: case chromiumBookmark:
return &data.ChromiumBookmark{} return &data2.ChromiumBookmark{}
case chromiumDownload: case chromiumDownload:
return &data.ChromiumDownload{} return &data2.ChromiumDownload{}
case chromiumLocalStorage: case chromiumLocalStorage:
return nil return nil
case chromiumCreditCard: case chromiumCreditCard:
return &data.ChromiumCreditCard{} return &data2.ChromiumCreditCard{}
case chromiumExtension: case chromiumExtension:
return nil return nil
case chromiumHistory: case chromiumHistory:
return &data.ChromiumHistory{} return &data2.ChromiumHistory{}
case yandexPassword: case yandexPassword:
return &data.ChromiumPassword{} return &data2.ChromiumPassword{}
case yandexCreditCard: case yandexCreditCard:
return &data.ChromiumCreditCard{} return &data2.ChromiumCreditCard{}
case firefoxPassword: case firefoxPassword:
return &data.FirefoxPassword{} return &data2.FirefoxPassword{}
case firefoxCookie: case firefoxCookie:
return &data.FirefoxCookie{} return &data2.FirefoxCookie{}
case firefoxBookmark: case firefoxBookmark:
return &data.FirefoxBookmark{} return &data2.FirefoxBookmark{}
case firefoxDownload: case firefoxDownload:
return &data.FirefoxDownload{} return &data2.FirefoxDownload{}
case firefoxHistory: case firefoxHistory:
return &data.FirefoxHistory{} return &data2.FirefoxHistory{}
default: default:
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/pkg/browser/data" "hack-browser-data/internal/browser/data"
) )
type outPutter struct { type outPutter struct {

@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"hack-browser-data/pkg/log" "hack-browser-data/internal/log"
) )
const Prefix = "[x]: " const Prefix = "[x]: "
Loading…
Cancel
Save