From 5b7c1feee9c062a36d4f5f0d3c53dbc060cb3927 Mon Sep 17 00:00:00 2001 From: sky Date: Tue, 18 May 2021 11:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EallInOne=E9=80=89=E9=A1=B9?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=B0=86=E6=89=80=E6=9C=89=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E7=9B=B4=E6=8E=A5=E8=BE=93=E5=87=BA=E5=88=B0=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E4=B8=AD,=E6=96=B9=E4=BE=BF=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BA=8C=E6=AC=A1=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cmd.go | 31 ++++++++++++++++++++++++++++--- core/data/output.go | 24 ++++++++++++++++++++++++ core/data/parse.go | 18 ++++++++++++++++++ log/log.go | 10 ++++++++-- utils/utils.go | 8 ++++++-- 5 files changed, 84 insertions(+), 7 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 903a378..bc40988 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,13 +1,15 @@ package cmd import ( + "bytes" + "encoding/json" + "fmt" + "github.com/urfave/cli/v2" "hack-browser-data/core" "hack-browser-data/log" "hack-browser-data/utils" "os" "strings" - - "github.com/urfave/cli/v2" ) var ( @@ -16,8 +18,10 @@ var ( outputFormat string verbose bool compress bool + allInOne bool customProfilePath string customKeyPath string + results map[string]interface{} ) func Execute() { @@ -29,6 +33,7 @@ func Execute() { 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.BoolFlag{Name: "all-in-one", Aliases: []string{"one"}, Destination: &allInOne, Value: false, Usage: "All the results are output as a file after json serialization or directly output to the console"}, &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"}, @@ -37,6 +42,11 @@ func Execute() { }, HideHelpCommand: true, Action: func(c *cli.Context) error { + log.AllInOne = allInOne + if allInOne { + outputFormat = "aconsole" + } + var ( browsers []core.Browser err error @@ -96,18 +106,33 @@ func Execute() { if err != nil { log.Error(err) } + err = item.OutPut(outputFormat, name, exportDir) if err != nil { log.Error(err) } } } - if compress { + + if compress && allInOne == false { err = utils.Compress(exportDir) if err != nil { log.Error(err) } } + + if allInOne { + utils.Result["status"] = "success" + w := new(bytes.Buffer) + enc := json.NewEncoder(w) + enc.SetEscapeHTML(false) + err = enc.Encode(utils.Result) + if err != nil { + fmt.Println("{\"status\":\"error\"}") + } else { + fmt.Println(w.String()) + } + } return nil }, } diff --git a/core/data/output.go b/core/data/output.go index 45b7a57..e31f324 100644 --- a/core/data/output.go +++ b/core/data/output.go @@ -222,3 +222,27 @@ func (c *creditCards) outPutConsole() { fmt.Printf("%+v\n", v) } } + +func (b *bookmarks) outPutAllInOneConsole(name string) { + utils.Result[name+"_bookmarks"] = b.bookmarks +} + +func (c *cookies) outPutAllInOneConsole(name string) { + utils.Result[name+"_cookies"] = c.cookies +} + +func (h *historyData) outPutAllInOneConsole(name string) { + utils.Result[name+"_history"] = h.history +} + +func (d *downloads) outPutAllInOneConsole(name string) { + utils.Result[name+"_downloads"] = d.downloads +} + +func (p *passwords) outPutAllInOneConsole(name string) { + utils.Result[name+"_logins"] = p.logins +} + +func (c *creditCards) outPutAllInOneConsole(name string) { + utils.Result[name+"_cards"] = c.cards +} diff --git a/core/data/parse.go b/core/data/parse.go index 86d08b9..1ef4528 100644 --- a/core/data/parse.go +++ b/core/data/parse.go @@ -186,6 +186,9 @@ func (b *bookmarks) OutPut(format, browser, dir string) error { case "console": b.outPutConsole() return nil + case "aconsole": + b.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := b.outPutJson(browser, dir) return err @@ -319,6 +322,9 @@ func (c *cookies) OutPut(format, browser, dir string) error { case "console": c.outPutConsole() return nil + case "aconsole": + c.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := c.outPutJson(browser, dir) return err @@ -445,6 +451,9 @@ func (h *historyData) OutPut(format, browser, dir string) error { case "console": h.outPutConsole() return nil + case "aconsole": + h.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := h.outPutJson(browser, dir) return err @@ -576,6 +585,9 @@ func (d *downloads) OutPut(format, browser, dir string) error { case "console": d.outPutConsole() return nil + case "aconsole": + d.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := d.outPutJson(browser, dir) return err @@ -747,6 +759,9 @@ func (p *passwords) OutPut(format, browser, dir string) error { case "console": p.outPutConsole() return nil + case "aconsole": + p.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := p.outPutJson(browser, dir) return err @@ -831,6 +846,9 @@ func (c *creditCards) OutPut(format, browser, dir string) error { case "console": c.outPutConsole() return nil + case "aconsole": + c.outPutAllInOneConsole(strings.ToLower(browser)) + return nil default: err := c.outPutJson(browser, dir) return err diff --git a/log/log.go b/log/log.go index 6b6c916..cea3ba4 100644 --- a/log/log.go +++ b/log/log.go @@ -7,6 +7,8 @@ import ( "os" ) +var AllInOne bool + type Level int const ( @@ -79,11 +81,15 @@ func Debug(v ...interface{}) { } func Warn(v ...interface{}) { - formatLogger.doLog(LevelWarn, v...) + if AllInOne == false { + formatLogger.doLog(LevelWarn, v...) + } } func Error(v ...interface{}) { - formatLogger.doLog(LevelError, v...) + if AllInOne == false { + formatLogger.doLog(LevelError, v...) + } } func Errorf(format string, v ...interface{}) { diff --git a/utils/utils.go b/utils/utils.go index b5e9c98..24dfcbb 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -4,17 +4,21 @@ import ( "archive/zip" "bytes" "fmt" + "hack-browser-data/log" "io/ioutil" "os" "path" "strings" "time" - - "hack-browser-data/log" ) const Prefix = "[x]: " +var Result map[string]interface{} + +func init() { + Result = make(map[string]interface{}) +} func IntToBool(a int) bool { switch a { case 0, -1: