Files
HackBrowserData/types/types.go
T
ᴍᴏᴏɴD4ʀᴋ ad020cf135 chore: downgrade golang version to 1.20, support Windows 7. (#435)
* chore: downgrade golang version to 1.20, support windows 7

* chore: Update dependencies for Go project.

- Update dependencies in go.sum
- Improvements and optimizations in various files
- Bug fixes and error handling enhancements

* chore: Update modernc.org/sqlite library versions in go.mod and go.sum files

- Update version of `modernc.org/sqlite` to `v1.31.1` in `go.mod` and `go.sum` files
- Update module hash in `go.sum` file for `modernc.org/sqlite`
- Ensure consistency between `go.mod` and `go.sum` files in relation to `modernc.org/sqlite` version

* chore: replace log/slog with standard logger (#436)

* chore: replace log/slog with standard logger

* chore: Update Go dependencies and versions

- Update Go version from `1.22.5` to `1.20` and other dependencies
- Update critical dependencies to latest versions
- Ensure compatibility with new versions of dependencies

* chore: Optimize dependency management in workflows

- Update build and lint workflows to use `go mod tidy` for getting dependencies
- Change modules download mode to `'mod'` in linters configuration
- Add step to get dependencies in lint workflow

* refactor: Update dependencies and refactor Chromium key deletion logic

- Update `modernc.org/sqlite` to `v1.31.1` in `go.mod` and `go.sum`
- Increase version number to `0.5.0` in `cmd/hack-browser-data/main.go`
- Refactor and update logic for filtering and copying items in `browser/chromium/chromium.go`

* Improve logging functionality and data type conversion

- Add `String()` method to `DataType` enum in types.go
- Update log level to Debug in logger_test.go
- Set log level to Debug in `TestLoggerDebug` and `TestLoggerDebugf` functions
2024-10-22 13:01:13 +08:00

222 lines
5.7 KiB
Go

package types
import (
"fmt"
"os"
"path/filepath"
)
type DataType int
const (
ChromiumKey DataType = iota
ChromiumPassword
ChromiumCookie
ChromiumBookmark
ChromiumHistory
ChromiumDownload
ChromiumCreditCard
ChromiumLocalStorage
ChromiumSessionStorage
ChromiumExtension
YandexPassword
YandexCreditCard
FirefoxKey4
FirefoxPassword
FirefoxCookie
FirefoxBookmark
FirefoxHistory
FirefoxDownload
FirefoxCreditCard
FirefoxLocalStorage
FirefoxSessionStorage
FirefoxExtension
)
var itemFileNames = map[DataType]string{
ChromiumKey: fileChromiumKey,
ChromiumPassword: fileChromiumPassword,
ChromiumCookie: fileChromiumCookie,
ChromiumBookmark: fileChromiumBookmark,
ChromiumDownload: fileChromiumDownload,
ChromiumLocalStorage: fileChromiumLocalStorage,
ChromiumSessionStorage: fileChromiumSessionStorage,
ChromiumCreditCard: fileChromiumCredit,
ChromiumExtension: fileChromiumExtension,
ChromiumHistory: fileChromiumHistory,
YandexPassword: fileYandexPassword,
YandexCreditCard: fileYandexCredit,
FirefoxKey4: fileFirefoxKey4,
FirefoxPassword: fileFirefoxPassword,
FirefoxCookie: fileFirefoxCookie,
FirefoxBookmark: fileFirefoxData,
FirefoxDownload: fileFirefoxData,
FirefoxLocalStorage: fileFirefoxLocalStorage,
FirefoxHistory: fileFirefoxData,
FirefoxExtension: fileFirefoxExtension,
FirefoxSessionStorage: UnsupportedItem,
FirefoxCreditCard: UnsupportedItem,
}
func (i DataType) String() string {
switch i {
case ChromiumKey:
return "ChromiumKey"
case ChromiumPassword:
return "ChromiumPassword"
case ChromiumCookie:
return "ChromiumCookie"
case ChromiumBookmark:
return "ChromiumBookmark"
case ChromiumHistory:
return "ChromiumHistory"
case ChromiumDownload:
return "ChromiumDownload"
case ChromiumCreditCard:
return "ChromiumCreditCard"
case ChromiumLocalStorage:
return "ChromiumLocalStorage"
case ChromiumSessionStorage:
return "ChromiumSessionStorage"
case ChromiumExtension:
return "ChromiumExtension"
case YandexPassword:
return "YandexPassword"
case YandexCreditCard:
return "YandexCreditCard"
case FirefoxKey4:
return "FirefoxKey4"
case FirefoxPassword:
return "FirefoxPassword"
case FirefoxCookie:
return "FirefoxCookie"
case FirefoxBookmark:
return "FirefoxBookmark"
case FirefoxHistory:
return "FirefoxHistory"
case FirefoxDownload:
return "FirefoxDownload"
case FirefoxCreditCard:
return "FirefoxCreditCard"
case FirefoxLocalStorage:
return "FirefoxLocalStorage"
case FirefoxSessionStorage:
return "FirefoxSessionStorage"
case FirefoxExtension:
return "FirefoxExtension"
default:
return "UnsupportedItem"
}
}
// 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 {
return fileName
}
return UnsupportedItem
}
// TempFilename returns the temp filename for the item with suffix
// eg: chromiumKey_0.temp
func (i DataType) TempFilename() string {
const tempSuffix = "temp"
tempFile := fmt.Sprintf("%s_%d.%s", i.Filename(), i, tempSuffix)
return filepath.Join(os.TempDir(), tempFile)
}
// IsSensitive returns whether the item is sensitive data
// password, cookie, credit card, master key is unlimited
func (i DataType) IsSensitive() bool {
switch i {
case ChromiumKey, ChromiumCookie, ChromiumPassword, ChromiumCreditCard,
FirefoxKey4, FirefoxPassword, FirefoxCookie, FirefoxCreditCard,
YandexPassword, YandexCreditCard:
return true
default:
return false
}
}
// FilterSensitiveItems returns the sensitive items
func FilterSensitiveItems(items []DataType) []DataType {
var filtered []DataType
for _, item := range items {
if item.IsSensitive() {
filtered = append(filtered, item)
}
}
return filtered
}
// DefaultFirefoxTypes returns the default items for the firefox browser
var DefaultFirefoxTypes = []DataType{
FirefoxKey4,
FirefoxPassword,
FirefoxCookie,
FirefoxBookmark,
FirefoxHistory,
FirefoxDownload,
FirefoxCreditCard,
FirefoxLocalStorage,
FirefoxSessionStorage,
FirefoxExtension,
}
// DefaultYandexTypes returns the default items for the yandex browser
var DefaultYandexTypes = []DataType{
ChromiumKey,
ChromiumCookie,
ChromiumBookmark,
ChromiumHistory,
ChromiumDownload,
ChromiumExtension,
YandexPassword,
ChromiumLocalStorage,
ChromiumSessionStorage,
YandexCreditCard,
}
// DefaultChromiumTypes returns the default items for the chromium browser
var DefaultChromiumTypes = []DataType{
ChromiumKey,
ChromiumPassword,
ChromiumCookie,
ChromiumBookmark,
ChromiumHistory,
ChromiumDownload,
ChromiumCreditCard,
ChromiumLocalStorage,
ChromiumSessionStorage,
ChromiumExtension,
}
// item's default filename
const (
fileChromiumKey = "Local State"
fileChromiumCredit = "Web Data"
fileChromiumPassword = "Login Data"
fileChromiumHistory = "History"
fileChromiumDownload = "History"
fileChromiumCookie = "Cookies"
fileChromiumBookmark = "Bookmarks"
fileChromiumLocalStorage = "Local Storage/leveldb"
fileChromiumSessionStorage = "Session Storage"
fileChromiumExtension = "Secure Preferences" // TODO: add more extension files and folders, eg: Preferences
fileYandexPassword = "Ya Passman Data"
fileYandexCredit = "Ya Credit Cards"
fileFirefoxKey4 = "key4.db"
fileFirefoxCookie = "cookies.sqlite"
fileFirefoxPassword = "logins.json"
fileFirefoxData = "places.sqlite"
fileFirefoxLocalStorage = "webappsstore.sqlite"
fileFirefoxExtension = "extensions.json"
UnsupportedItem = "unsupported item"
)