mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-21 19:06:47 +02:00
refactor: remove go-openssl package
This commit is contained in:
@@ -2,6 +2,7 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"hack-browser-data/log"
|
"hack-browser-data/log"
|
||||||
"hack-browser-data/utils"
|
"hack-browser-data/utils"
|
||||||
|
|
||||||
@@ -67,12 +68,16 @@ func ParseDB() (results []*LoginData) {
|
|||||||
LoginUrl: url,
|
LoginUrl: url,
|
||||||
}
|
}
|
||||||
if len(pwd) > 3 {
|
if len(pwd) > 3 {
|
||||||
password = utils.Aes128CBCDecrypt(pwd[3:])
|
password, err = utils.Aes128CBCDecrypt(pwd[3:])
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loginD.Password = password
|
loginD.Password = password
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("%+v\n", loginD)
|
||||||
results = append(results, loginD)
|
results = append(results, loginD)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ module hack-browser-data
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/forgoer/openssl v0.0.0-20200331032942-ad9f8d57d8b1
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.0
|
github.com/mattn/go-sqlite3 v1.14.0
|
||||||
go.uber.org/zap v1.15.0
|
go.uber.org/zap v1.15.0
|
||||||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
||||||
|
|||||||
@@ -5,20 +5,26 @@ import (
|
|||||||
"hack-browser-data/core/common"
|
"hack-browser-data/core/common"
|
||||||
"hack-browser-data/log"
|
"hack-browser-data/log"
|
||||||
"hack-browser-data/utils"
|
"hack-browser-data/utils"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := utils.CopyDB(utils.GetDBPath(utils.LoginData), utils.LoginData)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
osName := runtime.GOOS
|
osName := runtime.GOOS
|
||||||
switch osName {
|
switch osName {
|
||||||
case "darwin":
|
case "darwin":
|
||||||
|
chromePath, err := utils.GetDBPath(utils.LoginData)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("can't find chrome.app in OS")
|
||||||
|
}
|
||||||
|
err = utils.CopyDB(chromePath, utils.LoginData)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
utils.InitChromeKey()
|
utils.InitChromeKey()
|
||||||
common.ParseDB()
|
common.ParseDB()
|
||||||
case "windows":
|
case "windows":
|
||||||
fmt.Println("Windows")
|
fmt.Println("Windows")
|
||||||
}
|
}
|
||||||
|
os.Remove(utils.LoginData)
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-66
@@ -5,12 +5,10 @@ import (
|
|||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
|
||||||
"hack-browser-data/log"
|
"hack-browser-data/log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/forgoer/openssl"
|
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,12 +24,12 @@ var (
|
|||||||
chromePass []byte
|
chromePass []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDBPath(dbName string) string {
|
func GetDBPath(dbName string) (string, error) {
|
||||||
s, err := filepath.Glob(macChromeDir + dbName)
|
s, err := filepath.Glob(macChromeDir + dbName)
|
||||||
if err != nil && len(s) == 0 {
|
if err != nil && len(s) == 0 {
|
||||||
panic(err)
|
return "", err
|
||||||
}
|
}
|
||||||
return s[0]
|
return s[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitChromeKey() {
|
func InitChromeKey() {
|
||||||
@@ -47,78 +45,33 @@ func InitChromeKey() {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if stderr.Len() > 0 {
|
if stderr.Len() > 0 {
|
||||||
panic(stderr.String())
|
panic(stderr.String())
|
||||||
}
|
}
|
||||||
// replace /n
|
// replace /n
|
||||||
temp := stdout.Bytes()
|
temp := stdout.Bytes()
|
||||||
chromePass = temp[:len(temp)-1]
|
chromePass = temp[:len(temp)-1]
|
||||||
|
DecryptPass(chromePass)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DecryptPass(chromePass []byte) {
|
||||||
chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New)
|
chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecryptPass(chromePass []byte) []byte {
|
func Aes128CBCDecrypt(encryptPass []byte) (string, error) {
|
||||||
l := pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New)
|
block, err := aes.NewCipher(chromeKey)
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func Aes128CBCDecrypt(encryptPass []byte) string {
|
|
||||||
src, err := openssl.AesCBCDecrypt(encryptPass, chromeKey, iv, openssl.PKCS5_PADDING)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
return "", err
|
||||||
}
|
}
|
||||||
return string(src)
|
dst := make([]byte, len(encryptPass))
|
||||||
|
mode := cipher.NewCBCDecrypter(block, iv)
|
||||||
|
mode.CryptBlocks(dst, encryptPass)
|
||||||
|
dst = PKCS5UnPadding(dst)
|
||||||
|
return string(dst), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AesDecrypt(ciphertext []byte, key, iv []byte) ([]byte, error) {
|
func PKCS5UnPadding(src []byte) []byte {
|
||||||
block, err := aes.NewCipher(key)
|
length := len(src)
|
||||||
if err != nil {
|
unpadding := int(src[length-1])
|
||||||
return nil, err
|
return src[:(length - unpadding)]
|
||||||
}
|
|
||||||
blockMode := cipher.NewCBCDecrypter(block, iv)
|
|
||||||
origData := make([]byte, len(ciphertext))
|
|
||||||
fmt.Println(blockMode.BlockSize())
|
|
||||||
//func (x *cbcDecrypter) CryptBlocks(dst, src []byte) {
|
|
||||||
// if len(src)%x.blockSize != 0 {
|
|
||||||
// panic("crypto/cipher: input not full blocks")
|
|
||||||
blockMode.CryptBlocks(origData, ciphertext)
|
|
||||||
origData = PKCS5UnPadding(origData)
|
|
||||||
return origData, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ZeroPadding(ciphertext []byte, blockSize int) []byte {
|
|
||||||
padding := blockSize - len(ciphertext)%blockSize
|
|
||||||
padtext := bytes.Repeat([]byte{0}, padding)
|
|
||||||
return append(ciphertext, padtext...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ZeroUnPadding(origData []byte) []byte {
|
|
||||||
length := len(origData)
|
|
||||||
unpadding := int(origData[length-1])
|
|
||||||
return origData[:(length - unpadding)]
|
|
||||||
}
|
|
||||||
|
|
||||||
func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
|
|
||||||
padding := blockSize - len(ciphertext)%blockSize
|
|
||||||
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
|
||||||
return append(ciphertext, padtext...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PKCS5UnPadding(origData []byte) []byte {
|
|
||||||
length := len(origData)
|
|
||||||
// 去掉最后一个字节 unpadding 次
|
|
||||||
unpadding := int(origData[length-1])
|
|
||||||
return origData[:(length - unpadding)]
|
|
||||||
}
|
|
||||||
|
|
||||||
func PKCS7Padding(ciphertext []byte, blockSize int) []byte {
|
|
||||||
padding := blockSize - len(ciphertext)%blockSize
|
|
||||||
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
|
|
||||||
return append(ciphertext, padtext...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PKCS7UnPadding(origData []byte) []byte {
|
|
||||||
length := len(origData)
|
|
||||||
unpadding := int(origData[length-1])
|
|
||||||
return origData[:(length - unpadding)]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user