HackBrowserData/cmd/cmd.go

78 lines
2.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-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{
Name: "hack-browser-data",
2020-06-23 10:30:00 +00:00
Usage: "export passwords/cookies/history/bookmarks from browser",
Version: "0.1.0",
2020-06-22 09:23:18 +00:00
Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "all", Usage: "browser name, all|chrome|safari"},
2020-06-23 10:30:00 +00:00
&cli.StringFlag{Name: "results-dir", Aliases: []string{"d"}, Destination: &exportDir, Value: "results", Usage: "export dir"},
2020-06-22 09:23:18 +00:00
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "result format, csv|json"},
&cli.StringFlag{Name: "export-data", Aliases: []string{"e"}, Destination: &exportData, Value: "all", Usage: "all|password|cookie|history|bookmark"},
},
Action: func(c *cli.Context) error {
log.InitLog()
2020-06-23 10:30:00 +00:00
utils.MakeDir(exportDir)
var fileList []string
switch exportData {
case "all":
fileList = utils.GetDBPath(utils.LoginData, utils.History, utils.Bookmarks, utils.Cookies)
case "password", "cookie", "history", "bookmark":
fileList = utils.GetDBPath(exportData)
default:
2020-06-25 09:37:18 +00:00
log.Fatal("choose one from all|password|cookie|history|bookmark")
}
err := utils.InitChromeKey()
if err != nil {
panic(err)
2020-06-23 10:30:00 +00:00
}
for _, v := range fileList {
dst := filepath.Base(v)
err := utils.CopyDB(v, dst)
if err != nil {
log.Println(err)
continue
}
2020-06-25 20:33:23 +00:00
core.ChromeDB(dst)
2020-06-22 09:23:18 +00:00
}
2020-06-23 10:30:00 +00:00
if outputFormat == "json" {
2020-06-25 20:33:23 +00:00
err := core.FullData.OutPutJson(exportDir, outputFormat)
2020-06-23 10:30:00 +00:00
if err != nil {
log.Error(err)
}
} else {
2020-06-25 20:33:23 +00:00
err := core.FullData.OutPutCsv(exportDir, 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
}
}