feat: update to v0.4.0, based by generics

pull/125/head v0.4.0
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 6217ca3bed
commit aa3326f1a3
  1. 10
      cmd/hack-browser-data/main.go
  2. 7
      internal/browingdata/bookmark/bookmark.go
  3. 107
      internal/browingdata/browsingdata.go
  4. 25
      internal/browingdata/cookie/cookie.go
  5. 29
      internal/browingdata/creditcard/creditcard.go
  6. 21
      internal/browingdata/download/download.go
  7. 19
      internal/browingdata/history/history.go
  8. 76
      internal/browingdata/outputter.go
  9. 4
      internal/browingdata/outputter_test.go
  10. 24
      internal/browingdata/password/password.go
  11. 32
      internal/browser/browser.go
  12. 6
      internal/browser/chromium/chromium.go
  13. 4
      internal/browser/chromium/chromium_linux.go
  14. 10
      internal/browser/firefox/firefox.go
  15. 2
      internal/log/log.go
  16. 9
      internal/utils/fileutil/filetutil.go

@ -28,14 +28,14 @@ func Execute() {
app := &cli.App{ app := &cli.App{
Name: "hack-browser-data", Name: "hack-browser-data",
Usage: "Export passwords/cookies/history/bookmarks from browser", Usage: "Export passwords/cookies/history/bookmarks from browser",
UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nGet all browingdata(password/cookie/history/bookmark) from browser", UsageText: "[hack-browser-data -b chrome -f json -dir results -cc]\nExport all browingdata(password/cookie/history/bookmark) from browser\nGithub Link: https://github.com/moonD4rk/HackBrowserData",
Version: "0.4.0", Version: "0.4.0",
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{"zip"}, Destination: &compress, Value: false, Usage: "compress result to zip"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(browser.ListBrowser(), "|")}, &cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browserName, Value: "all", Usage: "available browsers: all|" + strings.Join(browser.ListBrowser(), "|")},
&cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &outputDir, Value: "results", Usage: "export dir"}, &cli.StringFlag{Name: "results-dir", Aliases: []string{"dir"}, Destination: &outputDir, 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: "file name csv|json"},
&cli.StringFlag{Name: "profile-path", Aliases: []string{"p"}, Destination: &profilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"}, &cli.StringFlag{Name: "profile-path", Aliases: []string{"p"}, Destination: &profilePath, Value: "", Usage: "custom profile dir path, get with chrome://version"},
}, },
HideHelpCommand: true, HideHelpCommand: true,
@ -56,11 +56,11 @@ func Execute() {
} }
for _, b := range browsers { for _, b := range browsers {
data, err := b.GetBrowsingData() data, err := b.BrowsingData()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
data.Output(outputDir, browserName, outputFormat) data.Output(outputDir, b.Name(), outputFormat)
} }
if compress { if compress {
if err = fileutil.CompressDir(outputDir); err != nil { if err = fileutil.CompressDir(outputDir); err != nil {

@ -1,4 +1,4 @@
package browingdata package bookmark
import ( import (
"database/sql" "database/sql"
@ -82,6 +82,11 @@ func (c *ChromiumBookmark) Name() string {
type FirefoxBookmark []bookmark type FirefoxBookmark []bookmark
const (
queryFirefoxBookMark = `SELECT id, url, type, dateAdded, title FROM (SELECT * FROM moz_bookmarks INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id)`
closeJournalMode = `PRAGMA journal_mode=off`
)
func (f *FirefoxBookmark) Parse(masterKey []byte) error { func (f *FirefoxBookmark) Parse(masterKey []byte) error {
var ( var (
err error err error

@ -2,11 +2,15 @@ package browingdata
import ( import (
"path" "path"
"time"
"hack-browser-data/internal/browingdata/bookmark"
"hack-browser-data/internal/browingdata/cookie"
"hack-browser-data/internal/browingdata/creditcard"
"hack-browser-data/internal/browingdata/download"
"hack-browser-data/internal/browingdata/history"
"hack-browser-data/internal/browingdata/password"
"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" "hack-browser-data/internal/utils/fileutil"
) )
@ -38,18 +42,18 @@ func (d *Data) Recovery(masterKey []byte) error {
return nil return nil
} }
func (d *Data) Output(dir, browserName, output string) { func (d *Data) Output(dir, browserName, flag string) {
outputter := outputter.New(output) output := NewOutPutter(flag)
for _, source := range d.Sources { for _, source := range d.Sources {
filename := fileutil.Filename(browserName, source.Name(), outputter.Ext()) filename := fileutil.Filename(browserName, source.Name(), output.Ext())
f, err := outputter.CreateFile(dir, filename) f, err := output.CreateFile(dir, filename)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
if err := outputter.Write(source, f); err != nil { if err := output.Write(source, f); err != nil {
log.Error(err) log.Error(err)
} }
log.Noticef("output to file %s success", path.Join(dir, filename)) log.Noticef("output to file %s success", path.Join(dir, filename))
@ -60,94 +64,31 @@ func (d *Data) addSource(Sources []item.Item) {
for _, source := range Sources { for _, source := range Sources {
switch source { switch source {
case item.ChromiumPassword: case item.ChromiumPassword:
d.Sources[source] = &ChromiumPassword{} d.Sources[source] = &password.ChromiumPassword{}
case item.ChromiumCookie: case item.ChromiumCookie:
d.Sources[source] = &ChromiumCookie{} d.Sources[source] = &cookie.ChromiumCookie{}
case item.ChromiumBookmark: case item.ChromiumBookmark:
d.Sources[source] = &ChromiumBookmark{} d.Sources[source] = &bookmark.ChromiumBookmark{}
case item.ChromiumHistory: case item.ChromiumHistory:
d.Sources[source] = &ChromiumHistory{} d.Sources[source] = &history.ChromiumHistory{}
case item.ChromiumDownload: case item.ChromiumDownload:
d.Sources[source] = &ChromiumDownload{} d.Sources[source] = &download.ChromiumDownload{}
case item.ChromiumCreditCard: case item.ChromiumCreditCard:
d.Sources[source] = &ChromiumCreditCard{} d.Sources[source] = &creditcard.ChromiumCreditCard{}
case item.YandexPassword: case item.YandexPassword:
d.Sources[source] = &YandexPassword{} d.Sources[source] = &password.YandexPassword{}
case item.YandexCreditCard: case item.YandexCreditCard:
d.Sources[source] = &YandexCreditCard{} d.Sources[source] = &creditcard.YandexCreditCard{}
case item.FirefoxPassword: case item.FirefoxPassword:
d.Sources[source] = &FirefoxPassword{} d.Sources[source] = &password.FirefoxPassword{}
case item.FirefoxCookie: case item.FirefoxCookie:
d.Sources[source] = &FirefoxCookie{} d.Sources[source] = &cookie.FirefoxCookie{}
case item.FirefoxBookmark: case item.FirefoxBookmark:
d.Sources[source] = &FirefoxBookmark{} d.Sources[source] = &bookmark.FirefoxBookmark{}
case item.FirefoxHistory: case item.FirefoxHistory:
d.Sources[source] = &FirefoxHistory{} d.Sources[source] = &history.FirefoxHistory{}
case item.FirefoxDownload: case item.FirefoxDownload:
d.Sources[source] = &FirefoxDownload{} d.Sources[source] = &download.FirefoxDownload{}
} }
} }
} }
const (
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`
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places where title not null`
queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content), url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id`
queryFirefoxBookMark = `SELECT id, url, type, dateAdded, title FROM (SELECT * FROM moz_bookmarks INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id)`
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
closeJournalMode = `PRAGMA journal_mode=off`
)
type (
loginData struct {
UserName string
encryptPass []byte
encryptUser []byte
Password string
LoginUrl string
CreateDate time.Time
}
cookie struct {
Host string
Path string
KeyName string
encryptValue []byte
Value string
IsSecure bool
IsHTTPOnly bool
HasExpire bool
IsPersistent bool
CreateDate time.Time
ExpireDate time.Time
}
history struct {
Title string
Url string
VisitCount int
LastVisitTime time.Time
}
download struct {
TargetPath string
Url string
TotalBytes int64
StartTime time.Time
EndTime time.Time
MimeType string
}
card struct {
GUID string
Name string
ExpirationYear string
ExpirationMonth string
CardNumber string
Address string
NickName string
}
)

@ -1,9 +1,10 @@
package browingdata package cookie
import ( import (
"database/sql" "database/sql"
"os" "os"
"sort" "sort"
"time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -15,6 +16,24 @@ import (
type ChromiumCookie []cookie type ChromiumCookie []cookie
type cookie struct {
Host string
Path string
KeyName string
encryptValue []byte
Value string
IsSecure bool
IsHTTPOnly bool
HasExpire bool
IsPersistent bool
CreateDate time.Time
ExpireDate time.Time
}
const (
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
)
func (c *ChromiumCookie) Parse(masterKey []byte) error { func (c *ChromiumCookie) Parse(masterKey []byte) error {
cookieDB, err := sql.Open("sqlite3", item.TempChromiumCookie) cookieDB, err := sql.Open("sqlite3", item.TempChromiumCookie)
if err != nil { if err != nil {
@ -77,6 +96,10 @@ func (c *ChromiumCookie) Name() string {
type FirefoxCookie []cookie type FirefoxCookie []cookie
const (
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
)
func (f *FirefoxCookie) Parse(masterKey []byte) error { func (f *FirefoxCookie) Parse(masterKey []byte) error {
cookieDB, err := sql.Open("sqlite3", item.TempFirefoxCookie) cookieDB, err := sql.Open("sqlite3", item.TempFirefoxCookie)
if err != nil { if err != nil {

@ -1,4 +1,4 @@
package browingdata package creditcard
import ( import (
"database/sql" "database/sql"
@ -13,6 +13,20 @@ import (
type ChromiumCreditCard []card type ChromiumCreditCard []card
type card struct {
GUID string
Name string
ExpirationYear string
ExpirationMonth string
CardNumber string
Address string
NickName string
}
const (
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, billing_address_id, nickname FROM credit_cards`
)
func (c *ChromiumCreditCard) Parse(masterKey []byte) error { func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
creditDB, err := sql.Open("sqlite3", item.TempChromiumCreditCard) creditDB, err := sql.Open("sqlite3", item.TempChromiumCreditCard)
if err != nil { if err != nil {
@ -70,6 +84,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
} }
defer os.Remove(item.TempYandexCreditCard) defer os.Remove(item.TempYandexCreditCard)
defer creditDB.Close() defer creditDB.Close()
defer creditDB.Close()
rows, err := creditDB.Query(queryChromiumCredit) rows, err := creditDB.Query(queryChromiumCredit)
if err != nil { if err != nil {
return err return err
@ -77,17 +92,19 @@ func (c *YandexCreditCard) 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)
@ -100,8 +117,8 @@ func (c *YandexCreditCard) 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
} }

@ -1,10 +1,11 @@
package browingdata package download
import ( import (
"database/sql" "database/sql"
"os" "os"
"sort" "sort"
"strings" "strings"
"time"
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
@ -16,6 +17,19 @@ import (
type ChromiumDownload []download type ChromiumDownload []download
type download struct {
TargetPath string
Url string
TotalBytes int64
StartTime time.Time
EndTime time.Time
MimeType string
}
const (
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
)
func (c *ChromiumDownload) Parse(masterKey []byte) error { func (c *ChromiumDownload) Parse(masterKey []byte) error {
historyDB, err := sql.Open("sqlite3", item.TempChromiumDownload) historyDB, err := sql.Open("sqlite3", item.TempChromiumDownload)
if err != nil { if err != nil {
@ -58,6 +72,11 @@ func (c *ChromiumDownload) Name() string {
type FirefoxDownload []download type FirefoxDownload []download
const (
queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content), url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id`
closeJournalMode = `PRAGMA journal_mode=off`
)
func (f *FirefoxDownload) Parse(masterKey []byte) error { func (f *FirefoxDownload) Parse(masterKey []byte) error {
var ( var (
err error err error

@ -1,9 +1,10 @@
package browingdata package history
import ( import (
"database/sql" "database/sql"
"os" "os"
"sort" "sort"
"time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -14,6 +15,17 @@ import (
type ChromiumHistory []history type ChromiumHistory []history
type history struct {
Title string
Url string
VisitCount int
LastVisitTime time.Time
}
const (
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
)
func (c *ChromiumHistory) Parse(masterKey []byte) error { func (c *ChromiumHistory) Parse(masterKey []byte) error {
historyDB, err := sql.Open("sqlite3", item.TempChromiumHistory) historyDB, err := sql.Open("sqlite3", item.TempChromiumHistory)
if err != nil { if err != nil {
@ -56,6 +68,11 @@ func (c *ChromiumHistory) Name() string {
type FirefoxHistory []history type FirefoxHistory []history
const (
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places where title not null`
closeJournalMode = `PRAGMA journal_mode=off`
)
func (f *FirefoxHistory) Parse(masterKey []byte) error { func (f *FirefoxHistory) Parse(masterKey []byte) error {
var ( var (
err error err error

@ -0,0 +1,76 @@
package browingdata
import (
"encoding/csv"
"errors"
"io"
"os"
"path/filepath"
"github.com/gocarina/gocsv"
jsoniter "github.com/json-iterator/go"
)
type OutPutter struct {
json bool
csv bool
}
func NewOutPutter(flag string) *OutPutter {
o := &OutPutter{}
if flag == "json" {
o.json = true
} else {
o.csv = true
}
return o
}
func (o *OutPutter) Write(data Source, writer io.Writer) error {
switch o.json {
case true:
encoder := jsoniter.NewEncoder(writer)
encoder.SetIndent(" ", " ")
encoder.SetEscapeHTML(false)
return encoder.Encode(data)
default:
gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter {
writer := csv.NewWriter(w)
writer.Comma = ','
return gocsv.NewSafeCSVWriter(writer)
})
return gocsv.Marshal(data, writer)
}
}
func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
if filename == "" {
return nil, errors.New("empty filename")
}
if dir != "" {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0777)
if err != nil {
return nil, err
}
}
}
var file *os.File
var err error
p := filepath.Join(dir, filename)
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
return file, nil
}
func (o *OutPutter) Ext() string {
if o.json {
return "json"
} else {
return "csv"
}
}

@ -1,4 +1,4 @@
package outputter package browingdata
import ( import (
"os" "os"
@ -6,7 +6,7 @@ import (
) )
func TestNewOutPutter(t *testing.T) { func TestNewOutPutter(t *testing.T) {
out := New("json") out := NewOutPutter("json")
if out == nil { if out == nil {
t.Error("New() returned nil") t.Error("New() returned nil")
} }

@ -1,4 +1,4 @@
package browingdata package password
import ( import (
"bytes" "bytes"
@ -20,6 +20,19 @@ import (
type ChromiumPassword []loginData type ChromiumPassword []loginData
type loginData struct {
UserName string
encryptPass []byte
encryptUser []byte
Password string
LoginUrl string
CreateDate time.Time
}
const (
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
)
func (c *ChromiumPassword) Parse(masterKey []byte) error { func (c *ChromiumPassword) Parse(masterKey []byte) error {
loginDB, err := sql.Open("sqlite3", item.TempChromiumPassword) loginDB, err := sql.Open("sqlite3", item.TempChromiumPassword)
if err != nil { if err != nil {
@ -79,6 +92,10 @@ func (c *ChromiumPassword) Name() string {
type YandexPassword []loginData type YandexPassword []loginData
const (
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
)
func (c *YandexPassword) Parse(masterKey []byte) error { func (c *YandexPassword) Parse(masterKey []byte) error {
loginDB, err := sql.Open("sqlite3", item.TempYandexPassword) loginDB, err := sql.Open("sqlite3", item.TempYandexPassword)
if err != nil { if err != nil {
@ -139,6 +156,11 @@ func (c *YandexPassword) Name() string {
type FirefoxPassword []loginData type FirefoxPassword []loginData
const (
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
)
func (f *FirefoxPassword) Parse(masterKey []byte) error { func (f *FirefoxPassword) Parse(masterKey []byte) error {
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4) globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4)
if err != nil { if err != nil {

@ -9,14 +9,14 @@ import (
"hack-browser-data/internal/browser/firefox" "hack-browser-data/internal/browser/firefox"
"hack-browser-data/internal/log" "hack-browser-data/internal/log"
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
"hack-browser-data/internal/utils/typeutil"
) )
type Browser interface { type Browser interface {
// Name is browser's name
Name() string Name() string
// BrowsingData returns all browsing data in the browser.
GetMasterKey() ([]byte, error) BrowsingData() (*browingdata.Data, error)
// GetBrowsingData returns the browsing data for the browser.
GetBrowsingData() (*browingdata.Data, error)
} }
func PickBrowser(name, profile string) ([]Browser, error) { func PickBrowser(name, profile string) ([]Browser, error) {
@ -47,11 +47,11 @@ func pickChromium(name, profile string) []Browser {
browsers = append(browsers, b) browsers = append(browsers, b)
} else { } else {
// TODO: show which browser find failed // TODO: show which browser find failed
if strings.Contains(err.Error(), "profile path is not exist") { if strings.Contains(err.Error(), "profile folder is not exist") {
log.Infof("find browser %s failed, profile path is not exist", v.name) log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name)
continue continue
} else { } else {
log.Error("new chromium error:", err) log.Errorf("new chromium error:", err)
} }
} }
} }
@ -62,10 +62,10 @@ func pickChromium(name, profile string) []Browser {
} }
b, err := chromium.New(c.name, c.storage, profile, c.items) b, err := chromium.New(c.name, c.storage, profile, c.items)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "profile path is not exist") { if strings.Contains(err.Error(), "profile folder is not exist") {
log.Infof("find browser %s failed, profile path is not exist", c.name) log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name)
} else { } else {
log.Error("new chromium error:", err) log.Fatalf("new chromium error:", err)
} }
} }
browsers = append(browsers, b) browsers = append(browsers, b)
@ -89,8 +89,8 @@ func pickFirefox(name, profile string) []Browser {
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 folder is not exist") {
log.Noticef("find browser firefox %s failed, profile path is not exist", v.name) log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
} else { } else {
log.Error(err) log.Error(err)
} }
@ -104,12 +104,8 @@ func pickFirefox(name, profile string) []Browser {
func ListBrowser() []string { func ListBrowser() []string {
var l []string var l []string
for c := range chromiumList { l = append(l, typeutil.Keys(chromiumList)...)
l = append(l, c) l = append(l, typeutil.Keys(firefoxList)...)
}
for f := range firefoxList {
l = append(l, f)
}
return l return l
} }

@ -30,7 +30,7 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
} }
// TODO: Handle file path is not exist // TODO: Handle file path is not exist
if !fileutil.FolderExists(profilePath) { if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath) return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
} }
itemsPaths, err := c.getItemPath(profilePath, items) itemsPaths, err := c.getItemPath(profilePath, items)
if err != nil { if err != nil {
@ -46,7 +46,7 @@ func (c *chromium) Name() string {
return c.name return c.name
} }
func (c *chromium) GetBrowsingData() (*browingdata.Data, error) { func (c *chromium) BrowsingData() (*browingdata.Data, error) {
b := browingdata.New(c.items) b := browingdata.New(c.items)
if err := c.copyItemToLocal(); err != nil { if err := c.copyItemToLocal(); err != nil {
@ -72,7 +72,7 @@ func (c *chromium) copyItemToLocal() error {
// TODO: Handle read file error // TODO: Handle read file error
d, err := ioutil.ReadFile(path) d, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
fmt.Println(err.Error()) return err
} }
err = ioutil.WriteFile(filename, d, 0777) err = ioutil.WriteFile(filename, d, 0777)
if err != nil { if err != nil {

@ -2,6 +2,7 @@ package chromium
import ( import (
"crypto/sha1" "crypto/sha1"
"errors"
"os" "os"
"github.com/godbus/dbus/v5" "github.com/godbus/dbus/v5"
@ -49,8 +50,7 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
if label == c.storage { if label == c.storage {
se, err := i.GetSecret(session.Path()) se, err := i.GetSecret(session.Path())
if err != nil { if err != nil {
log.Error(err) return nil, errors.New("get storage from dbus error:" + err.Error())
return nil, err
} }
chromiumSecret = se.Value chromiumSecret = se.Value
} }

@ -26,7 +26,7 @@ type firefox struct {
// New returns a new firefox instance. // New returns a new firefox instance.
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) { func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
if !fileutil.FolderExists(profilePath) { if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath) return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
} }
f := &firefox{ f := &firefox{
name: name, name: name,
@ -36,7 +36,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
} }
multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items) multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "profile path is not exist") { if strings.Contains(err.Error(), "profile folder is not exist") {
log.Error(err) log.Error(err)
return nil, nil return nil, nil
} }
@ -45,7 +45,7 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
var firefoxList []*firefox var firefoxList []*firefox
for name, itemPaths := range multiItemPaths { for name, itemPaths := range multiItemPaths {
firefoxList = append(firefoxList, &firefox{ firefoxList = append(firefoxList, &firefox{
name: name, name: fmt.Sprintf("firefox-%s", name),
items: typeutil.Keys(itemPaths), items: typeutil.Keys(itemPaths),
itemPaths: itemPaths, itemPaths: itemPaths,
}) })
@ -66,7 +66,7 @@ func (f *firefox) copyItemToLocal() error {
// TODO: Handle read file error // TODO: Handle read file error
d, err := ioutil.ReadFile(path) d, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
fmt.Println(err.Error()) return err
} }
err = ioutil.WriteFile(filename, d, 0777) err = ioutil.WriteFile(filename, d, 0777)
if err != nil { if err != nil {
@ -100,7 +100,7 @@ func (f *firefox) Name() string {
return f.name return f.name
} }
func (f *firefox) GetBrowsingData() (*browingdata.Data, error) { func (f *firefox) BrowsingData() (*browingdata.Data, error) {
b := browingdata.New(f.items) b := browingdata.New(f.items)
if err := f.copyItemToLocal(); err != nil { if err := f.copyItemToLocal(); err != nil {

@ -17,7 +17,7 @@ func Init(l string) {
} }
} }
const template = "hack-browser-data [{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n" const template = "[{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n"
// NewStdLogger instance // NewStdLogger instance
func newStdLogger(level slog.Level) *slog.SugaredLogger { func newStdLogger(level slog.Level) *slog.SugaredLogger {

@ -52,7 +52,7 @@ func CopyItemToLocal(itemPaths map[item.Item]string) error {
// TODO: Handle read file error // TODO: Handle read file error
d, err := ioutil.ReadFile(p) d, err := ioutil.ReadFile(p)
if err != nil { if err != nil {
fmt.Println(err.Error()) log.Error(err.Error())
} }
err = ioutil.WriteFile(filename, d, 0777) err = ioutil.WriteFile(filename, d, 0777)
if err != nil { if err != nil {
@ -63,7 +63,8 @@ func CopyItemToLocal(itemPaths map[item.Item]string) error {
} }
func Filename(browser, item, ext string) string { func Filename(browser, item, ext string) string {
return strings.ToLower(fmt.Sprintf("%s_%s.%s", browser, item, ext)) replace := strings.NewReplacer(" ", "_", ".", "_", "-", "_")
return strings.ToLower(fmt.Sprintf("%s_%s.%s", replace.Replace(browser), item, ext))
} }
func ParentDir(p string) string { func ParentDir(p string) string {
@ -106,7 +107,7 @@ func CompressDir(dir string) error {
if err := zw.Close(); err != nil { if err := zw.Close(); err != nil {
return err return err
} }
filename := filepath.Join(dir, "archive.zip") filename := filepath.Join(dir, fmt.Sprintf("%s.zip", dir))
outFile, err := os.Create(filename) outFile, err := os.Create(filename)
if err != nil { if err != nil {
return err return err
@ -115,6 +116,6 @@ func CompressDir(dir string) error {
if err != nil { if err != nil {
return err return err
} }
log.Debugf("Compress success, zip filename is %s", filename) log.Noticef("compress success, zip filename is %s", filename)
return nil return nil
} }

Loading…
Cancel
Save