mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
591b97ce6d
* feat: Refactor crypto decryption functions for consistency and error handling - Close #301 - Refactored and renamed decryption functions across multiple files for consistency - Updated cookie sorting method to sort in descending order - Added new encryption functions for AES in CBC and GCM modes and DES in CBC mode - Added error handling to decryption functions and created new error variables for invalid ciphertext length and decode failures - Test cases added for encryption and decryption functions - Removed unused code and imports. * chore: Add new words to .typos.toml dictionary - Add new terms to `.typos.toml` dictionary - Improve code formatting and readability - Refactor functions for better performance - Update comments and documentation - Resolve minor bugs and errors * refactor: Refactor crypto package for better structure and readability - Refactored and cleaned up crypto package code for better readability - Renamed `ToByteArray` method to `bytes` for consistency - Modified `DecryptWithDPAPI` method to use `outBlob.bytes()` for efficiency - Added comments and removed unused methods in `loginPBE` - Refactored `nssPBE` and `metaPBE` Decrypt methods to use `deriveKeyAndIV` helper method - Improved overall maintainability and organization of codebase * refactor: Refactor firefox password encryption and decryption. - Implement ASN1PBE interface with various PBE struct types and encryption/decryption methods - Fix naming and remove unused variables in browsingdata and crypto files - Add tests for ASN1PBE implementation using external assertion package - Refactor and improve error handling in firefox file functions related to master key retrieval - Add input validation and AES-GCM encryption function to crypto file
242 lines
5.2 KiB
Go
242 lines
5.2 KiB
Go
package password
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/base64"
|
|
"log/slog"
|
|
"os"
|
|
"sort"
|
|
"time"
|
|
|
|
"github.com/tidwall/gjson"
|
|
_ "modernc.org/sqlite" // import sqlite3 driver
|
|
|
|
"github.com/moond4rk/hackbrowserdata/crypto"
|
|
"github.com/moond4rk/hackbrowserdata/item"
|
|
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
|
|
)
|
|
|
|
type ChromiumPassword []loginData
|
|
|
|
type loginData struct {
|
|
UserName string
|
|
encryptPass []byte
|
|
encryptUser []byte
|
|
Password string
|
|
LoginURL string
|
|
CreateDate time.Time
|
|
}
|
|
|
|
const (
|
|
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
|
)
|
|
|
|
func (c *ChromiumPassword) Parse(masterKey []byte) error {
|
|
db, err := sql.Open("sqlite", item.ChromiumPassword.TempFilename())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.Remove(item.ChromiumPassword.TempFilename())
|
|
defer db.Close()
|
|
|
|
rows, err := db.Query(queryChromiumLogin)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var (
|
|
url, username string
|
|
pwd, password []byte
|
|
create int64
|
|
)
|
|
if err := rows.Scan(&url, &username, &pwd, &create); err != nil {
|
|
slog.Error("scan chromium password error", "err", err)
|
|
}
|
|
login := loginData{
|
|
UserName: username,
|
|
encryptPass: pwd,
|
|
LoginURL: url,
|
|
}
|
|
if len(pwd) > 0 {
|
|
if len(masterKey) == 0 {
|
|
password, err = crypto.DecryptWithDPAPI(pwd)
|
|
} else {
|
|
password, err = crypto.DecryptWithChromium(masterKey, pwd)
|
|
}
|
|
if err != nil {
|
|
slog.Error("decrypt chromium password error", "err", err)
|
|
}
|
|
}
|
|
if create > time.Now().Unix() {
|
|
login.CreateDate = typeutil.TimeEpoch(create)
|
|
} else {
|
|
login.CreateDate = typeutil.TimeStamp(create)
|
|
}
|
|
login.Password = string(password)
|
|
*c = append(*c, login)
|
|
}
|
|
// sort with create date
|
|
sort.Slice(*c, func(i, j int) bool {
|
|
return (*c)[i].CreateDate.After((*c)[j].CreateDate)
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (c *ChromiumPassword) Name() string {
|
|
return "password"
|
|
}
|
|
|
|
func (c *ChromiumPassword) Len() int {
|
|
return len(*c)
|
|
}
|
|
|
|
type YandexPassword []loginData
|
|
|
|
const (
|
|
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
|
)
|
|
|
|
func (c *YandexPassword) Parse(masterKey []byte) error {
|
|
db, err := sql.Open("sqlite", item.YandexPassword.TempFilename())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer os.Remove(item.YandexPassword.TempFilename())
|
|
defer db.Close()
|
|
|
|
rows, err := db.Query(queryYandexLogin)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
|
|
for rows.Next() {
|
|
var (
|
|
url, username string
|
|
pwd, password []byte
|
|
create int64
|
|
)
|
|
if err := rows.Scan(&url, &username, &pwd, &create); err != nil {
|
|
slog.Error("scan yandex password error", "err", err)
|
|
}
|
|
login := loginData{
|
|
UserName: username,
|
|
encryptPass: pwd,
|
|
LoginURL: url,
|
|
}
|
|
|
|
if len(pwd) > 0 {
|
|
if len(masterKey) == 0 {
|
|
password, err = crypto.DecryptWithDPAPI(pwd)
|
|
} else {
|
|
password, err = crypto.DecryptWithChromium(masterKey, pwd)
|
|
}
|
|
if err != nil {
|
|
slog.Error("decrypt yandex password error", "err", err)
|
|
}
|
|
}
|
|
if create > time.Now().Unix() {
|
|
login.CreateDate = typeutil.TimeEpoch(create)
|
|
} else {
|
|
login.CreateDate = typeutil.TimeStamp(create)
|
|
}
|
|
login.Password = string(password)
|
|
*c = append(*c, login)
|
|
}
|
|
// sort with create date
|
|
sort.Slice(*c, func(i, j int) bool {
|
|
return (*c)[i].CreateDate.After((*c)[j].CreateDate)
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (c *YandexPassword) Name() string {
|
|
return "password"
|
|
}
|
|
|
|
func (c *YandexPassword) Len() int {
|
|
return len(*c)
|
|
}
|
|
|
|
type FirefoxPassword []loginData
|
|
|
|
func (f *FirefoxPassword) Parse(globalSalt []byte) error {
|
|
logins, err := getFirefoxLoginData()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, v := range logins {
|
|
userPBE, err := crypto.NewASN1PBE(v.encryptUser)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pwdPBE, err := crypto.NewASN1PBE(v.encryptPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
user, err := userPBE.Decrypt(globalSalt)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pwd, err := pwdPBE.Decrypt(globalSalt)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*f = append(*f, loginData{
|
|
LoginURL: v.LoginURL,
|
|
UserName: string(user),
|
|
Password: string(pwd),
|
|
CreateDate: v.CreateDate,
|
|
})
|
|
}
|
|
|
|
sort.Slice(*f, func(i, j int) bool {
|
|
return (*f)[i].CreateDate.After((*f)[j].CreateDate)
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func getFirefoxLoginData() ([]loginData, error) {
|
|
s, err := os.ReadFile(item.FirefoxPassword.TempFilename())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer os.Remove(item.FirefoxPassword.TempFilename())
|
|
loginsJSON := gjson.GetBytes(s, "logins")
|
|
var logins []loginData
|
|
if loginsJSON.Exists() {
|
|
for _, v := range loginsJSON.Array() {
|
|
var (
|
|
m loginData
|
|
user []byte
|
|
pass []byte
|
|
)
|
|
m.LoginURL = v.Get("formSubmitURL").String()
|
|
user, err = base64.StdEncoding.DecodeString(v.Get("encryptedUsername").String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pass, err = base64.StdEncoding.DecodeString(v.Get("encryptedPassword").String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
m.encryptUser = user
|
|
m.encryptPass = pass
|
|
m.CreateDate = typeutil.TimeStamp(v.Get("timeCreated").Int() / 1000)
|
|
logins = append(logins, m)
|
|
}
|
|
}
|
|
return logins, nil
|
|
}
|
|
|
|
func (f *FirefoxPassword) Name() string {
|
|
return "password"
|
|
}
|
|
|
|
func (f *FirefoxPassword) Len() int {
|
|
return len(*f)
|
|
}
|