diff --git a/cmd/hack-browser-data/main.go b/cmd/hack-browser-data/main.go index b480958..5858317 100644 --- a/cmd/hack-browser-data/main.go +++ b/cmd/hack-browser-data/main.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) } } diff --git a/internal/browingdata/browsingdata.go b/internal/browingdata/browsingdata.go index aeed250..81215f5 100644 --- a/internal/browingdata/browsingdata.go +++ b/internal/browingdata/browsingdata.go @@ -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 } ) diff --git a/internal/browingdata/creditcard.go b/internal/browingdata/creditcard.go index 8ac135e..44a5b02 100644 --- a/internal/browingdata/creditcard.go +++ b/internal/browingdata/creditcard.go @@ -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 } diff --git a/internal/browingdata/password.go b/internal/browingdata/password.go index d4b2110..ba5bf10 100644 --- a/internal/browingdata/password.go +++ b/internal/browingdata/password.go @@ -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, }) } diff --git a/internal/browser/browser.go b/internal/browser/browser.go index 11ee860..4dac386 100644 --- a/internal/browser/browser.go +++ b/internal/browser/browser.go @@ -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) } diff --git a/internal/log/log.go b/internal/log/log.go index 09b302d..b775298 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -13,7 +13,7 @@ func Init(l string) { if l == "debug" { std = newStdLogger(slog.DebugLevel) } else { - std = newStdLogger(slog.ErrorLevel) + std = newStdLogger(slog.NoticeLevel) } } diff --git a/internal/outputter/outputter.go b/internal/outputter/outputter.go index 7548d7d..f74418b 100644 --- a/internal/outputter/outputter.go +++ b/internal/outputter/outputter.go @@ -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" + } +} diff --git a/internal/utils/fileutil/filetutil.go b/internal/utils/fileutil/filetutil.go index 6b7bf60..05957e1 100644 --- a/internal/utils/fileutil/filetutil.go +++ b/internal/utils/fileutil/filetutil.go @@ -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) }