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
import (
"fmt"
"os"
"strings"
"hack-browser-data/internal/browser"
"hack-browser-data/internal/log"
"hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils/fileutil"
"github.com/urfave/cli/v2"
@ -45,7 +43,7 @@ func Execute() {
if verbose {
log.Init("debug")
} else {
log.Init("error")
log.Init("notice")
}
var (
browsers []browser.Browser
@ -56,29 +54,16 @@ func Execute() {
if err != nil {
log.Error(err)
}
output := outputter.New(outputFormat)
for _, b := range browsers {
data, err := b.GetBrowsingData()
if err != nil {
log.Error(err)
}
var f *os.File
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)
}
}
data.Output(outputDir, browserName, outputFormat)
}
if compress {
err = fileutil.CompressDir(outputDir)
if err != nil {
if err = fileutil.CompressDir(outputDir); err != nil {
log.Error(err)
}
}

@ -1,10 +1,13 @@
package browingdata
import (
"path"
"time"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
"hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils/fileutil"
)
type Data struct {
@ -35,6 +38,24 @@ func (d *Data) Recovery(masterKey []byte) error {
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) {
for _, source := range Sources {
switch source {
@ -69,7 +90,7 @@ func (d *Data) addSource(Sources []item.Item) {
}
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`
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
@ -126,5 +147,7 @@ type (
ExpirationYear string
ExpirationMonth string
CardNumber string
Address string
NickName string
}
)

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

@ -189,8 +189,8 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
}
*f = append(*f, loginData{
LoginUrl: v.LoginUrl,
UserName: string(decrypter.PKCS5UnPadding(user)),
Password: string(decrypter.PKCS5UnPadding(pwd)),
UserName: string(user),
Password: string(pwd),
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 {
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)
}
} else {
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 {
log.Error(err)
}

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

@ -13,13 +13,13 @@ import (
"hack-browser-data/internal/browingdata"
)
type outPutter struct {
type OutPutter struct {
json bool
csv bool
}
func New(flag string) *outPutter {
o := &outPutter{}
func New(flag string) *OutPutter {
o := &OutPutter{}
if flag == "json" {
o.json = true
} else {
@ -28,7 +28,7 @@ func New(flag string) *outPutter {
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 {
case true:
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 == "" {
return nil, errors.New("empty filename")
}
@ -68,3 +68,11 @@ func (o *outPutter) CreateFile(dir, filename string) (*os.File, error) {
}
return file, nil
}
func (o *OutPutter) Ext() string {
if o.json {
return ".json"
} else {
return ".csv"
}
}

@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
@ -61,6 +62,10 @@ func CopyItemToLocal(itemPaths map[item.Item]string) error {
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 {
return filepath.Dir(p)
}

Loading…
Cancel
Save