refactor: output browsing data package

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 13c92b0a2e
commit 04e620e54c
  1. 21
      cmd/hack-browser-data/main.go
  2. 25
      internal/browingdata/browsingdata.go
  3. 14
      internal/browingdata/creditcard.go
  4. 4
      internal/browingdata/password.go
  5. 4
      internal/browser/browser.go
  6. 2
      internal/log/log.go
  7. 18
      internal/outputter/outputter.go
  8. 5
      internal/utils/fileutil/filetutil.go

@ -1,13 +1,11 @@
package main package main
import ( import (
"fmt"
"os" "os"
"strings" "strings"
"hack-browser-data/internal/browser" "hack-browser-data/internal/browser"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
"hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -45,7 +43,7 @@ func Execute() {
if verbose { if verbose {
log.Init("debug") log.Init("debug")
} else { } else {
log.Init("error") log.Init("notice")
} }
var ( var (
browsers []browser.Browser browsers []browser.Browser
@ -56,29 +54,16 @@ func Execute() {
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
output := outputter.New(outputFormat)
for _, b := range browsers { for _, b := range browsers {
data, err := b.GetBrowsingData() data, err := b.GetBrowsingData()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
var f *os.File data.Output(outputDir, browserName, outputFormat)
for _, source := range data.Sources {
filename := fmt.Sprintf("%s_%s.%s", b.Name(), source.Name(), outputFormat)
f, err = output.CreateFile(outputDir, filename)
if err != nil {
log.Error(err)
}
err = output.Write(source, f)
if err != nil {
log.Error(err)
}
}
} }
if compress { if compress {
err = fileutil.CompressDir(outputDir) if err = fileutil.CompressDir(outputDir); err != nil {
if err != nil {
log.Error(err) log.Error(err)
} }
} }

@ -1,10 +1,13 @@
package browingdata package browingdata
import ( import (
"path"
"time" "time"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
"hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils/fileutil"
) )
type Data struct { type Data struct {
@ -35,6 +38,24 @@ func (d *Data) Recovery(masterKey []byte) error {
return nil return nil
} }
func (d *Data) Output(dir, browserName, output string) {
outputter := outputter.New(output)
for _, source := range d.Sources {
filename := fileutil.Filename(browserName, source.Name(), outputter.Ext())
f, err := outputter.CreateFile(dir, filename)
if err != nil {
log.Error(err)
}
if err := outputter.Write(source, f); err != nil {
log.Error(err)
}
log.Noticef("output to file %s success", path.Join(dir, filename))
}
}
func (d *Data) addSource(Sources []item.Item) { func (d *Data) addSource(Sources []item.Item) {
for _, source := range Sources { for _, source := range Sources {
switch source { switch source {
@ -69,7 +90,7 @@ func (d *Data) addSource(Sources []item.Item) {
} }
const ( const (
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards` queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, billing_address_id, nickname FROM credit_cards`
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins` queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins` queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls` queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
@ -126,5 +147,7 @@ type (
ExpirationYear string ExpirationYear string
ExpirationMonth string ExpirationMonth string
CardNumber string CardNumber string
Address string
NickName string
} }
) )

@ -27,17 +27,19 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var ( var (
name, month, year, guid string name, month, year, guid, address, nickname string
value, encryptValue []byte value, encryptValue []byte
) )
if err := rows.Scan(&guid, &name, &month, &year, &encryptValue); err != nil { if err := rows.Scan(&guid, &name, &month, &year, &encryptValue, &address, &nickname); err != nil {
log.Warn(err) log.Warn(err)
} }
creditCardInfo := card{ ccInfo := card{
GUID: guid, GUID: guid,
Name: name, Name: name,
ExpirationMonth: month, ExpirationMonth: month,
ExpirationYear: year, ExpirationYear: year,
Address: address,
NickName: nickname,
} }
if masterKey == nil { if masterKey == nil {
value, err = decrypter.DPApi(encryptValue) value, err = decrypter.DPApi(encryptValue)
@ -50,8 +52,8 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
return err return err
} }
} }
creditCardInfo.CardNumber = string(value) ccInfo.CardNumber = string(value)
*c = append(*c, creditCardInfo) *c = append(*c, ccInfo)
} }
return nil return nil
} }

@ -189,8 +189,8 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
} }
*f = append(*f, loginData{ *f = append(*f, loginData{
LoginUrl: v.LoginUrl, LoginUrl: v.LoginUrl,
UserName: string(decrypter.PKCS5UnPadding(user)), UserName: string(user),
Password: string(decrypter.PKCS5UnPadding(pwd)), Password: string(pwd),
CreateDate: v.CreateDate, CreateDate: v.CreateDate,
}) })
} }

@ -85,12 +85,12 @@ func pickFirefox(name, profile string) []Browser {
} }
if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil { if multiFirefox, err := firefox.New(v.name, v.storage, profile, v.items); err == nil {
for _, b := range multiFirefox { for _, b := range multiFirefox {
log.Noticef("find browser: firefox %s success", b.Name()) log.Noticef("find browser firefox %s success", b.Name())
browsers = append(browsers, b) browsers = append(browsers, b)
} }
} else { } else {
if strings.Contains(err.Error(), "profile path is not exist") { if strings.Contains(err.Error(), "profile path is not exist") {
log.Noticef("find browser: firefox %s failed, profile path is not exist", v.name) log.Noticef("find browser firefox %s failed, profile path is not exist", v.name)
} else { } else {
log.Error(err) log.Error(err)
} }

@ -13,7 +13,7 @@ func Init(l string) {
if l == "debug" { if l == "debug" {
std = newStdLogger(slog.DebugLevel) std = newStdLogger(slog.DebugLevel)
} else { } else {
std = newStdLogger(slog.ErrorLevel) std = newStdLogger(slog.NoticeLevel)
} }
} }

@ -13,13 +13,13 @@ import (
"hack-browser-data/internal/browingdata" "hack-browser-data/internal/browingdata"
) )
type outPutter struct { type OutPutter struct {
json bool json bool
csv bool csv bool
} }
func New(flag string) *outPutter { func New(flag string) *OutPutter {
o := &outPutter{} o := &OutPutter{}
if flag == "json" { if flag == "json" {
o.json = true o.json = true
} else { } else {
@ -28,7 +28,7 @@ func New(flag string) *outPutter {
return o return o
} }
func (o *outPutter) Write(data browingdata.Source, writer io.Writer) error { func (o *OutPutter) Write(data browingdata.Source, writer io.Writer) error {
switch o.json { switch o.json {
case true: case true:
encoder := jsoniter.NewEncoder(writer) encoder := jsoniter.NewEncoder(writer)
@ -45,7 +45,7 @@ func (o *outPutter) Write(data browingdata.Source, writer io.Writer) error {
} }
} }
func (o *outPutter) CreateFile(dir, filename string) (*os.File, error) { func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
if filename == "" { if filename == "" {
return nil, errors.New("empty filename") return nil, errors.New("empty filename")
} }
@ -68,3 +68,11 @@ func (o *outPutter) CreateFile(dir, filename string) (*os.File, error) {
} }
return file, nil return file, nil
} }
func (o *OutPutter) Ext() string {
if o.json {
return ".json"
} else {
return ".csv"
}
}

@ -8,6 +8,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
@ -61,6 +62,10 @@ func CopyItemToLocal(itemPaths map[item.Item]string) error {
return nil return nil
} }
func Filename(browser, item, ext string) string {
return strings.ToLower(fmt.Sprintf("%s_%s.%s", browser, item, ext))
}
func ParentDir(p string) string { func ParentDir(p string) string {
return filepath.Dir(p) return filepath.Dir(p)
} }

Loading…
Cancel
Save