refactor: format project layout

pull/121/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent a341928926
commit c2bc33e2fe
  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"
"strings"
"hack-browser-data/pkg/browser"
"hack-browser-data/pkg/browser/outputter"
"hack-browser-data/pkg/log"
"github.com/urfave/cli/v2"
"hack-browser-data/internal/browser"
"hack-browser-data/internal/browser/outputter"
"hack-browser-data/internal/log"
)
var (
@ -26,7 +26,7 @@ func Execute() {
Name: "hack-browser-data",
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",
Version: "0.3.7",
Version: "0.3.8",
Flags: []cli.Flag{
&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"},
@ -46,7 +46,7 @@ func Execute() {
} else {
log.InitLog("error")
}
browsers = browser.PickBrowsers(browserName)
browsers = browser.PickBrowser(browserName)
output := outputter.NewOutPutter(outputFormat)
if err := output.MakeDir(exportDir); err != nil {

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

@ -7,7 +7,7 @@ import (
keyring "github.com/ppacher/go-dbus-keyring"
"golang.org/x/crypto/pbkdf2"
"hack-browser-data/pkg/log"
"hack-browser-data/internal/log"
)
const (

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

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

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

@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"hack-browser-data/pkg/browser/data"
"hack-browser-data/internal/browser/data"
)
type Browser interface {
@ -27,16 +27,16 @@ var (
homeDir, _ = os.UserHomeDir()
)
func PickBrowsers(name string) []Browser {
func PickBrowser(name string) []Browser {
var browsers []Browser
chromiumList := pickChromium(name)
for _, b := range chromiumList {
clist := pickChromium(name)
for _, b := range clist {
if b != nil {
browsers = append(browsers, b)
}
}
firefoxList := pickFirefox(name)
for _, b := range firefoxList {
flist := pickFirefox(name)
for _, b := range flist {
if b != nil {
browsers = append(browsers, b)
}
@ -49,11 +49,14 @@ func pickChromium(name string) []Browser {
name = strings.ToLower(name)
if name == "all" {
for _, choice := range chromiumList {
b, err := newChromium(choice.browserInfo, choice.items)
if err != nil {
if b, err := newChromium(choice.browserInfo, choice.items); err == nil {
browsers = append(browsers, b)
} else {
if strings.Contains(err.Error(), "profile path is not exist") {
continue
}
panic(err)
}
browsers = append(browsers, b)
}
return browsers
}
@ -72,8 +75,8 @@ func pickFirefox(name string) []Browser {
var browsers []Browser
name = strings.ToLower(name)
if name == "all" || name == "firefox" {
for _, v := range firefoxList {
multiFirefox, err := newMultiFirefox(v.browserInfo, v.items)
for _, b := range firefoxList {
multiFirefox, err := newMultiFirefox(b.browserInfo, b.items)
if err != nil {
panic(err)
}
@ -163,6 +166,10 @@ func newMultiFirefox(info *browserInfo, items []item) ([]*firefox, error) {
}
multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items)
if err != nil {
if strings.Contains(err.Error(), "profile path is not exist") {
fmt.Println(err)
return nil, nil
}
panic(err)
}
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) {
var multiItemPaths = make(map[string]map[item]string)
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))
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) {
var itemPaths = make(map[item]string)
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))
return itemPaths, err
}
@ -272,6 +287,7 @@ func (f *firefox) GetBrowsingData() []data.BrowsingData {
}
return browsingData
}
func ListBrowser() []string {
var l []string
for c := range chromiumList {
@ -283,6 +299,13 @@ 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
@ -291,10 +314,23 @@ type browserInfo struct {
}
const (
chromeName = "Chrome"
edgeName = "Edge"
firefoxName = "Firefox"
yandexName = "Yandex"
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "Chromium"
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{

@ -13,7 +13,6 @@ var (
chromiumList = map[string]struct {
browserInfo *browserInfo
items []item
// New func(browser *browserInfo, items []item) *firefox
}{
"chrome": {
browserInfo: chromeInfo,
@ -23,6 +22,38 @@ var (
browserInfo: edgeInfo,
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 {
browserInfo *browserInfo
@ -63,26 +94,12 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
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)
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,
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/"
@ -110,3 +127,60 @@ 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,
}
)

@ -4,8 +4,8 @@ import (
"fmt"
"testing"
"hack-browser-data/pkg/browser/outputter"
"hack-browser-data/pkg/log"
"hack-browser-data/internal/browser/outputter"
"hack-browser-data/internal/log"
)
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) {
browsers := pickFirefox("all")
filetype := "json"

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

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

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

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

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

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

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

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

@ -10,7 +10,7 @@ import (
"github.com/gocarina/gocsv"
jsoniter "github.com/json-iterator/go"
"hack-browser-data/pkg/browser/data"
"hack-browser-data/internal/browser/data"
)
type outPutter struct {

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