You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
6.4 KiB
293 lines
6.4 KiB
3 years ago
|
package password
|
||
3 years ago
|
|
||
|
import (
|
||
3 years ago
|
"bytes"
|
||
3 years ago
|
"database/sql"
|
||
3 years ago
|
"encoding/base64"
|
||
3 years ago
|
"os"
|
||
3 years ago
|
"sort"
|
||
|
"time"
|
||
|
|
||
2 years ago
|
// import sqlite3 driver
|
||
|
_ "github.com/mattn/go-sqlite3"
|
||
|
"github.com/tidwall/gjson"
|
||
2 years ago
|
|
||
|
"github.com/moond4rk/HackBrowserData/crypto"
|
||
|
"github.com/moond4rk/HackBrowserData/item"
|
||
|
"github.com/moond4rk/HackBrowserData/log"
|
||
|
"github.com/moond4rk/HackBrowserData/utils/typeutil"
|
||
3 years ago
|
)
|
||
|
|
||
|
type ChromiumPassword []loginData
|
||
|
|
||
3 years ago
|
type loginData struct {
|
||
|
UserName string
|
||
|
encryptPass []byte
|
||
|
encryptUser []byte
|
||
|
Password string
|
||
2 years ago
|
LoginURL string
|
||
3 years ago
|
CreateDate time.Time
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||
|
)
|
||
|
|
||
3 years ago
|
func (c *ChromiumPassword) Parse(masterKey []byte) error {
|
||
3 years ago
|
loginDB, err := sql.Open("sqlite3", item.TempChromiumPassword)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
3 years ago
|
defer os.Remove(item.TempChromiumPassword)
|
||
3 years ago
|
defer loginDB.Close()
|
||
|
rows, err := loginDB.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 {
|
||
3 years ago
|
log.Warn(err)
|
||
3 years ago
|
}
|
||
|
login := loginData{
|
||
|
UserName: username,
|
||
|
encryptPass: pwd,
|
||
2 years ago
|
LoginURL: url,
|
||
3 years ago
|
}
|
||
|
if len(pwd) > 0 {
|
||
3 years ago
|
var err error
|
||
3 years ago
|
if masterKey == nil {
|
||
2 years ago
|
password, err = crypto.DPAPI(pwd)
|
||
3 years ago
|
} else {
|
||
2 years ago
|
password, err = crypto.Chromium(masterKey, pwd)
|
||
3 years ago
|
}
|
||
3 years ago
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
}
|
||
3 years ago
|
}
|
||
|
if create > time.Now().Unix() {
|
||
3 years ago
|
login.CreateDate = typeutil.TimeEpoch(create)
|
||
3 years ago
|
} else {
|
||
3 years ago
|
login.CreateDate = typeutil.TimeStamp(create)
|
||
3 years ago
|
}
|
||
|
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"
|
||
|
}
|
||
|
|
||
3 years ago
|
func (c *ChromiumPassword) Length() int {
|
||
|
return len(*c)
|
||
|
}
|
||
|
|
||
3 years ago
|
type YandexPassword []loginData
|
||
|
|
||
3 years ago
|
const (
|
||
|
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
||
|
)
|
||
|
|
||
3 years ago
|
func (c *YandexPassword) Parse(masterKey []byte) error {
|
||
|
loginDB, err := sql.Open("sqlite3", item.TempYandexPassword)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer os.Remove(item.TempYandexPassword)
|
||
|
defer loginDB.Close()
|
||
3 years ago
|
rows, err := loginDB.Query(queryYandexLogin)
|
||
3 years ago
|
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 {
|
||
|
log.Warn(err)
|
||
|
}
|
||
|
login := loginData{
|
||
|
UserName: username,
|
||
|
encryptPass: pwd,
|
||
2 years ago
|
LoginURL: url,
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
if len(pwd) > 0 {
|
||
|
var err error
|
||
|
if masterKey == nil {
|
||
2 years ago
|
password, err = crypto.DPAPI(pwd)
|
||
3 years ago
|
} else {
|
||
2 years ago
|
password, err = crypto.Chromium(masterKey, pwd)
|
||
3 years ago
|
}
|
||
|
if err != nil {
|
||
3 years ago
|
log.Errorf("decrypt yandex password error %s", err)
|
||
3 years ago
|
}
|
||
|
}
|
||
|
if create > time.Now().Unix() {
|
||
3 years ago
|
login.CreateDate = typeutil.TimeEpoch(create)
|
||
3 years ago
|
} else {
|
||
3 years ago
|
login.CreateDate = typeutil.TimeStamp(create)
|
||
3 years ago
|
}
|
||
|
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"
|
||
|
}
|
||
|
|
||
3 years ago
|
func (c *YandexPassword) Length() int {
|
||
|
return len(*c)
|
||
|
}
|
||
|
|
||
3 years ago
|
type FirefoxPassword []loginData
|
||
|
|
||
3 years ago
|
const (
|
||
|
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
|
||
|
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
|
||
|
)
|
||
|
|
||
3 years ago
|
func (f *FirefoxPassword) Parse(masterKey []byte) error {
|
||
3 years ago
|
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
2 years ago
|
metaPBE, err := crypto.NewASN1PBE(metaBytes)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
3 years ago
|
|
||
3 years ago
|
k, err := metaPBE.Decrypt(globalSalt, masterKey)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
keyLin := []byte{248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
||
|
if bytes.Contains(k, []byte("password-check")) {
|
||
|
m := bytes.Compare(nssA102, keyLin)
|
||
|
if m == 0 {
|
||
2 years ago
|
nssPBE, err := crypto.NewASN1PBE(nssA11)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
finallyKey, err := nssPBE.Decrypt(globalSalt, masterKey)
|
||
|
finallyKey = finallyKey[:24]
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
2 years ago
|
allLogin, err := getFirefoxLoginData()
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, v := range allLogin {
|
||
2 years ago
|
userPBE, err := crypto.NewASN1PBE(v.encryptUser)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
2 years ago
|
pwdPBE, err := crypto.NewASN1PBE(v.encryptPass)
|
||
3 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
user, err := userPBE.Decrypt(finallyKey, masterKey)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
pwd, err := pwdPBE.Decrypt(finallyKey, masterKey)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
*f = append(*f, loginData{
|
||
2 years ago
|
LoginURL: v.LoginURL,
|
||
3 years ago
|
UserName: string(user),
|
||
|
Password: string(pwd),
|
||
3 years ago
|
CreateDate: v.CreateDate,
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
sort.Slice(*f, func(i, j int) bool {
|
||
|
return (*f)[i].CreateDate.After((*f)[j].CreateDate)
|
||
|
})
|
||
3 years ago
|
return nil
|
||
|
}
|
||
3 years ago
|
|
||
|
func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err error) {
|
||
3 years ago
|
var keyDB *sql.DB
|
||
3 years ago
|
keyDB, err = sql.Open("sqlite3", key4file)
|
||
|
if err != nil {
|
||
|
return nil, nil, nil, nil, err
|
||
|
}
|
||
3 years ago
|
defer os.Remove(key4file)
|
||
3 years ago
|
defer keyDB.Close()
|
||
|
|
||
|
if err = keyDB.QueryRow(queryMetaData).Scan(&item1, &item2); err != nil {
|
||
|
return nil, nil, nil, nil, err
|
||
|
}
|
||
|
|
||
|
if err = keyDB.QueryRow(queryNssPrivate).Scan(&a11, &a102); err != nil {
|
||
|
return nil, nil, nil, nil, err
|
||
|
}
|
||
|
return item1, item2, a11, a102, nil
|
||
|
}
|
||
|
|
||
2 years ago
|
func getFirefoxLoginData() (l []loginData, err error) {
|
||
|
s, err := os.ReadFile(item.TempFirefoxPassword)
|
||
3 years ago
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
2 years ago
|
defer os.Remove(item.TempFirefoxPassword)
|
||
3 years ago
|
h := gjson.GetBytes(s, "logins")
|
||
|
if h.Exists() {
|
||
|
for _, v := range h.Array() {
|
||
|
var (
|
||
|
m loginData
|
||
|
user []byte
|
||
|
pass []byte
|
||
|
)
|
||
2 years ago
|
m.LoginURL = v.Get("formSubmitURL").String()
|
||
3 years ago
|
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
|
||
3 years ago
|
m.CreateDate = typeutil.TimeStamp(v.Get("timeCreated").Int() / 1000)
|
||
3 years ago
|
l = append(l, m)
|
||
|
}
|
||
|
}
|
||
|
return l, nil
|
||
|
}
|
||
3 years ago
|
|
||
|
func (f *FirefoxPassword) Name() string {
|
||
|
return "password"
|
||
|
}
|
||
|
|
||
|
func (f *FirefoxPassword) Length() int {
|
||
|
return len(*f)
|
||
|
}
|