mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-08-09 23:24:23 +02:00
refactor: Optimize traversal browser data logic (#311)
* refactor: Refactor package names and imports for better code organization. * refactor: Package imports and variable types for consistency * chore: Disable unused-parameter rule in revive. * refactor: Refactor and organize data extraction and browserdata parse. * fix: rename wrong error message info
This commit is contained in:
+3
-3
@@ -191,9 +191,9 @@ results/
|
|||||||
|
|
||||||
hack-browser-data
|
hack-browser-data
|
||||||
!/cmd/hack-browser-data
|
!/cmd/hack-browser-data
|
||||||
!/browsingdata/history
|
!/browserdata/history
|
||||||
!/browsingdata/history/history.go
|
!/browserdata/history/history.go
|
||||||
!/browsingdata/history/history_test.go
|
!/browserdata/history/history_test.go
|
||||||
|
|
||||||
# github action
|
# github action
|
||||||
!/.github/workflows/unittest.yml
|
!/.github/workflows/unittest.yml
|
||||||
|
|||||||
+24
-20
@@ -1,7 +1,5 @@
|
|||||||
run:
|
run:
|
||||||
timeout: '5m'
|
timeout: '5m'
|
||||||
skip-dirs:
|
|
||||||
- 'assets'
|
|
||||||
allow-parallel-runners: true
|
allow-parallel-runners: true
|
||||||
modules-download-mode: 'readonly'
|
modules-download-mode: 'readonly'
|
||||||
|
|
||||||
@@ -96,6 +94,8 @@ issues:
|
|||||||
- path: browser/browser\.go
|
- path: browser/browser\.go
|
||||||
linters:
|
linters:
|
||||||
- 'unused'
|
- 'unused'
|
||||||
|
exclude-dirs:
|
||||||
|
- 'vendor'
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
|
|
||||||
@@ -194,16 +194,16 @@ linters-settings:
|
|||||||
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`.
|
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`.
|
||||||
# By default, list of stable checks is used.
|
# By default, list of stable checks is used.
|
||||||
enabled-checks:
|
enabled-checks:
|
||||||
- nestingReduce
|
# - nestingReduce
|
||||||
- unnamedResult
|
# - unnamedResult
|
||||||
- ruleguard
|
- ruleguard
|
||||||
- captLocal
|
# - captLocal
|
||||||
- elseif
|
# - elseif
|
||||||
- ifElseChain
|
# - ifElseChain
|
||||||
- rangeExprCopy
|
- rangeExprCopy
|
||||||
- tooManyResultsChecker
|
# - tooManyResultsChecker
|
||||||
- truncateCmp
|
# - truncateCmp
|
||||||
- underef
|
# - underef
|
||||||
# Which checks should be disabled; can't be combined with 'enabled-checks'.
|
# Which checks should be disabled; can't be combined with 'enabled-checks'.
|
||||||
# Default: []
|
# Default: []
|
||||||
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
||||||
@@ -211,16 +211,16 @@ linters-settings:
|
|||||||
# Default: []
|
# Default: []
|
||||||
enabled-tags:
|
enabled-tags:
|
||||||
- diagnostic
|
- diagnostic
|
||||||
- style
|
# - style
|
||||||
- performance
|
# - performance
|
||||||
- experimental
|
# - experimental
|
||||||
- opinionated
|
|
||||||
disabled-tags:
|
|
||||||
- diagnostic
|
|
||||||
- style
|
|
||||||
- performance
|
|
||||||
- experimental
|
|
||||||
- opinionated
|
- opinionated
|
||||||
|
# disabled-tags:
|
||||||
|
# - diagnostic
|
||||||
|
# - style
|
||||||
|
# - performance
|
||||||
|
# - experimental
|
||||||
|
# - opinionated
|
||||||
# Settings passed to gocritic.
|
# Settings passed to gocritic.
|
||||||
# The settings key is the name of a supported gocritic checker.
|
# The settings key is the name of a supported gocritic checker.
|
||||||
# The list of supported checkers can be find in https://go-critic.github.io/overview.
|
# The list of supported checkers can be find in https://go-critic.github.io/overview.
|
||||||
@@ -357,4 +357,8 @@ linters-settings:
|
|||||||
constant-kind: true
|
constant-kind: true
|
||||||
# DEPRECATED Suggest the use of syslog.Priority.
|
# DEPRECATED Suggest the use of syslog.Priority.
|
||||||
# Default: false
|
# Default: false
|
||||||
syslog-priority: true
|
syslog-priority: true
|
||||||
|
revive:
|
||||||
|
rules:
|
||||||
|
- name: unused-parameter
|
||||||
|
disabled: true
|
||||||
|
|||||||
+5
-5
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
"github.com/moond4rk/hackbrowserdata/browser/chromium"
|
||||||
"github.com/moond4rk/hackbrowserdata/browser/firefox"
|
"github.com/moond4rk/hackbrowserdata/browser/firefox"
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata"
|
"github.com/moond4rk/hackbrowserdata/browserdata"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,7 @@ type Browser interface {
|
|||||||
// Name is browser's name
|
// Name is browser's name
|
||||||
Name() string
|
Name() string
|
||||||
// BrowsingData returns all browsing data in the browser.
|
// BrowsingData returns all browsing data in the browser.
|
||||||
BrowsingData(isFullExport bool) (*browsingdata.Data, error)
|
BrowsingData(isFullExport bool) (*browserdata.BrowserData, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PickBrowsers returns a list of browsers that match the name and profile.
|
// PickBrowsers returns a list of browsers that match the name and profile.
|
||||||
@@ -47,7 +47,7 @@ func pickChromium(name, profile string) []Browser {
|
|||||||
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
|
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.items)
|
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.dataTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("new chromium error", "err", err)
|
slog.Error("new chromium error", "err", err)
|
||||||
continue
|
continue
|
||||||
@@ -65,7 +65,7 @@ func pickChromium(name, profile string) []Browser {
|
|||||||
if !fileutil.IsDirExists(filepath.Clean(profile)) {
|
if !fileutil.IsDirExists(filepath.Clean(profile)) {
|
||||||
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
|
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
|
||||||
}
|
}
|
||||||
chromiumList, err := chromium.New(c.name, c.storage, profile, c.items)
|
chromiumList, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("new chromium error", "err", err)
|
slog.Error("new chromium error", "err", err)
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ func pickFirefox(name, profile string) []Browser {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if multiFirefox, err := firefox.New(profile, v.items); err == nil {
|
if multiFirefox, err := firefox.New(profile, v.dataTypes); err == nil {
|
||||||
for _, b := range multiFirefox {
|
for _, b := range multiFirefox {
|
||||||
slog.Warn("find browser success", "browser", b.Name())
|
slog.Warn("find browser success", "browser", b.Name())
|
||||||
browsers = append(browsers, b)
|
browsers = append(browsers, b)
|
||||||
|
|||||||
+15
-15
@@ -3,7 +3,7 @@
|
|||||||
package browser
|
package browser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -11,85 +11,85 @@ var (
|
|||||||
name string
|
name string
|
||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"chrome": {
|
"chrome": {
|
||||||
name: chromeName,
|
name: chromeName,
|
||||||
storage: chromeStorageName,
|
storage: chromeStorageName,
|
||||||
profilePath: chromeProfilePath,
|
profilePath: chromeProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"edge": {
|
"edge": {
|
||||||
name: edgeName,
|
name: edgeName,
|
||||||
storage: edgeStorageName,
|
storage: edgeStorageName,
|
||||||
profilePath: edgeProfilePath,
|
profilePath: edgeProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chromium": {
|
"chromium": {
|
||||||
name: chromiumName,
|
name: chromiumName,
|
||||||
storage: chromiumStorageName,
|
storage: chromiumStorageName,
|
||||||
profilePath: chromiumProfilePath,
|
profilePath: chromiumProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chrome-beta": {
|
"chrome-beta": {
|
||||||
name: chromeBetaName,
|
name: chromeBetaName,
|
||||||
storage: chromeBetaStorageName,
|
storage: chromeBetaStorageName,
|
||||||
profilePath: chromeBetaProfilePath,
|
profilePath: chromeBetaProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"opera": {
|
"opera": {
|
||||||
name: operaName,
|
name: operaName,
|
||||||
profilePath: operaProfilePath,
|
profilePath: operaProfilePath,
|
||||||
storage: operaStorageName,
|
storage: operaStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"opera-gx": {
|
"opera-gx": {
|
||||||
name: operaGXName,
|
name: operaGXName,
|
||||||
profilePath: operaGXProfilePath,
|
profilePath: operaGXProfilePath,
|
||||||
storage: operaStorageName,
|
storage: operaStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"vivaldi": {
|
"vivaldi": {
|
||||||
name: vivaldiName,
|
name: vivaldiName,
|
||||||
storage: vivaldiStorageName,
|
storage: vivaldiStorageName,
|
||||||
profilePath: vivaldiProfilePath,
|
profilePath: vivaldiProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"coccoc": {
|
"coccoc": {
|
||||||
name: coccocName,
|
name: coccocName,
|
||||||
storage: coccocStorageName,
|
storage: coccocStorageName,
|
||||||
profilePath: coccocProfilePath,
|
profilePath: coccocProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"brave": {
|
"brave": {
|
||||||
name: braveName,
|
name: braveName,
|
||||||
profilePath: braveProfilePath,
|
profilePath: braveProfilePath,
|
||||||
storage: braveStorageName,
|
storage: braveStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"yandex": {
|
"yandex": {
|
||||||
name: yandexName,
|
name: yandexName,
|
||||||
storage: yandexStorageName,
|
storage: yandexStorageName,
|
||||||
profilePath: yandexProfilePath,
|
profilePath: yandexProfilePath,
|
||||||
items: item.DefaultYandex,
|
dataTypes: types.DefaultYandexTypes,
|
||||||
},
|
},
|
||||||
"arc": {
|
"arc": {
|
||||||
name: arcName,
|
name: arcName,
|
||||||
profilePath: arcProfilePath,
|
profilePath: arcProfilePath,
|
||||||
storage: arcStorageName,
|
storage: arcStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
firefoxList = map[string]struct {
|
firefoxList = map[string]struct {
|
||||||
name string
|
name string
|
||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"firefox": {
|
"firefox": {
|
||||||
name: firefoxName,
|
name: firefoxName,
|
||||||
profilePath: firefoxProfilePath,
|
profilePath: firefoxProfilePath,
|
||||||
items: item.DefaultFirefox,
|
dataTypes: types.DefaultFirefoxTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+11
-11
@@ -3,7 +3,7 @@
|
|||||||
package browser
|
package browser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -11,61 +11,61 @@ var (
|
|||||||
name string
|
name string
|
||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"chrome": {
|
"chrome": {
|
||||||
name: chromeName,
|
name: chromeName,
|
||||||
storage: chromeStorageName,
|
storage: chromeStorageName,
|
||||||
profilePath: chromeProfilePath,
|
profilePath: chromeProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"edge": {
|
"edge": {
|
||||||
name: edgeName,
|
name: edgeName,
|
||||||
storage: edgeStorageName,
|
storage: edgeStorageName,
|
||||||
profilePath: edgeProfilePath,
|
profilePath: edgeProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chromium": {
|
"chromium": {
|
||||||
name: chromiumName,
|
name: chromiumName,
|
||||||
storage: chromiumStorageName,
|
storage: chromiumStorageName,
|
||||||
profilePath: chromiumProfilePath,
|
profilePath: chromiumProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chrome-beta": {
|
"chrome-beta": {
|
||||||
name: chromeBetaName,
|
name: chromeBetaName,
|
||||||
storage: chromeBetaStorageName,
|
storage: chromeBetaStorageName,
|
||||||
profilePath: chromeBetaProfilePath,
|
profilePath: chromeBetaProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"opera": {
|
"opera": {
|
||||||
name: operaName,
|
name: operaName,
|
||||||
profilePath: operaProfilePath,
|
profilePath: operaProfilePath,
|
||||||
storage: operaStorageName,
|
storage: operaStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"vivaldi": {
|
"vivaldi": {
|
||||||
name: vivaldiName,
|
name: vivaldiName,
|
||||||
storage: vivaldiStorageName,
|
storage: vivaldiStorageName,
|
||||||
profilePath: vivaldiProfilePath,
|
profilePath: vivaldiProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"brave": {
|
"brave": {
|
||||||
name: braveName,
|
name: braveName,
|
||||||
profilePath: braveProfilePath,
|
profilePath: braveProfilePath,
|
||||||
storage: braveStorageName,
|
storage: braveStorageName,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
firefoxList = map[string]struct {
|
firefoxList = map[string]struct {
|
||||||
name string
|
name string
|
||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"firefox": {
|
"firefox": {
|
||||||
name: firefoxName,
|
name: firefoxName,
|
||||||
profilePath: firefoxProfilePath,
|
profilePath: firefoxProfilePath,
|
||||||
items: item.DefaultFirefox,
|
dataTypes: types.DefaultFirefoxTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+18
-18
@@ -3,7 +3,7 @@
|
|||||||
package browser
|
package browser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -11,89 +11,89 @@ var (
|
|||||||
name string
|
name string
|
||||||
profilePath string
|
profilePath string
|
||||||
storage string
|
storage string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"chrome": {
|
"chrome": {
|
||||||
name: chromeName,
|
name: chromeName,
|
||||||
profilePath: chromeUserDataPath,
|
profilePath: chromeUserDataPath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"edge": {
|
"edge": {
|
||||||
name: edgeName,
|
name: edgeName,
|
||||||
profilePath: edgeProfilePath,
|
profilePath: edgeProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chromium": {
|
"chromium": {
|
||||||
name: chromiumName,
|
name: chromiumName,
|
||||||
profilePath: chromiumUserDataPath,
|
profilePath: chromiumUserDataPath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"chrome-beta": {
|
"chrome-beta": {
|
||||||
name: chromeBetaName,
|
name: chromeBetaName,
|
||||||
profilePath: chromeBetaUserDataPath,
|
profilePath: chromeBetaUserDataPath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"opera": {
|
"opera": {
|
||||||
name: operaName,
|
name: operaName,
|
||||||
profilePath: operaProfilePath,
|
profilePath: operaProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"opera-gx": {
|
"opera-gx": {
|
||||||
name: operaGXName,
|
name: operaGXName,
|
||||||
profilePath: operaGXProfilePath,
|
profilePath: operaGXProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"vivaldi": {
|
"vivaldi": {
|
||||||
name: vivaldiName,
|
name: vivaldiName,
|
||||||
profilePath: vivaldiProfilePath,
|
profilePath: vivaldiProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"coccoc": {
|
"coccoc": {
|
||||||
name: coccocName,
|
name: coccocName,
|
||||||
profilePath: coccocProfilePath,
|
profilePath: coccocProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"brave": {
|
"brave": {
|
||||||
name: braveName,
|
name: braveName,
|
||||||
profilePath: braveProfilePath,
|
profilePath: braveProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"yandex": {
|
"yandex": {
|
||||||
name: yandexName,
|
name: yandexName,
|
||||||
profilePath: yandexProfilePath,
|
profilePath: yandexProfilePath,
|
||||||
items: item.DefaultYandex,
|
dataTypes: types.DefaultYandexTypes,
|
||||||
},
|
},
|
||||||
"360": {
|
"360": {
|
||||||
name: speed360Name,
|
name: speed360Name,
|
||||||
profilePath: speed360ProfilePath,
|
profilePath: speed360ProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"qq": {
|
"qq": {
|
||||||
name: qqBrowserName,
|
name: qqBrowserName,
|
||||||
profilePath: qqBrowserProfilePath,
|
profilePath: qqBrowserProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"dc": {
|
"dc": {
|
||||||
name: dcBrowserName,
|
name: dcBrowserName,
|
||||||
profilePath: dcBrowserProfilePath,
|
profilePath: dcBrowserProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
"sogou": {
|
"sogou": {
|
||||||
name: sogouName,
|
name: sogouName,
|
||||||
profilePath: sogouProfilePath,
|
profilePath: sogouProfilePath,
|
||||||
items: item.DefaultChromium,
|
dataTypes: types.DefaultChromiumTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
firefoxList = map[string]struct {
|
firefoxList = map[string]struct {
|
||||||
name string
|
name string
|
||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
}{
|
}{
|
||||||
"firefox": {
|
"firefox": {
|
||||||
name: firefoxName,
|
name: firefoxName,
|
||||||
profilePath: firefoxProfilePath,
|
profilePath: firefoxProfilePath,
|
||||||
items: item.DefaultFirefox,
|
dataTypes: types.DefaultFirefoxTypes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata"
|
"github.com/moond4rk/hackbrowserdata/browserdata"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
@@ -17,28 +17,28 @@ type Chromium struct {
|
|||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
masterKey []byte
|
masterKey []byte
|
||||||
items []item.Item
|
dataTypes []types.DataType
|
||||||
itemPaths map[item.Item]string
|
Paths map[types.DataType]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New create instance of Chromium browser, fill item's path if item is existed.
|
// New create instance of Chromium browser, fill item's path if item is existed.
|
||||||
func New(name, storage, profilePath string, items []item.Item) ([]*Chromium, error) {
|
func New(name, storage, profilePath string, dataTypes []types.DataType) ([]*Chromium, error) {
|
||||||
c := &Chromium{
|
c := &Chromium{
|
||||||
name: name,
|
name: name,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
profilePath: profilePath,
|
profilePath: profilePath,
|
||||||
items: items,
|
dataTypes: dataTypes,
|
||||||
}
|
}
|
||||||
multiItemPaths, err := c.userItemPaths(c.profilePath, c.items)
|
multiDataTypePaths, err := c.userDataTypePaths(c.profilePath, c.dataTypes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chromiumList := make([]*Chromium, 0, len(multiItemPaths))
|
chromiumList := make([]*Chromium, 0, len(multiDataTypePaths))
|
||||||
for user, itemPaths := range multiItemPaths {
|
for user, itemPaths := range multiDataTypePaths {
|
||||||
chromiumList = append(chromiumList, &Chromium{
|
chromiumList = append(chromiumList, &Chromium{
|
||||||
name: fileutil.BrowserName(name, user),
|
name: fileutil.BrowserName(name, user),
|
||||||
items: typeutil.Keys(itemPaths),
|
dataTypes: typeutil.Keys(itemPaths),
|
||||||
itemPaths: itemPaths,
|
Paths: itemPaths,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -49,13 +49,13 @@ func (c *Chromium) Name() string {
|
|||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chromium) BrowsingData(isFullExport bool) (*browsingdata.Data, error) {
|
func (c *Chromium) BrowsingData(isFullExport bool) (*browserdata.BrowserData, error) {
|
||||||
items := c.items
|
items := c.dataTypes
|
||||||
if !isFullExport {
|
if !isFullExport {
|
||||||
items = item.FilterSensitiveItems(c.items)
|
items = types.FilterSensitiveItems(c.dataTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := browsingdata.New(items)
|
data := browserdata.New(items)
|
||||||
|
|
||||||
if err := c.copyItemToLocal(); err != nil {
|
if err := c.copyItemToLocal(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -75,15 +75,15 @@ func (c *Chromium) BrowsingData(isFullExport bool) (*browsingdata.Data, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chromium) copyItemToLocal() error {
|
func (c *Chromium) copyItemToLocal() error {
|
||||||
for i, path := range c.itemPaths {
|
for i, path := range c.Paths {
|
||||||
filename := i.TempFilename()
|
filename := i.TempFilename()
|
||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case fileutil.IsDirExists(path):
|
case fileutil.IsDirExists(path):
|
||||||
if i == item.ChromiumLocalStorage {
|
if i == types.ChromiumLocalStorage {
|
||||||
err = fileutil.CopyDir(path, filename, "lock")
|
err = fileutil.CopyDir(path, filename, "lock")
|
||||||
}
|
}
|
||||||
if i == item.ChromiumSessionStorage {
|
if i == types.ChromiumSessionStorage {
|
||||||
err = fileutil.CopyDir(path, filename, "lock")
|
err = fileutil.CopyDir(path, filename, "lock")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -97,9 +97,9 @@ func (c *Chromium) copyItemToLocal() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// userItemPaths return a map of user to item path, map[profile 1][item's name & path key pair]
|
// userDataTypePaths return a map of user to item path, map[profile 1][item's name & path key pair]
|
||||||
func (c *Chromium) userItemPaths(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
|
func (c *Chromium) userDataTypePaths(profilePath string, items []types.DataType) (map[string]map[types.DataType]string, error) {
|
||||||
multiItemPaths := make(map[string]map[item.Item]string)
|
multiItemPaths := make(map[string]map[types.DataType]string)
|
||||||
parentDir := fileutil.ParentDir(profilePath)
|
parentDir := fileutil.ParentDir(profilePath)
|
||||||
err := filepath.Walk(parentDir, chromiumWalkFunc(items, multiItemPaths))
|
err := filepath.Walk(parentDir, chromiumWalkFunc(items, multiItemPaths))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,27 +109,27 @@ func (c *Chromium) userItemPaths(profilePath string, items []item.Item) (map[str
|
|||||||
var dir string
|
var dir string
|
||||||
for userDir, v := range multiItemPaths {
|
for userDir, v := range multiItemPaths {
|
||||||
for _, p := range v {
|
for _, p := range v {
|
||||||
if strings.HasSuffix(p, item.ChromiumKey.Filename()) {
|
if strings.HasSuffix(p, types.ChromiumKey.Filename()) {
|
||||||
keyPath = p
|
keyPath = p
|
||||||
dir = userDir
|
dir = userDir
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t := make(map[string]map[item.Item]string)
|
t := make(map[string]map[types.DataType]string)
|
||||||
for userDir, v := range multiItemPaths {
|
for userDir, v := range multiItemPaths {
|
||||||
if userDir == dir {
|
if userDir == dir {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t[userDir] = v
|
t[userDir] = v
|
||||||
t[userDir][item.ChromiumKey] = keyPath
|
t[userDir][types.ChromiumKey] = keyPath
|
||||||
fillLocalStoragePath(t[userDir], item.ChromiumLocalStorage)
|
fillLocalStoragePath(t[userDir], types.ChromiumLocalStorage)
|
||||||
}
|
}
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// chromiumWalkFunc return a filepath.WalkFunc to find item's path
|
// chromiumWalkFunc return a filepath.WalkFunc to find item's path
|
||||||
func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc {
|
func chromiumWalkFunc(items []types.DataType, multiItemPaths map[string]map[types.DataType]string) filepath.WalkFunc {
|
||||||
return func(path string, info fs.FileInfo, err error) error {
|
return func(path string, info fs.FileInfo, err error) error {
|
||||||
for _, v := range items {
|
for _, v := range items {
|
||||||
if info.Name() != v.Filename() {
|
if info.Name() != v.Filename() {
|
||||||
@@ -145,18 +145,18 @@ func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item
|
|||||||
if _, exist := multiItemPaths[profileFolder]; exist {
|
if _, exist := multiItemPaths[profileFolder]; exist {
|
||||||
multiItemPaths[profileFolder][v] = path
|
multiItemPaths[profileFolder][v] = path
|
||||||
} else {
|
} else {
|
||||||
multiItemPaths[profileFolder] = map[item.Item]string{v: path}
|
multiItemPaths[profileFolder] = map[types.DataType]string{v: path}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillLocalStoragePath(itemPaths map[item.Item]string, storage item.Item) {
|
func fillLocalStoragePath(itemPaths map[types.DataType]string, storage types.DataType) {
|
||||||
if p, ok := itemPaths[item.ChromiumHistory]; ok {
|
if p, ok := itemPaths[types.ChromiumHistory]; ok {
|
||||||
lsp := filepath.Join(filepath.Dir(p), storage.Filename())
|
lsp := filepath.Join(filepath.Dir(p), storage.Filename())
|
||||||
if fileutil.IsDirExists(lsp) {
|
if fileutil.IsDirExists(lsp) {
|
||||||
itemPaths[item.ChromiumLocalStorage] = lsp
|
itemPaths[types.ChromiumLocalStorage] = lsp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -24,7 +24,7 @@ var (
|
|||||||
|
|
||||||
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
||||||
// don't need chromium key file for macOS
|
// don't need chromium key file for macOS
|
||||||
defer os.Remove(item.ChromiumKey.TempFilename())
|
defer os.Remove(types.ChromiumKey.TempFilename())
|
||||||
// Get the master key from the keychain
|
// Get the master key from the keychain
|
||||||
// $ security find-generic-password -wa 'Chrome'
|
// $ security find-generic-password -wa 'Chrome'
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import (
|
|||||||
keyring "github.com/ppacher/go-dbus-keyring"
|
keyring "github.com/ppacher/go-dbus-keyring"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
||||||
// what is d-bus @https://dbus.freedesktop.org/
|
// what is d-bus @https://dbus.freedesktop.org/
|
||||||
// don't need chromium key file for Linux
|
// don't need chromium key file for Linux
|
||||||
defer os.Remove(item.ChromiumKey.TempFilename())
|
defer os.Remove(types.ChromiumKey.TempFilename())
|
||||||
|
|
||||||
conn, err := dbus.SessionBus()
|
conn, err := dbus.SessionBus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -56,7 +56,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 {
|
||||||
return nil, fmt.Errorf("get storage from dbus error: %v" + err.Error())
|
return nil, fmt.Errorf("get storage from dbus: %w", err)
|
||||||
}
|
}
|
||||||
secret = se.Value
|
secret = se.Value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,18 +11,18 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
|
||||||
|
|
||||||
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
func (c *Chromium) GetMasterKey() ([]byte, error) {
|
||||||
b, err := fileutil.ReadFile(item.ChromiumKey.TempFilename())
|
b, err := fileutil.ReadFile(types.ChromiumKey.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumKey.TempFilename())
|
defer os.Remove(types.ChromiumKey.TempFilename())
|
||||||
|
|
||||||
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
|
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
|
||||||
if !encryptedKey.Exists() {
|
if !encryptedKey.Exists() {
|
||||||
|
|||||||
+13
-13
@@ -11,9 +11,9 @@ import (
|
|||||||
|
|
||||||
_ "modernc.org/sqlite" // sqlite3 driver TODO: replace with chooseable driver
|
_ "modernc.org/sqlite" // sqlite3 driver TODO: replace with chooseable driver
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata"
|
"github.com/moond4rk/hackbrowserdata/browserdata"
|
||||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
@@ -23,15 +23,15 @@ type Firefox struct {
|
|||||||
storage string
|
storage string
|
||||||
profilePath string
|
profilePath string
|
||||||
masterKey []byte
|
masterKey []byte
|
||||||
items []item.Item
|
items []types.DataType
|
||||||
itemPaths map[item.Item]string
|
itemPaths map[types.DataType]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrProfilePathNotFound = errors.New("profile path not found")
|
var ErrProfilePathNotFound = errors.New("profile path not found")
|
||||||
|
|
||||||
// New returns new Firefox instances.
|
// New returns new Firefox instances.
|
||||||
func New(profilePath string, items []item.Item) ([]*Firefox, error) {
|
func New(profilePath string, items []types.DataType) ([]*Firefox, error) {
|
||||||
multiItemPaths := make(map[string]map[item.Item]string)
|
multiItemPaths := make(map[string]map[types.DataType]string)
|
||||||
// ignore walk dir error since it can be produced by a single entry
|
// ignore walk dir error since it can be produced by a single entry
|
||||||
_ = filepath.WalkDir(profilePath, firefoxWalkFunc(items, multiItemPaths))
|
_ = filepath.WalkDir(profilePath, firefoxWalkFunc(items, multiItemPaths))
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func (f *Firefox) copyItemToLocal() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) fs.WalkDirFunc {
|
func firefoxWalkFunc(items []types.DataType, multiItemPaths map[string]map[types.DataType]string) fs.WalkDirFunc {
|
||||||
return func(path string, info fs.DirEntry, err error) error {
|
return func(path string, info fs.DirEntry, err error) error {
|
||||||
for _, v := range items {
|
for _, v := range items {
|
||||||
if info.Name() == v.Filename() {
|
if info.Name() == v.Filename() {
|
||||||
@@ -65,7 +65,7 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
|
|||||||
if _, exist := multiItemPaths[parentBaseDir]; exist {
|
if _, exist := multiItemPaths[parentBaseDir]; exist {
|
||||||
multiItemPaths[parentBaseDir][v] = path
|
multiItemPaths[parentBaseDir][v] = path
|
||||||
} else {
|
} else {
|
||||||
multiItemPaths[parentBaseDir] = map[item.Item]string{v: path}
|
multiItemPaths[parentBaseDir] = map[types.DataType]string{v: path}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]
|
|||||||
|
|
||||||
// GetMasterKey returns master key of Firefox. from key4.db
|
// GetMasterKey returns master key of Firefox. from key4.db
|
||||||
func (f *Firefox) GetMasterKey() ([]byte, error) {
|
func (f *Firefox) GetMasterKey() ([]byte, error) {
|
||||||
tempFilename := item.FirefoxKey4.TempFilename()
|
tempFilename := types.FirefoxKey4.TempFilename()
|
||||||
|
|
||||||
// Open and defer close of the database.
|
// Open and defer close of the database.
|
||||||
keyDB, err := sql.Open("sqlite", tempFilename)
|
keyDB, err := sql.Open("sqlite", tempFilename)
|
||||||
@@ -135,7 +135,7 @@ func processMasterKey(metaItem1, metaItem2, nssA11, nssA102 []byte) ([]byte, err
|
|||||||
return nil, errors.New("flag verification failed: password-check not found")
|
return nil, errors.New("flag verification failed: password-check not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyLin = []byte{248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
keyLin := []byte{248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
||||||
if !bytes.Equal(nssA102, keyLin) {
|
if !bytes.Equal(nssA102, keyLin) {
|
||||||
return nil, errors.New("master key verification failed: nssA102 not equal to expected value")
|
return nil, errors.New("master key verification failed: nssA102 not equal to expected value")
|
||||||
}
|
}
|
||||||
@@ -159,13 +159,13 @@ func (f *Firefox) Name() string {
|
|||||||
return f.name
|
return f.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Firefox) BrowsingData(isFullExport bool) (*browsingdata.Data, error) {
|
func (f *Firefox) BrowsingData(isFullExport bool) (*browserdata.BrowserData, error) {
|
||||||
items := f.items
|
items := f.items
|
||||||
if !isFullExport {
|
if !isFullExport {
|
||||||
items = item.FilterSensitiveItems(f.items)
|
items = types.FilterSensitiveItems(f.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
b := browsingdata.New(items)
|
b := browserdata.New(items)
|
||||||
|
|
||||||
if err := f.copyItemToLocal(); err != nil {
|
if err := f.copyItemToLocal(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -10,11 +10,21 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
_ "modernc.org/sqlite" // import sqlite3 driver
|
_ "modernc.org/sqlite" // import sqlite3 driver
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumBookmark, func() extractor.Extractor {
|
||||||
|
return new(ChromiumBookmark)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxBookmark, func() extractor.Extractor {
|
||||||
|
return new(FirefoxBookmark)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumBookmark []bookmark
|
type ChromiumBookmark []bookmark
|
||||||
|
|
||||||
type bookmark struct {
|
type bookmark struct {
|
||||||
@@ -25,12 +35,12 @@ type bookmark struct {
|
|||||||
DateAdded time.Time
|
DateAdded time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChromiumBookmark) Parse(_ []byte) error {
|
func (c *ChromiumBookmark) Extract(_ []byte) error {
|
||||||
bookmarks, err := fileutil.ReadFile(item.ChromiumBookmark.TempFilename())
|
bookmarks, err := fileutil.ReadFile(types.ChromiumBookmark.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumBookmark.TempFilename())
|
defer os.Remove(types.ChromiumBookmark.TempFilename())
|
||||||
r := gjson.Parse(bookmarks)
|
r := gjson.Parse(bookmarks)
|
||||||
if r.Exists() {
|
if r.Exists() {
|
||||||
roots := r.Get("roots")
|
roots := r.Get("roots")
|
||||||
@@ -92,12 +102,12 @@ const (
|
|||||||
closeJournalMode = `PRAGMA journal_mode=off`
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxBookmark) Parse(_ []byte) error {
|
func (f *FirefoxBookmark) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxBookmark.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxBookmark.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxBookmark.TempFilename())
|
defer os.Remove(types.FirefoxBookmark.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
_, err = db.Exec(closeJournalMode)
|
_, err = db.Exec(closeJournalMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package browserdata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BrowserData struct {
|
||||||
|
extractors map[types.DataType]extractor.Extractor
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(items []types.DataType) *BrowserData {
|
||||||
|
bd := &BrowserData{
|
||||||
|
extractors: make(map[types.DataType]extractor.Extractor),
|
||||||
|
}
|
||||||
|
bd.addExtractors(items)
|
||||||
|
return bd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *BrowserData) Recovery(masterKey []byte) error {
|
||||||
|
for _, source := range d.extractors {
|
||||||
|
if err := source.Extract(masterKey); err != nil {
|
||||||
|
slog.Error("parse error", "source_data", source.Name(), "err", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *BrowserData) Output(dir, browserName, flag string) {
|
||||||
|
output := newOutPutter(flag)
|
||||||
|
|
||||||
|
for _, source := range d.extractors {
|
||||||
|
if source.Len() == 0 {
|
||||||
|
// if the length of the export data is 0, then it is not necessary to output
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
|
||||||
|
|
||||||
|
f, err := output.CreateFile(dir, filename)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("create file error", "filename", filename, "err", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := output.Write(source, f); err != nil {
|
||||||
|
slog.Error("write to file error", "filename", filename, "err", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
slog.Error("close file error", "filename", filename, "err", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
slog.Warn("export success", "filename", filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *BrowserData) addExtractors(items []types.DataType) {
|
||||||
|
for _, itemType := range items {
|
||||||
|
if source := extractor.CreateExtractor(itemType); source != nil {
|
||||||
|
d.extractors[itemType] = source
|
||||||
|
} else {
|
||||||
|
slog.Debug("source not found", "source", itemType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,20 @@ import (
|
|||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumCookie, func() extractor.Extractor {
|
||||||
|
return new(ChromiumCookie)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxCookie, func() extractor.Extractor {
|
||||||
|
return new(FirefoxCookie)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumCookie []cookie
|
type ChromiumCookie []cookie
|
||||||
|
|
||||||
type cookie struct {
|
type cookie struct {
|
||||||
@@ -35,12 +45,12 @@ const (
|
|||||||
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
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) Extract(masterKey []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.ChromiumCookie.TempFilename())
|
db, err := sql.Open("sqlite", types.ChromiumCookie.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumCookie.TempFilename())
|
defer os.Remove(types.ChromiumCookie.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
rows, err := db.Query(queryChromiumCookie)
|
rows, err := db.Query(queryChromiumCookie)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -103,12 +113,12 @@ const (
|
|||||||
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxCookie) Parse(_ []byte) error {
|
func (f *FirefoxCookie) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxCookie.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxCookie.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxCookie.TempFilename())
|
defer os.Remove(types.FirefoxCookie.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
rows, err := db.Query(queryFirefoxCookie)
|
rows, err := db.Query(queryFirefoxCookie)
|
||||||
@@ -9,9 +9,19 @@ import (
|
|||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumCreditCard, func() extractor.Extractor {
|
||||||
|
return new(ChromiumCreditCard)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.YandexCreditCard, func() extractor.Extractor {
|
||||||
|
return new(YandexCreditCard)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumCreditCard []card
|
type ChromiumCreditCard []card
|
||||||
|
|
||||||
type card struct {
|
type card struct {
|
||||||
@@ -28,12 +38,12 @@ const (
|
|||||||
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, billing_address_id, nickname FROM credit_cards`
|
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) Extract(masterKey []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.ChromiumCreditCard.TempFilename())
|
db, err := sql.Open("sqlite", types.ChromiumCreditCard.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumCreditCard.TempFilename())
|
defer os.Remove(types.ChromiumCreditCard.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
rows, err := db.Query(queryChromiumCredit)
|
rows, err := db.Query(queryChromiumCredit)
|
||||||
@@ -84,12 +94,12 @@ func (c *ChromiumCreditCard) Len() int {
|
|||||||
|
|
||||||
type YandexCreditCard []card
|
type YandexCreditCard []card
|
||||||
|
|
||||||
func (c *YandexCreditCard) Parse(masterKey []byte) error {
|
func (c *YandexCreditCard) Extract(masterKey []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.YandexCreditCard.TempFilename())
|
db, err := sql.Open("sqlite", types.YandexCreditCard.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.YandexCreditCard.TempFilename())
|
defer os.Remove(types.YandexCreditCard.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
rows, err := db.Query(queryChromiumCredit)
|
rows, err := db.Query(queryChromiumCredit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -11,10 +11,20 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
_ "modernc.org/sqlite" // import sqlite3 driver
|
_ "modernc.org/sqlite" // import sqlite3 driver
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumDownload, func() extractor.Extractor {
|
||||||
|
return new(ChromiumDownload)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxDownload, func() extractor.Extractor {
|
||||||
|
return new(FirefoxDownload)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumDownload []download
|
type ChromiumDownload []download
|
||||||
|
|
||||||
type download struct {
|
type download struct {
|
||||||
@@ -30,12 +40,12 @@ const (
|
|||||||
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
|
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *ChromiumDownload) Parse(_ []byte) error {
|
func (c *ChromiumDownload) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.ChromiumDownload.TempFilename())
|
db, err := sql.Open("sqlite", types.ChromiumDownload.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumDownload.TempFilename())
|
defer os.Remove(types.ChromiumDownload.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
rows, err := db.Query(queryChromiumDownload)
|
rows, err := db.Query(queryChromiumDownload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -81,12 +91,12 @@ const (
|
|||||||
closeJournalMode = `PRAGMA journal_mode=off`
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxDownload) Parse(_ []byte) error {
|
func (f *FirefoxDownload) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxDownload.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxDownload.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxDownload.TempFilename())
|
defer os.Remove(types.FirefoxDownload.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(closeJournalMode)
|
_, err = db.Exec(closeJournalMode)
|
||||||
@@ -8,10 +8,20 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumExtension, func() extractor.Extractor {
|
||||||
|
return new(ChromiumExtension)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxExtension, func() extractor.Extractor {
|
||||||
|
return new(FirefoxExtension)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumExtension []*extension
|
type ChromiumExtension []*extension
|
||||||
|
|
||||||
type extension struct {
|
type extension struct {
|
||||||
@@ -24,12 +34,12 @@ type extension struct {
|
|||||||
HomepageURL string
|
HomepageURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChromiumExtension) Parse(_ []byte) error {
|
func (c *ChromiumExtension) Extract(_ []byte) error {
|
||||||
extensionFile, err := fileutil.ReadFile(item.ChromiumExtension.TempFilename())
|
extensionFile, err := fileutil.ReadFile(types.ChromiumExtension.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumExtension.TempFilename())
|
defer os.Remove(types.ChromiumExtension.TempFilename())
|
||||||
|
|
||||||
result, err := parseChromiumExtensions(extensionFile)
|
result, err := parseChromiumExtensions(extensionFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -113,12 +123,12 @@ type FirefoxExtension []*extension
|
|||||||
|
|
||||||
var lang = language.Und
|
var lang = language.Und
|
||||||
|
|
||||||
func (f *FirefoxExtension) Parse(_ []byte) error {
|
func (f *FirefoxExtension) Extract(_ []byte) error {
|
||||||
s, err := fileutil.ReadFile(item.FirefoxExtension.TempFilename())
|
s, err := fileutil.ReadFile(types.FirefoxExtension.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_ = os.Remove(item.FirefoxExtension.TempFilename())
|
_ = os.Remove(types.FirefoxExtension.TempFilename())
|
||||||
j := gjson.Parse(s)
|
j := gjson.Parse(s)
|
||||||
for _, v := range j.Get("addons").Array() {
|
for _, v := range j.Get("addons").Array() {
|
||||||
// https://searchfox.org/mozilla-central/source/toolkit/mozapps/extensions/internal/XPIDatabase.jsm#157
|
// https://searchfox.org/mozilla-central/source/toolkit/mozapps/extensions/internal/XPIDatabase.jsm#157
|
||||||
@@ -10,10 +10,20 @@ import (
|
|||||||
// import sqlite3 driver
|
// import sqlite3 driver
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumHistory, func() extractor.Extractor {
|
||||||
|
return new(ChromiumHistory)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxHistory, func() extractor.Extractor {
|
||||||
|
return new(FirefoxHistory)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumHistory []history
|
type ChromiumHistory []history
|
||||||
|
|
||||||
type history struct {
|
type history struct {
|
||||||
@@ -27,12 +37,12 @@ const (
|
|||||||
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *ChromiumHistory) Parse(_ []byte) error {
|
func (c *ChromiumHistory) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.ChromiumHistory.TempFilename())
|
db, err := sql.Open("sqlite", types.ChromiumHistory.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumHistory.TempFilename())
|
defer os.Remove(types.ChromiumHistory.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
rows, err := db.Query(queryChromiumHistory)
|
rows, err := db.Query(queryChromiumHistory)
|
||||||
@@ -78,12 +88,12 @@ const (
|
|||||||
closeJournalMode = `PRAGMA journal_mode=off`
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxHistory) Parse(_ []byte) error {
|
func (f *FirefoxHistory) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxHistory.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxHistory.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxHistory.TempFilename())
|
defer os.Remove(types.FirefoxHistory.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(closeJournalMode)
|
_, err = db.Exec(closeJournalMode)
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// Package browserdata is responsible for initializing all the necessary
|
||||||
|
// components that handle different types of browser data extraction.
|
||||||
|
// This file, imports.go, is specifically used to import various data
|
||||||
|
// handler packages to ensure their initialization logic is executed.
|
||||||
|
// These imports are crucial as they trigger the `init()` functions
|
||||||
|
// within each package, which typically handle registration of their
|
||||||
|
// specific data handlers to a central registry.
|
||||||
|
package browserdata
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/bookmark"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/cookie"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/creditcard"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/download"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/extension"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/history"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/localstorage"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/password"
|
||||||
|
_ "github.com/moond4rk/hackbrowserdata/browserdata/sessionstorage"
|
||||||
|
)
|
||||||
+17
-7
@@ -12,11 +12,21 @@ import (
|
|||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/byteutil"
|
"github.com/moond4rk/hackbrowserdata/utils/byteutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumLocalStorage, func() extractor.Extractor {
|
||||||
|
return new(ChromiumLocalStorage)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxLocalStorage, func() extractor.Extractor {
|
||||||
|
return new(FirefoxLocalStorage)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumLocalStorage []storage
|
type ChromiumLocalStorage []storage
|
||||||
|
|
||||||
type storage struct {
|
type storage struct {
|
||||||
@@ -28,12 +38,12 @@ type storage struct {
|
|||||||
|
|
||||||
const maxLocalStorageValueLength = 1024 * 2
|
const maxLocalStorageValueLength = 1024 * 2
|
||||||
|
|
||||||
func (c *ChromiumLocalStorage) Parse(_ []byte) error {
|
func (c *ChromiumLocalStorage) Extract(_ []byte) error {
|
||||||
db, err := leveldb.OpenFile(item.ChromiumLocalStorage.TempFilename(), nil)
|
db, err := leveldb.OpenFile(types.ChromiumLocalStorage.TempFilename(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(item.ChromiumLocalStorage.TempFilename())
|
defer os.RemoveAll(types.ChromiumLocalStorage.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
iter := db.NewIterator(nil, nil)
|
iter := db.NewIterator(nil, nil)
|
||||||
@@ -105,12 +115,12 @@ const (
|
|||||||
closeJournalMode = `PRAGMA journal_mode=off`
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxLocalStorage) Parse(_ []byte) error {
|
func (f *FirefoxLocalStorage) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxLocalStorage.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxLocalStorage.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxLocalStorage.TempFilename())
|
defer os.Remove(types.FirefoxLocalStorage.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(closeJournalMode)
|
_, err = db.Exec(closeJournalMode)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package browsingdata
|
package browserdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"github.com/gocarina/gocsv"
|
"github.com/gocarina/gocsv"
|
||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
|
|
||||||
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
)
|
)
|
||||||
|
|
||||||
type outPutter struct {
|
type outPutter struct {
|
||||||
@@ -28,7 +30,7 @@ func newOutPutter(flag string) *outPutter {
|
|||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *outPutter) Write(data Source, writer io.Writer) error {
|
func (o *outPutter) Write(data extractor.Extractor, writer io.Writer) error {
|
||||||
switch o.json {
|
switch o.json {
|
||||||
case true:
|
case true:
|
||||||
encoder := json.NewEncoder(writer)
|
encoder := json.NewEncoder(writer)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package browsingdata
|
package browserdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@@ -12,10 +12,23 @@ import (
|
|||||||
_ "modernc.org/sqlite" // import sqlite3 driver
|
_ "modernc.org/sqlite" // import sqlite3 driver
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/crypto"
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumPassword, func() extractor.Extractor {
|
||||||
|
return new(ChromiumPassword)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.YandexPassword, func() extractor.Extractor {
|
||||||
|
return new(YandexPassword)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxPassword, func() extractor.Extractor {
|
||||||
|
return new(FirefoxPassword)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumPassword []loginData
|
type ChromiumPassword []loginData
|
||||||
|
|
||||||
type loginData struct {
|
type loginData struct {
|
||||||
@@ -31,12 +44,12 @@ const (
|
|||||||
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *ChromiumPassword) Parse(masterKey []byte) error {
|
func (c *ChromiumPassword) Extract(masterKey []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.ChromiumPassword.TempFilename())
|
db, err := sql.Open("sqlite", types.ChromiumPassword.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.ChromiumPassword.TempFilename())
|
defer os.Remove(types.ChromiumPassword.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
rows, err := db.Query(queryChromiumLogin)
|
rows, err := db.Query(queryChromiumLogin)
|
||||||
@@ -98,12 +111,12 @@ const (
|
|||||||
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *YandexPassword) Parse(masterKey []byte) error {
|
func (c *YandexPassword) Extract(masterKey []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.YandexPassword.TempFilename())
|
db, err := sql.Open("sqlite", types.YandexPassword.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.YandexPassword.TempFilename())
|
defer os.Remove(types.YandexPassword.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
rows, err := db.Query(queryYandexLogin)
|
rows, err := db.Query(queryYandexLogin)
|
||||||
@@ -162,7 +175,7 @@ func (c *YandexPassword) Len() int {
|
|||||||
|
|
||||||
type FirefoxPassword []loginData
|
type FirefoxPassword []loginData
|
||||||
|
|
||||||
func (f *FirefoxPassword) Parse(globalSalt []byte) error {
|
func (f *FirefoxPassword) Extract(globalSalt []byte) error {
|
||||||
logins, err := getFirefoxLoginData()
|
logins, err := getFirefoxLoginData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -200,11 +213,11 @@ func (f *FirefoxPassword) Parse(globalSalt []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getFirefoxLoginData() ([]loginData, error) {
|
func getFirefoxLoginData() ([]loginData, error) {
|
||||||
s, err := os.ReadFile(item.FirefoxPassword.TempFilename())
|
s, err := os.ReadFile(types.FirefoxPassword.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxPassword.TempFilename())
|
defer os.Remove(types.FirefoxPassword.TempFilename())
|
||||||
loginsJSON := gjson.GetBytes(s, "logins")
|
loginsJSON := gjson.GetBytes(s, "logins")
|
||||||
var logins []loginData
|
var logins []loginData
|
||||||
if loginsJSON.Exists() {
|
if loginsJSON.Exists() {
|
||||||
+17
-7
@@ -12,11 +12,21 @@ import (
|
|||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
"github.com/moond4rk/hackbrowserdata/extractor"
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/byteutil"
|
"github.com/moond4rk/hackbrowserdata/utils/byteutil"
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
extractor.RegisterExtractor(types.ChromiumSessionStorage, func() extractor.Extractor {
|
||||||
|
return new(ChromiumSessionStorage)
|
||||||
|
})
|
||||||
|
extractor.RegisterExtractor(types.FirefoxSessionStorage, func() extractor.Extractor {
|
||||||
|
return new(FirefoxSessionStorage)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type ChromiumSessionStorage []session
|
type ChromiumSessionStorage []session
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
@@ -28,12 +38,12 @@ type session struct {
|
|||||||
|
|
||||||
const maxLocalStorageValueLength = 1024 * 2
|
const maxLocalStorageValueLength = 1024 * 2
|
||||||
|
|
||||||
func (c *ChromiumSessionStorage) Parse(_ []byte) error {
|
func (c *ChromiumSessionStorage) Extract(_ []byte) error {
|
||||||
db, err := leveldb.OpenFile(item.ChromiumSessionStorage.TempFilename(), nil)
|
db, err := leveldb.OpenFile(types.ChromiumSessionStorage.TempFilename(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(item.ChromiumSessionStorage.TempFilename())
|
defer os.RemoveAll(types.ChromiumSessionStorage.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
iter := db.NewIterator(nil, nil)
|
iter := db.NewIterator(nil, nil)
|
||||||
@@ -113,12 +123,12 @@ const (
|
|||||||
closeJournalMode = `PRAGMA journal_mode=off`
|
closeJournalMode = `PRAGMA journal_mode=off`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *FirefoxSessionStorage) Parse(_ []byte) error {
|
func (f *FirefoxSessionStorage) Extract(_ []byte) error {
|
||||||
db, err := sql.Open("sqlite", item.FirefoxSessionStorage.TempFilename())
|
db, err := sql.Open("sqlite", types.FirefoxSessionStorage.TempFilename())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.Remove(item.FirefoxSessionStorage.TempFilename())
|
defer os.Remove(types.FirefoxSessionStorage.TempFilename())
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
_, err = db.Exec(closeJournalMode)
|
_, err = db.Exec(closeJournalMode)
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
package browsingdata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/bookmark"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/cookie"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/creditcard"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/download"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/extension"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/history"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/localstorage"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/password"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/browsingdata/sessionstorage"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/item"
|
|
||||||
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Data struct {
|
|
||||||
sources map[item.Item]Source
|
|
||||||
}
|
|
||||||
|
|
||||||
type Source interface {
|
|
||||||
Parse(masterKey []byte) error
|
|
||||||
|
|
||||||
Name() string
|
|
||||||
|
|
||||||
Len() int
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(items []item.Item) *Data {
|
|
||||||
bd := &Data{
|
|
||||||
sources: make(map[item.Item]Source),
|
|
||||||
}
|
|
||||||
bd.addSources(items)
|
|
||||||
return bd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Data) Recovery(masterKey []byte) error {
|
|
||||||
for _, source := range d.sources {
|
|
||||||
if err := source.Parse(masterKey); err != nil {
|
|
||||||
slog.Error("parse error", "source_data", source.Name(), "err", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Data) Output(dir, browserName, flag string) {
|
|
||||||
output := newOutPutter(flag)
|
|
||||||
|
|
||||||
for _, source := range d.sources {
|
|
||||||
if source.Len() == 0 {
|
|
||||||
// if the length of the export data is 0, then it is not necessary to output
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filename := fileutil.ItemName(browserName, source.Name(), output.Ext())
|
|
||||||
|
|
||||||
f, err := output.CreateFile(dir, filename)
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("create file error", "filename", filename, "err", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := output.Write(source, f); err != nil {
|
|
||||||
slog.Error("write to file error", "filename", filename, "err", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
slog.Error("close file error", "filename", filename, "err", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
slog.Warn("export success", "filename", filename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Data) addSources(items []item.Item) {
|
|
||||||
for _, source := range items {
|
|
||||||
switch source {
|
|
||||||
case item.ChromiumPassword:
|
|
||||||
d.sources[source] = &password.ChromiumPassword{}
|
|
||||||
case item.ChromiumCookie:
|
|
||||||
d.sources[source] = &cookie.ChromiumCookie{}
|
|
||||||
case item.ChromiumBookmark:
|
|
||||||
d.sources[source] = &bookmark.ChromiumBookmark{}
|
|
||||||
case item.ChromiumHistory:
|
|
||||||
d.sources[source] = &history.ChromiumHistory{}
|
|
||||||
case item.ChromiumDownload:
|
|
||||||
d.sources[source] = &download.ChromiumDownload{}
|
|
||||||
case item.ChromiumCreditCard:
|
|
||||||
d.sources[source] = &creditcard.ChromiumCreditCard{}
|
|
||||||
case item.ChromiumLocalStorage:
|
|
||||||
d.sources[source] = &localstorage.ChromiumLocalStorage{}
|
|
||||||
case item.ChromiumSessionStorage:
|
|
||||||
d.sources[source] = &sessionstorage.ChromiumSessionStorage{}
|
|
||||||
case item.ChromiumExtension:
|
|
||||||
d.sources[source] = &extension.ChromiumExtension{}
|
|
||||||
case item.YandexPassword:
|
|
||||||
d.sources[source] = &password.YandexPassword{}
|
|
||||||
case item.YandexCreditCard:
|
|
||||||
d.sources[source] = &creditcard.YandexCreditCard{}
|
|
||||||
case item.FirefoxPassword:
|
|
||||||
d.sources[source] = &password.FirefoxPassword{}
|
|
||||||
case item.FirefoxCookie:
|
|
||||||
d.sources[source] = &cookie.FirefoxCookie{}
|
|
||||||
case item.FirefoxBookmark:
|
|
||||||
d.sources[source] = &bookmark.FirefoxBookmark{}
|
|
||||||
case item.FirefoxHistory:
|
|
||||||
d.sources[source] = &history.FirefoxHistory{}
|
|
||||||
case item.FirefoxDownload:
|
|
||||||
d.sources[source] = &download.FirefoxDownload{}
|
|
||||||
case item.FirefoxLocalStorage:
|
|
||||||
d.sources[source] = &localstorage.FirefoxLocalStorage{}
|
|
||||||
case item.FirefoxExtension:
|
|
||||||
d.sources[source] = &extension.FirefoxExtension{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -62,7 +62,7 @@ func (n nssPBE) Decrypt(globalSalt []byte) ([]byte, error) {
|
|||||||
return DES3Decrypt(key, iv, n.Encrypted)
|
return DES3Decrypt(key, iv, n.Encrypted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n nssPBE) Encrypt(globalSalt []byte, plaintext []byte) ([]byte, error) {
|
func (n nssPBE) Encrypt(globalSalt, plaintext []byte) ([]byte, error) {
|
||||||
key, iv := n.deriveKeyAndIV(globalSalt)
|
key, iv := n.deriveKeyAndIV(globalSalt)
|
||||||
|
|
||||||
return DES3Encrypt(key, iv, plaintext)
|
return DES3Encrypt(key, iv, plaintext)
|
||||||
|
|||||||
+3
-5
@@ -9,9 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrCiphertextLengthIsInvalid = errors.New("ciphertext length is invalid")
|
||||||
ErrCiphertextLengthIsInvalid = errors.New("ciphertext length is invalid")
|
|
||||||
)
|
|
||||||
|
|
||||||
func AES128CBCDecrypt(key, iv, ciphertext []byte) ([]byte, error) {
|
func AES128CBCDecrypt(key, iv, ciphertext []byte) ([]byte, error) {
|
||||||
block, err := aes.NewCipher(key)
|
block, err := aes.NewCipher(key)
|
||||||
@@ -57,7 +55,7 @@ func AES128CBCEncrypt(key, iv, plaintext []byte) ([]byte, error) {
|
|||||||
return encryptedData, nil
|
return encryptedData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DES3Decrypt(key, iv []byte, ciphertext []byte) ([]byte, error) {
|
func DES3Decrypt(key, iv, ciphertext []byte) ([]byte, error) {
|
||||||
block, err := des.NewTripleDESCipher(key)
|
block, err := des.NewTripleDESCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -76,7 +74,7 @@ func DES3Decrypt(key, iv []byte, ciphertext []byte) ([]byte, error) {
|
|||||||
return pkcs5UnPadding(sq)
|
return pkcs5UnPadding(sq)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DES3Encrypt(key, iv []byte, plaintext []byte) ([]byte, error) {
|
func DES3Encrypt(key, iv, plaintext []byte) ([]byte, error) {
|
||||||
block, err := des.NewTripleDESCipher(key)
|
block, err := des.NewTripleDESCipher(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ func DecryptWithChromium(key, password []byte) ([]byte, error) {
|
|||||||
if len(password) <= 3 {
|
if len(password) <= 3 {
|
||||||
return nil, ErrCiphertextLengthIsInvalid
|
return nil, ErrCiphertextLengthIsInvalid
|
||||||
}
|
}
|
||||||
var iv = []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
|
iv := []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
|
||||||
return AES128CBCDecrypt(key, iv, password[3:])
|
return AES128CBCDecrypt(key, iv, password[3:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ func DecryptWithChromium(key, encryptPass []byte) ([]byte, error) {
|
|||||||
if len(encryptPass) < 3 {
|
if len(encryptPass) < 3 {
|
||||||
return nil, ErrCiphertextLengthIsInvalid
|
return nil, ErrCiphertextLengthIsInvalid
|
||||||
}
|
}
|
||||||
var iv = []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
|
iv := []byte{32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32}
|
||||||
return AES128CBCDecrypt(key, iv, encryptPass[3:])
|
return AES128CBCDecrypt(key, iv, encryptPass[3:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package extractor
|
||||||
|
|
||||||
|
// Extractor is an interface for extracting data from browser data files
|
||||||
|
type Extractor interface {
|
||||||
|
Extract(masterKey []byte) error
|
||||||
|
|
||||||
|
Name() string
|
||||||
|
|
||||||
|
Len() int
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package extractor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/moond4rk/hackbrowserdata/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var extractorRegistry = make(map[types.DataType]func() Extractor)
|
||||||
|
|
||||||
|
// RegisterExtractor is used to register the data source
|
||||||
|
func RegisterExtractor(dataType types.DataType, factoryFunc func() Extractor) {
|
||||||
|
extractorRegistry[dataType] = factoryFunc
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateExtractor is used to create the data source
|
||||||
|
func CreateExtractor(dataType types.DataType) Extractor {
|
||||||
|
if factoryFunc, ok := extractorRegistry[dataType]; ok {
|
||||||
|
return factoryFunc()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package item
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -6,10 +6,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Item int
|
type DataType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChromiumKey Item = iota
|
ChromiumKey DataType = iota
|
||||||
ChromiumPassword
|
ChromiumPassword
|
||||||
ChromiumCookie
|
ChromiumCookie
|
||||||
ChromiumBookmark
|
ChromiumBookmark
|
||||||
@@ -35,7 +35,7 @@ const (
|
|||||||
FirefoxExtension
|
FirefoxExtension
|
||||||
)
|
)
|
||||||
|
|
||||||
var itemFileNames = map[Item]string{
|
var itemFileNames = map[DataType]string{
|
||||||
ChromiumKey: fileChromiumKey,
|
ChromiumKey: fileChromiumKey,
|
||||||
ChromiumPassword: fileChromiumPassword,
|
ChromiumPassword: fileChromiumPassword,
|
||||||
ChromiumCookie: fileChromiumCookie,
|
ChromiumCookie: fileChromiumCookie,
|
||||||
@@ -60,25 +60,26 @@ var itemFileNames = map[Item]string{
|
|||||||
FirefoxCreditCard: UnsupportedItem,
|
FirefoxCreditCard: UnsupportedItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Item) Filename() string {
|
// Filename returns the filename for the item, defined by browser
|
||||||
|
// chromium local storage is a folder, so it returns the file name of the folder
|
||||||
|
func (i DataType) Filename() string {
|
||||||
if fileName, ok := itemFileNames[i]; ok {
|
if fileName, ok := itemFileNames[i]; ok {
|
||||||
return fileName
|
return fileName
|
||||||
}
|
}
|
||||||
return UnsupportedItem
|
return UnsupportedItem
|
||||||
}
|
}
|
||||||
|
|
||||||
const tempSuffix = "temp"
|
|
||||||
|
|
||||||
// TempFilename returns the temp filename for the item with suffix
|
// TempFilename returns the temp filename for the item with suffix
|
||||||
// eg: chromiumKey_0.temp
|
// eg: chromiumKey_0.temp
|
||||||
func (i Item) TempFilename() string {
|
func (i DataType) TempFilename() string {
|
||||||
|
const tempSuffix = "temp"
|
||||||
tempFile := fmt.Sprintf("%s_%d.%s", i.Filename(), i, tempSuffix)
|
tempFile := fmt.Sprintf("%s_%d.%s", i.Filename(), i, tempSuffix)
|
||||||
return filepath.Join(os.TempDir(), tempFile)
|
return filepath.Join(os.TempDir(), tempFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSensitive returns whether the item is sensitive data
|
// IsSensitive returns whether the item is sensitive data
|
||||||
// password, cookie, credit card, master key is unlimited
|
// password, cookie, credit card, master key is unlimited
|
||||||
func (i Item) IsSensitive() bool {
|
func (i DataType) IsSensitive() bool {
|
||||||
switch i {
|
switch i {
|
||||||
case ChromiumKey, ChromiumCookie, ChromiumPassword, ChromiumCreditCard,
|
case ChromiumKey, ChromiumCookie, ChromiumPassword, ChromiumCreditCard,
|
||||||
FirefoxKey4, FirefoxPassword, FirefoxCookie, FirefoxCreditCard,
|
FirefoxKey4, FirefoxPassword, FirefoxCookie, FirefoxCreditCard,
|
||||||
@@ -90,8 +91,8 @@ func (i Item) IsSensitive() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FilterSensitiveItems returns the sensitive items
|
// FilterSensitiveItems returns the sensitive items
|
||||||
func FilterSensitiveItems(items []Item) []Item {
|
func FilterSensitiveItems(items []DataType) []DataType {
|
||||||
var filtered []Item
|
var filtered []DataType
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.IsSensitive() {
|
if item.IsSensitive() {
|
||||||
filtered = append(filtered, item)
|
filtered = append(filtered, item)
|
||||||
@@ -100,8 +101,8 @@ func FilterSensitiveItems(items []Item) []Item {
|
|||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultFirefox returns the default items for the firefox browser
|
// DefaultFirefoxTypes returns the default items for the firefox browser
|
||||||
var DefaultFirefox = []Item{
|
var DefaultFirefoxTypes = []DataType{
|
||||||
FirefoxKey4,
|
FirefoxKey4,
|
||||||
FirefoxPassword,
|
FirefoxPassword,
|
||||||
FirefoxCookie,
|
FirefoxCookie,
|
||||||
@@ -114,8 +115,8 @@ var DefaultFirefox = []Item{
|
|||||||
FirefoxExtension,
|
FirefoxExtension,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultYandex returns the default items for the yandex browser
|
// DefaultYandexTypes returns the default items for the yandex browser
|
||||||
var DefaultYandex = []Item{
|
var DefaultYandexTypes = []DataType{
|
||||||
ChromiumKey,
|
ChromiumKey,
|
||||||
ChromiumCookie,
|
ChromiumCookie,
|
||||||
ChromiumBookmark,
|
ChromiumBookmark,
|
||||||
@@ -128,8 +129,8 @@ var DefaultYandex = []Item{
|
|||||||
YandexCreditCard,
|
YandexCreditCard,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultChromium returns the default items for the chromium browser
|
// DefaultChromiumTypes returns the default items for the chromium browser
|
||||||
var DefaultChromium = []Item{
|
var DefaultChromiumTypes = []DataType{
|
||||||
ChromiumKey,
|
ChromiumKey,
|
||||||
ChromiumPassword,
|
ChromiumPassword,
|
||||||
ChromiumCookie,
|
ChromiumCookie,
|
||||||
@@ -164,9 +165,6 @@ const (
|
|||||||
fileFirefoxData = "places.sqlite"
|
fileFirefoxData = "places.sqlite"
|
||||||
fileFirefoxLocalStorage = "webappsstore.sqlite"
|
fileFirefoxLocalStorage = "webappsstore.sqlite"
|
||||||
fileFirefoxExtension = "extensions.json"
|
fileFirefoxExtension = "extensions.json"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
UnknownItem = "unknown item"
|
|
||||||
UnsupportedItem = "unsupported item"
|
UnsupportedItem = "unsupported item"
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package item
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -9,23 +9,23 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestItem_FileName(t *testing.T) {
|
func TestDataType_FileName(t *testing.T) {
|
||||||
for _, item := range DefaultChromium {
|
for _, item := range DefaultChromiumTypes {
|
||||||
assert.Equal(t, item.Filename(), item.filename())
|
assert.Equal(t, item.Filename(), item.filename())
|
||||||
}
|
}
|
||||||
for _, item := range DefaultFirefox {
|
for _, item := range DefaultFirefoxTypes {
|
||||||
assert.Equal(t, item.Filename(), item.filename())
|
assert.Equal(t, item.Filename(), item.filename())
|
||||||
}
|
}
|
||||||
for _, item := range DefaultYandex {
|
for _, item := range DefaultYandexTypes {
|
||||||
assert.Equal(t, item.Filename(), item.filename())
|
assert.Equal(t, item.Filename(), item.filename())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestItem_TempFilename(t *testing.T) {
|
func TestDataType_TempFilename(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
item Item
|
item DataType
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{ChromiumKey, "Local State"},
|
{ChromiumKey, "Local State"},
|
||||||
@@ -45,10 +45,10 @@ func TestItem_TempFilename(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestItem_IsSensitive(t *testing.T) {
|
func TestDataType_IsSensitive(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
item Item
|
item DataType
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{ChromiumKey, true},
|
{ChromiumKey, true},
|
||||||
@@ -63,11 +63,11 @@ func TestItem_IsSensitive(t *testing.T) {
|
|||||||
func TestFilterSensitiveItems(t *testing.T) {
|
func TestFilterSensitiveItems(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
items []Item
|
items []DataType
|
||||||
expected int
|
expected int
|
||||||
}{
|
}{
|
||||||
{[]Item{ChromiumKey, ChromiumBookmark, ChromiumPassword}, 2},
|
{[]DataType{ChromiumKey, ChromiumBookmark, ChromiumPassword}, 2},
|
||||||
{[]Item{ChromiumBookmark, ChromiumHistory}, 0},
|
{[]DataType{ChromiumBookmark, ChromiumHistory}, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@@ -79,7 +79,7 @@ func TestFilterSensitiveItems(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Item) filename() string {
|
func (i DataType) filename() string {
|
||||||
switch i {
|
switch i {
|
||||||
case ChromiumKey:
|
case ChromiumKey:
|
||||||
return fileChromiumKey
|
return fileChromiumKey
|
||||||
@@ -64,10 +64,10 @@ func CopyFile(src, dst string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ItemName returns the filename from the provided path
|
// Filename returns the filename from the provided path
|
||||||
func ItemName(browser, item, ext string) string {
|
func Filename(browser, dataType, ext string) string {
|
||||||
replace := strings.NewReplacer(" ", "_", ".", "_", "-", "_")
|
replace := strings.NewReplacer(" ", "_", ".", "_", "-", "_")
|
||||||
return strings.ToLower(fmt.Sprintf("%s_%s.%s", replace.Replace(browser), item, ext))
|
return strings.ToLower(fmt.Sprintf("%s_%s.%s", replace.Replace(browser), dataType, ext))
|
||||||
}
|
}
|
||||||
|
|
||||||
func BrowserName(browser, user string) string {
|
func BrowserName(browser, user string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user