新增allInOne选项,用于将所有结果直接输出到屏幕中,方便其他程序二次调用

pull/83/head
sky 4 years ago
parent a843224137
commit 5b7c1feee9
  1. 31
      cmd/cmd.go
  2. 24
      core/data/output.go
  3. 18
      core/data/parse.go
  4. 6
      log/log.go
  5. 8
      utils/utils.go

@ -1,13 +1,15 @@
package cmd package cmd
import ( import (
"bytes"
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"hack-browser-data/core" "hack-browser-data/core"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils" "hack-browser-data/utils"
"os" "os"
"strings" "strings"
"github.com/urfave/cli/v2"
) )
var ( var (
@ -16,8 +18,10 @@ var (
outputFormat string outputFormat string
verbose bool verbose bool
compress bool compress bool
allInOne bool
customProfilePath string customProfilePath string
customKeyPath string customKeyPath string
results map[string]interface{}
) )
func Execute() { func Execute() {
@ -29,6 +33,7 @@ func Execute() {
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"}, &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: "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: "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: "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: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "format, csv|json|console"},
@ -37,6 +42,11 @@ func Execute() {
}, },
HideHelpCommand: true, HideHelpCommand: true,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
log.AllInOne = allInOne
if allInOne {
outputFormat = "aconsole"
}
var ( var (
browsers []core.Browser browsers []core.Browser
err error err error
@ -96,18 +106,33 @@ func Execute() {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
err = item.OutPut(outputFormat, name, exportDir) err = item.OutPut(outputFormat, name, exportDir)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
} }
} }
if compress {
if compress && allInOne == false {
err = utils.Compress(exportDir) err = utils.Compress(exportDir)
if err != nil { if err != nil {
log.Error(err) 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 return nil
}, },
} }

@ -222,3 +222,27 @@ func (c *creditCards) outPutConsole() {
fmt.Printf("%+v\n", v) 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
}

@ -186,6 +186,9 @@ func (b *bookmarks) OutPut(format, browser, dir string) error {
case "console": case "console":
b.outPutConsole() b.outPutConsole()
return nil return nil
case "aconsole":
b.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := b.outPutJson(browser, dir) err := b.outPutJson(browser, dir)
return err return err
@ -319,6 +322,9 @@ func (c *cookies) OutPut(format, browser, dir string) error {
case "console": case "console":
c.outPutConsole() c.outPutConsole()
return nil return nil
case "aconsole":
c.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := c.outPutJson(browser, dir) err := c.outPutJson(browser, dir)
return err return err
@ -445,6 +451,9 @@ func (h *historyData) OutPut(format, browser, dir string) error {
case "console": case "console":
h.outPutConsole() h.outPutConsole()
return nil return nil
case "aconsole":
h.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := h.outPutJson(browser, dir) err := h.outPutJson(browser, dir)
return err return err
@ -576,6 +585,9 @@ func (d *downloads) OutPut(format, browser, dir string) error {
case "console": case "console":
d.outPutConsole() d.outPutConsole()
return nil return nil
case "aconsole":
d.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := d.outPutJson(browser, dir) err := d.outPutJson(browser, dir)
return err return err
@ -747,6 +759,9 @@ func (p *passwords) OutPut(format, browser, dir string) error {
case "console": case "console":
p.outPutConsole() p.outPutConsole()
return nil return nil
case "aconsole":
p.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := p.outPutJson(browser, dir) err := p.outPutJson(browser, dir)
return err return err
@ -831,6 +846,9 @@ func (c *creditCards) OutPut(format, browser, dir string) error {
case "console": case "console":
c.outPutConsole() c.outPutConsole()
return nil return nil
case "aconsole":
c.outPutAllInOneConsole(strings.ToLower(browser))
return nil
default: default:
err := c.outPutJson(browser, dir) err := c.outPutJson(browser, dir)
return err return err

@ -7,6 +7,8 @@ import (
"os" "os"
) )
var AllInOne bool
type Level int type Level int
const ( const (
@ -79,12 +81,16 @@ func Debug(v ...interface{}) {
} }
func Warn(v ...interface{}) { func Warn(v ...interface{}) {
if AllInOne == false {
formatLogger.doLog(LevelWarn, v...) formatLogger.doLog(LevelWarn, v...)
} }
}
func Error(v ...interface{}) { func Error(v ...interface{}) {
if AllInOne == false {
formatLogger.doLog(LevelError, v...) formatLogger.doLog(LevelError, v...)
} }
}
func Errorf(format string, v ...interface{}) { func Errorf(format string, v ...interface{}) {
formatLogger.doLogf(LevelError, format, v...) formatLogger.doLogf(LevelError, format, v...)

@ -4,17 +4,21 @@ import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"fmt" "fmt"
"hack-browser-data/log"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
"time" "time"
"hack-browser-data/log"
) )
const Prefix = "[x]: " const Prefix = "[x]: "
var Result map[string]interface{}
func init() {
Result = make(map[string]interface{})
}
func IntToBool(a int) bool { func IntToBool(a int) bool {
switch a { switch a {
case 0, -1: case 0, -1:

Loading…
Cancel
Save