HackBrowserData/cmd/cmd.go

85 lines
2.2 KiB
Go
Raw Normal View History

2020-06-22 09:23:18 +00:00
package cmd
import (
2020-06-23 10:30:00 +00:00
"hack-browser-data/core/common"
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
"runtime"
"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)
2020-06-22 09:23:18 +00:00
switch runtime.GOOS {
case "darwin":
err := utils.InitChromeKey()
if err != nil {
}
case "windows":
2020-06-23 10:30:00 +00:00
}
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:
log.Fatal("choose one all|password|cookie|history|bookmark")
}
for _, v := range fileList {
dst := filepath.Base(v)
err := utils.CopyDB(v, dst)
if err != nil {
log.Println(err)
continue
}
common.ParseDB(dst)
2020-06-22 09:23:18 +00:00
}
2020-06-23 10:30:00 +00:00
if outputFormat == "json" {
err := common.FullData.OutPutJson(exportDir, outputFormat)
if err != nil {
log.Error(err)
}
} else {
err := common.FullData.OutPutCsv(exportDir, outputFormat)
if err != nil {
log.Error(err)
}
2020-06-22 09:23:18 +00:00
}
2020-06-23 10:30:00 +00:00
2020-06-22 09:23:18 +00:00
return nil
},
}
err := app.Run(os.Args)
if err != nil {
panic(err)
return
}
}