HackBrowserData/cmd/cmd.go

105 lines
3.1 KiB
Go
Raw Normal View History

2020-06-22 09:23:18 +00:00
package cmd
import (
2020-06-25 20:33:23 +00:00
"hack-browser-data/core"
2020-06-22 09:23:18 +00:00
"hack-browser-data/log"
"hack-browser-data/utils"
"os"
2020-06-23 10:30:00 +00:00
"path/filepath"
2020-06-28 09:18:02 +00:00
"strings"
2020-06-22 09:23:18 +00:00
"github.com/urfave/cli/v2"
)
var (
browser string
exportData string
exportDir string
outputFormat string
verbose bool
)
func Execute() {
app := &cli.App{
2020-06-28 09:18:02 +00:00
Name: "hack-browser-data",
2020-06-30 06:13:53 +00:00
Usage: "Export passwords/cookies/history/bookmarks from browser",
2020-06-28 09:18:02 +00:00
UsageText: "[hack-browser-data -b chrome -f json -dir results -e all]\n Get all data(password/cookie/history/bookmark) from chrome",
2020-06-23 10:30:00 +00:00
Version: "0.1.0",
2020-06-22 09:23:18 +00:00
Flags: []cli.Flag{
2020-07-10 03:29:03 +00:00
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "Verbose"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "chrome", Usage: "Available browsers: " + strings.Join(utils.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"},
2020-06-22 09:23:18 +00:00
&cli.StringFlag{Name: "export-data", Aliases: []string{"e"}, Destination: &exportData, Value: "all", Usage: "all|password|cookie|history|bookmark"},
},
2020-06-28 09:18:02 +00:00
HideHelpCommand: true,
HideVersion: true,
2020-06-22 09:23:18 +00:00
Action: func(c *cli.Context) error {
2020-06-28 09:18:02 +00:00
if verbose {
log.InitLog("debug")
} else {
log.InitLog("error")
}
browserDir, key, err := utils.PickBrowser(browser)
if err != nil {
log.Fatal(err, " Available browsers: "+strings.Join(utils.ListBrowser(), "|"))
}
2020-07-06 07:19:11 +00:00
if browser != "firefox" {
err = utils.InitKey(key)
2020-06-23 10:30:00 +00:00
if err != nil {
2020-07-06 07:19:11 +00:00
log.Fatal(err, "Please Open an issue on GitHub")
}
var fileList []string
switch exportData {
case "all":
fileList = utils.GetDBPath(browserDir, utils.LoginData, utils.History, utils.Bookmarks, utils.Cookies)
case "password", "cookie", "history", "bookmark":
fileList = utils.GetDBPath(browserDir, exportData)
default:
log.Fatal("Choose one from all|password|cookie|history|bookmark")
}
for _, v := range fileList {
dst := filepath.Base(v)
err := utils.CopyDB(v, dst)
if err != nil {
2020-07-09 08:49:35 +00:00
log.Debug(err)
2020-07-06 07:19:11 +00:00
continue
}
core.ParseResult(dst)
}
} else {
fileList := utils.GetDBPath(browserDir, utils.FirefoxLoginData, utils.FirefoxKey4DB, utils.FirefoxCookie, utils.FirefoxData)
2020-07-10 08:09:23 +00:00
log.Error("fileList", fileList)
2020-07-06 07:19:11 +00:00
for _, v := range fileList {
dst := filepath.Base(v)
err := utils.CopyDB(v, dst)
if err != nil {
2020-07-09 08:49:35 +00:00
log.Debug(err)
2020-07-06 07:19:11 +00:00
continue
}
2020-07-06 08:13:25 +00:00
core.ParseResult(dst)
2020-06-23 10:30:00 +00:00
}
2020-06-22 09:23:18 +00:00
}
2020-07-07 13:27:50 +00:00
core.FullData.Sorted()
2020-07-09 08:49:35 +00:00
utils.MakeDir(exportDir)
2020-06-23 10:30:00 +00:00
if outputFormat == "json" {
2020-06-28 09:18:02 +00:00
err := core.FullData.OutPutJson(exportDir, browser, outputFormat)
2020-06-23 10:30:00 +00:00
if err != nil {
log.Error(err)
}
} else {
2020-06-28 09:18:02 +00:00
err := core.FullData.OutPutCsv(exportDir, browser, outputFormat)
2020-06-23 10:30:00 +00:00
if err != nil {
log.Error(err)
}
2020-06-22 09:23:18 +00:00
}
return nil
},
}
err := app.Run(os.Args)
if err != nil {
panic(err)
return
}
}