feat: add cli options

pull/121/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent b064326103
commit dd4c3c4029
  1. 172
      cmd/hack-browser-data/main.go
  2. 6
      internal/browingdata/bookmark.go
  3. 4
      internal/browingdata/cookie.go
  4. 4
      internal/browingdata/password.go
  5. 4
      internal/browser/browser.go

@ -3,10 +3,14 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"hack-browser-data/internal/browser" "hack-browser-data/internal/browser"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
"hack-browser-data/internal/outputter" "hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils"
"github.com/urfave/cli/v2"
) )
var ( var (
@ -23,122 +27,62 @@ func main() {
} }
func Execute() { func Execute() {
browsers := browser.PickBrowser("firefox") app := &cli.App{
log.InitLog("debug") Name: "hack-browser-data",
filetype := "json" Usage: "Export passwords/cookies/history/bookmarks from browser",
dir := "results" UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\n Get all browingdata(password/cookie/history/bookmark) from chrome",
// dir := "result" Version: "0.4.0",
output := outputter.New(filetype) Flags: []cli.Flag{
var file *os.File &cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
fmt.Println("browser number:", len(browsers)) &cli.BoolFlag{Name: "compress", Aliases: []string{"cc"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
for _, b := range browsers { &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(browser.ListBrowser(), "|")},
browsingData, err := b.GetBrowsingData() &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &exportDir, Value: "results", Usage: "export dir"},
if err != nil { &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "format, csv|json|console"},
panic(err) &cli.StringFlag{Name: "profile-dir-path", Aliases: []string{"p"}, Destination: &customProfilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"},
} },
for _, source := range browsingData.Sources { HideHelpCommand: true,
filename := fmt.Sprintf("%s_%s.%s", b.Name(), source.Name(), filetype) Action: func(c *cli.Context) error {
file, err = output.CreateFile(dir, filename) var (
err = output.Write(source, file) browsers []browser.Browser
err error
)
if verbose {
log.InitLog("debug")
} else {
log.InitLog("error")
}
browsers, err = browser.PickBrowser(browserName)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
} output := outputter.New(outputFormat)
for _, b := range browsers {
data, err := b.GetBrowsingData()
if err != nil {
log.Error(err)
}
var f *os.File
for _, source := range data.Sources {
filename := fmt.Sprintf("%s_%s.%s", b.Name(), source.Name(), outputFormat)
f, err = output.CreateFile(exportDir, filename)
err = output.Write(source, f)
if err != nil {
log.Error(err)
}
}
}
if compress {
err = utils.Compress(exportDir)
if err != nil {
log.Error(err)
}
}
return nil
},
}
err := app.Run(os.Args)
if err != nil {
log.Error(err)
} }
} }
// func Execute() {
// app := &cli.App{
// 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 browingdata(password/cookie/history/bookmark) from chrome",
// Version: "0.3.7",
// 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"},
// &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(core.ListBrowser(), "|")},
// &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &exportDir, Value: "results", Usage: "export dir"},
// &cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "format, csv|json|console"},
// &cli.StringFlag{Name: "profile-dir-path", Aliases: []string{"p"}, Destination: &customProfilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"},
// },
// HideHelpCommand: true,
// Action: func(c *cli.Context) error {
// var (
// browsers []core.Browser
// err error
// )
// if verbose {
// log.InitLog("debug")
// } else {
// log.InitLog("error")
// }
// if customProfilePath != "" {
// browsers, err = core.PickCustomBrowser(browserName, customProfilePath, customKeyPath)
// if err != nil {
// log.Error(err)
// }
// } else {
// // default select all browsers
// browsers, err = core.PickBrowser(browserName)
// if err != nil {
// log.Error(err)
// }
// }
// err = utils.MakeDir(exportDir)
// if err != nil {
// log.Error(err)
// }
// for _, browser := range browsers {
// err := browser.InitSecretKey()
// if err != nil {
// log.Error(err)
// }
// // default select all items
// // you can get single item with browser.GetItem(itemName)
// items, err := browser.GetAllItems()
// if err != nil {
// log.Error(err)
// }
// name := browser.Name()
// key := browser.GetSecretKey()
// for _, item := range items {
// err := item.CopyDB()
// if err != nil {
// log.Error(err)
// }
// switch browser.(type) {
// case *core.Chromium:
// err := item.ChromeParse(key)
// if err != nil {
// log.Error(err)
// }
// case *core.Firefox:
// err := item.FirefoxParse()
// if err != nil {
// log.Error(err)
// }
// }
// err = item.Release()
// if err != nil {
// log.Error(err)
// }
// err = item.OutPut(outputFormat, name, exportDir)
// if err != nil {
// log.Error(err)
// }
// }
// }
// if compress {
// err = utils.Compress(exportDir)
// if err != nil {
// log.Error(err)
// }
// }
// return nil
// },
// }
// err := app.Run(os.Args)
// if err != nil {
// log.Error(err)
// }
// }

@ -40,7 +40,7 @@ func (c *ChromiumBookmark) Parse(masterKey []byte) error {
return true return true
}) })
} }
// TODO: 使用泛型重构 // TODO: refactor with go generics
sort.Slice(*c, func(i, j int) bool { sort.Slice(*c, func(i, j int) bool {
return (*c)[i].DateAdded.After((*c)[j].DateAdded) return (*c)[i].DateAdded.After((*c)[j].DateAdded)
}) })
@ -95,7 +95,9 @@ func (f *FirefoxBookmark) Parse(masterKey []byte) error {
defer os.Remove(item.TempFirefoxBookmark) defer os.Remove(item.TempFirefoxBookmark)
defer keyDB.Close() defer keyDB.Close()
_, err = keyDB.Exec(closeJournalMode) _, err = keyDB.Exec(closeJournalMode)
if err != nil {
log.Error(err)
}
bookmarkRows, err = keyDB.Query(queryFirefoxBookMark) bookmarkRows, err = keyDB.Query(queryFirefoxBookMark)
if err != nil { if err != nil {
return err return err

@ -58,7 +58,9 @@ func (c *ChromiumCookie) Parse(masterKey []byte) error {
} else { } else {
value, err = decrypter.ChromePass(masterKey, encryptValue) value, err = decrypter.ChromePass(masterKey, encryptValue)
} }
log.Error(err) if err != nil {
log.Error(err)
}
} }
cookie.Value = string(value) cookie.Value = string(value)
*c = append(*c, cookie) *c = append(*c, cookie)

@ -54,7 +54,9 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error {
} else { } else {
password, err = decrypter.ChromePass(masterKey, pwd) password, err = decrypter.ChromePass(masterKey, pwd)
} }
log.Error(err) if err != nil {
log.Error(err)
}
} }
if create > time.Now().Unix() { if create > time.Now().Unix() {
login.CreateDate = utils.TimeEpochFormat(create) login.CreateDate = utils.TimeEpochFormat(create)

@ -18,7 +18,7 @@ type Browser interface {
GetBrowsingData() (*browingdata.Data, error) GetBrowsingData() (*browingdata.Data, error)
} }
func PickBrowser(name string) []Browser { func PickBrowser(name string) ([]Browser, error) {
var browsers []Browser var browsers []Browser
clist := pickChromium(name) clist := pickChromium(name)
for _, b := range clist { for _, b := range clist {
@ -32,7 +32,7 @@ func PickBrowser(name string) []Browser {
browsers = append(browsers, b) browsers = append(browsers, b)
} }
} }
return browsers return browsers, nil
} }
func pickChromium(name string) []Browser { func pickChromium(name string) []Browser {

Loading…
Cancel
Save