add file type and filepath param

pull/54/head
polunzh 5 years ago
parent 35c26a148e
commit 2f5482736b
  1. 62
      cmd/cmd.go
  2. 135
      core/data/parse.go

@ -3,7 +3,6 @@ package cmd
import ( import (
"hack-browser-data/core" "hack-browser-data/core"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils"
"os" "os"
"strings" "strings"
@ -14,6 +13,8 @@ var (
browser string browser string
exportDir string exportDir string
outputFormat string outputFormat string
fileType string
filepath string
verbose bool verbose bool
compress bool compress bool
) )
@ -30,6 +31,8 @@ func Execute() {
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "all", Usage: "Available browsers: all|" + strings.Join(core.ListBrowser(), "|")}, &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, 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"},
&cli.StringFlag{Name: "file-type", Aliases: []string{"ft"}, Destination: &fileType, Value: "csv", Usage: "File Type, bookmark|cookie|history|password|creditcard"},
&cli.StringFlag{Name: "filepath", Destination: &filepath, Value: "csv", Usage: "Filepath of the file type"},
}, },
HideHelpCommand: true, HideHelpCommand: true,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
@ -43,56 +46,35 @@ func Execute() {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
err = utils.MakeDir(exportDir)
browser := browsers[0]
err = browser.InitSecretKey()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
for _, browser := range browsers { item, err := browser.GetItem(fileType)
err := browser.InitSecretKey() if err != nil {
log.Error(err)
}
name := browser.GetName()
key := browser.GetSecretKey()
switch browser.(type) {
case *core.Chromium:
err := item.ChromeParse(key, filepath)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
// default select all items case *core.Firefox:
// you can get single item with browser.GetItem(itemName) err := item.FirefoxParse(filepath)
items, err := browser.GetAllItems()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
name := browser.GetName()
key := browser.GetSecretKey()
for _, item := range items {
err := item.CopyDB()
if err != nil {
log.Error(err)
}
switch browser.(type) {
case *core.Chromium:
err := item.ChromeParse(key)
if err != nil {
log.Error(err)
}
case *core.Firefox:
err := item.FirefoxParse()
if err != nil {
log.Error(err)
}
}
err = item.Release()
if err != nil {
log.Error(err)
}
err = item.OutPut(outputFormat, name, exportDir)
if err != nil {
log.Error(err)
}
}
} }
if compress { err = item.OutPut(outputFormat, name, exportDir)
err = utils.Compress(exportDir) if err != nil {
if err != nil { log.Error(err)
log.Error(err)
}
} }
return nil return nil
}, },
} }

@ -20,19 +20,19 @@ import (
type Item interface { type Item interface {
// ChromeParse parse chrome items, Password and Cookie need secret key // ChromeParse parse chrome items, Password and Cookie need secret key
ChromeParse(key []byte) error ChromeParse(key []byte, filepath string) error
// FirefoxParse parse firefox items // FirefoxParse parse firefox items
FirefoxParse() error FirefoxParse(filepath string) error
// OutPut file name and format type // OutPut file name and format type
OutPut(format, browser, dir string) error OutPut(format, browser, dir string) error
// CopyDB is copy item db file to current dir // CopyDB is copy item db file to current dir
CopyDB() error // CopyDB() error
// Release is delete item db file // Release is delete item db file
Release() error // Release() error
} }
const ( const (
@ -78,8 +78,8 @@ func NewBookmarks(main, sub string) Item {
return &bookmarks{mainPath: main} return &bookmarks{mainPath: main}
} }
func (b *bookmarks) ChromeParse(key []byte) error { func (b *bookmarks) ChromeParse(key []byte, filepath string) error {
bookmarks, err := utils.ReadFile(ChromeBookmarkFile) bookmarks, err := utils.ReadFile(filepath)
if err != nil { if err != nil {
return err return err
} }
@ -115,7 +115,7 @@ func getBookmarkChildren(value gjson.Result, b *bookmarks) (children gjson.Resul
return children return children
} }
func (b *bookmarks) FirefoxParse() error { func (b *bookmarks) FirefoxParse(filepath string) error {
var ( var (
err error err error
keyDB *sql.DB keyDB *sql.DB
@ -123,7 +123,7 @@ func (b *bookmarks) FirefoxParse() error {
tempMap map[int64]string tempMap map[int64]string
bookmarkUrl string bookmarkUrl string
) )
keyDB, err = sql.Open("sqlite3", FirefoxDataFile) keyDB, err = sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -163,13 +163,13 @@ func (b *bookmarks) FirefoxParse() error {
return nil return nil
} }
func (b *bookmarks) CopyDB() error { // func (b *bookmarks) CopyDB() error {
return copyToLocalPath(b.mainPath, filepath.Base(b.mainPath)) // return copyToLocalPath(b.mainPath, filepath.Base(b.mainPath))
} // }
func (b *bookmarks) Release() error { // func (b *bookmarks) Release() error {
return os.Remove(filepath.Base(b.mainPath)) // return os.Remove(filepath.Base(b.mainPath))
} // }
func (b *bookmarks) OutPut(format, browser, dir string) error { func (b *bookmarks) OutPut(format, browser, dir string) error {
sort.Slice(b.bookmarks, func(i, j int) bool { sort.Slice(b.bookmarks, func(i, j int) bool {
@ -197,9 +197,10 @@ func NewCookies(main, sub string) Item {
return &cookies{mainPath: main} return &cookies{mainPath: main}
} }
func (c *cookies) ChromeParse(secretKey []byte) error { // 解析 chrome cookie
func (c *cookies) ChromeParse(secretKey []byte, filepath string) error {
c.cookies = make(map[string][]cookie) c.cookies = make(map[string][]cookie)
cookieDB, err := sql.Open("sqlite3", ChromeCookieFile) cookieDB, err := sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -255,9 +256,9 @@ func (c *cookies) ChromeParse(secretKey []byte) error {
return nil return nil
} }
func (c *cookies) FirefoxParse() error { func (c *cookies) FirefoxParse(filepath string) error {
c.cookies = make(map[string][]cookie) c.cookies = make(map[string][]cookie)
cookieDB, err := sql.Open("sqlite3", FirefoxCookieFile) cookieDB, err := sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -299,13 +300,13 @@ func (c *cookies) FirefoxParse() error {
return nil return nil
} }
func (c *cookies) CopyDB() error { // func (c *cookies) CopyDB() error {
return copyToLocalPath(c.mainPath, filepath.Base(c.mainPath)) // return copyToLocalPath(c.mainPath, filepath.Base(c.mainPath))
} // }
func (c *cookies) Release() error { // func (c *cookies) Release() error {
return os.Remove(filepath.Base(c.mainPath)) // return os.Remove(filepath.Base(c.mainPath))
} // }
func (c *cookies) OutPut(format, browser, dir string) error { func (c *cookies) OutPut(format, browser, dir string) error {
switch format { switch format {
@ -330,8 +331,8 @@ func NewHistoryData(main, sub string) Item {
return &historyData{mainPath: main} return &historyData{mainPath: main}
} }
func (h *historyData) ChromeParse(key []byte) error { func (h *historyData) ChromeParse(key []byte, filepath string) error {
historyDB, err := sql.Open("sqlite3", ChromeHistoryFile) historyDB, err := sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -370,7 +371,7 @@ func (h *historyData) ChromeParse(key []byte) error {
return nil return nil
} }
func (h *historyData) FirefoxParse() error { func (h *historyData) FirefoxParse(filepath string) error {
var ( var (
err error err error
keyDB *sql.DB keyDB *sql.DB
@ -378,7 +379,7 @@ func (h *historyData) FirefoxParse() error {
tempMap map[int64]string tempMap map[int64]string
) )
tempMap = make(map[int64]string) tempMap = make(map[int64]string)
keyDB, err = sql.Open("sqlite3", FirefoxDataFile) keyDB, err = sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -422,13 +423,13 @@ func (h *historyData) FirefoxParse() error {
return nil return nil
} }
func (h *historyData) CopyDB() error { // func (h *historyData) CopyDB() error {
return copyToLocalPath(h.mainPath, filepath.Base(h.mainPath)) // return copyToLocalPath(h.mainPath, filepath.Base(h.mainPath))
} // }
func (h *historyData) Release() error { // func (h *historyData) Release() error {
return os.Remove(filepath.Base(h.mainPath)) // return os.Remove(filepath.Base(h.mainPath))
} // }
func (h *historyData) OutPut(format, browser, dir string) error { func (h *historyData) OutPut(format, browser, dir string) error {
sort.Slice(h.history, func(i, j int) bool { sort.Slice(h.history, func(i, j int) bool {
@ -461,8 +462,8 @@ func NewCPasswords(main, sub string) Item {
return &passwords{mainPath: main} return &passwords{mainPath: main}
} }
func (p *passwords) ChromeParse(key []byte) error { func (p *passwords) ChromeParse(key []byte, filepath string) error {
loginDB, err := sql.Open("sqlite3", ChromePasswordFile) loginDB, err := sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -514,7 +515,7 @@ func (p *passwords) ChromeParse(key []byte) error {
return nil return nil
} }
func (p *passwords) FirefoxParse() error { func (p *passwords) FirefoxParse(filepath string) error {
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey() globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey()
if err != nil { if err != nil {
return err return err
@ -574,27 +575,27 @@ func (p *passwords) FirefoxParse() error {
return nil return nil
} }
func (p *passwords) CopyDB() error { // func (p *passwords) CopyDB() error {
err := copyToLocalPath(p.mainPath, filepath.Base(p.mainPath)) // err := copyToLocalPath(p.mainPath, filepath.Base(p.mainPath))
if err != nil { // if err != nil {
log.Error(err) // log.Error(err)
} // }
if p.subPath != "" { // if p.subPath != "" {
err = copyToLocalPath(p.subPath, filepath.Base(p.subPath)) // err = copyToLocalPath(p.subPath, filepath.Base(p.subPath))
} // }
return err // return err
} // }
func (p *passwords) Release() error { // func (p *passwords) Release() error {
err := os.Remove(filepath.Base(p.mainPath)) // err := os.Remove(filepath.Base(p.mainPath))
if err != nil { // if err != nil {
log.Error(err) // log.Error(err)
} // }
if p.subPath != "" { // if p.subPath != "" {
err = os.Remove(filepath.Base(p.subPath)) // err = os.Remove(filepath.Base(p.subPath))
} // }
return err // return err
} // }
func (p *passwords) OutPut(format, browser, dir string) error { func (p *passwords) OutPut(format, browser, dir string) error {
sort.Sort(p) sort.Sort(p)
@ -620,13 +621,13 @@ func NewCCards(main string, sub string) Item {
return &creditCards{mainPath: main} return &creditCards{mainPath: main}
} }
func (c *creditCards) FirefoxParse() error { func (c *creditCards) FirefoxParse(filepath string) error {
return nil // FireFox does not have a credit card saving feature return nil // FireFox does not have a credit card saving feature
} }
func (c *creditCards) ChromeParse(secretKey []byte) error { func (c *creditCards) ChromeParse(secretKey []byte, filepath string) error {
c.cards = make(map[string][]card) c.cards = make(map[string][]card)
creditDB, err := sql.Open("sqlite3", ChromeCreditFile) creditDB, err := sql.Open("sqlite3", filepath)
if err != nil { if err != nil {
return err return err
} }
@ -673,13 +674,13 @@ func (c *creditCards) ChromeParse(secretKey []byte) error {
return nil return nil
} }
func (c *creditCards) CopyDB() error { // func (c *creditCards) CopyDB() error {
return copyToLocalPath(c.mainPath, filepath.Base(c.mainPath)) // return copyToLocalPath(c.mainPath, filepath.Base(c.mainPath))
} // }
func (c *creditCards) Release() error { // func (c *creditCards) Release() error {
return os.Remove(filepath.Base(c.mainPath)) // return os.Remove(filepath.Base(c.mainPath))
} // }
func (c *creditCards) OutPut(format, browser, dir string) error { func (c *creditCards) OutPut(format, browser, dir string) error {
switch format { switch format {

Loading…
Cancel
Save