|
|
|
@ -1,66 +1,17 @@ |
|
|
|
|
package utils |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"crypto/aes" |
|
|
|
|
"crypto/cipher" |
|
|
|
|
"crypto/des" |
|
|
|
|
"encoding/asn1" |
|
|
|
|
"fmt" |
|
|
|
|
"hack-browser-data/log" |
|
|
|
|
"io/ioutil" |
|
|
|
|
"os" |
|
|
|
|
"path" |
|
|
|
|
"path/filepath" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type DecryptError struct { |
|
|
|
|
err error |
|
|
|
|
msg string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *DecryptError) Error() string { |
|
|
|
|
return fmt.Sprintf("%s: %s", e.msg, e.err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *DecryptError) Unwrap() error { |
|
|
|
|
return e.err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Browser struct { |
|
|
|
|
Name string |
|
|
|
|
DataDir string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
LoginData = "Login Data" |
|
|
|
|
History = "History" |
|
|
|
|
Cookies = "Cookies" |
|
|
|
|
Bookmarks = "Bookmarks" |
|
|
|
|
FirefoxCookie = "cookies.sqlite" |
|
|
|
|
FirefoxKey4DB = "key4.db" |
|
|
|
|
FirefoxLoginData = "logins.json" |
|
|
|
|
FirefoxData = "places.sqlite" |
|
|
|
|
FirefoxKey3DB = "key3.db" |
|
|
|
|
"hack-browser-data/log" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetDBPath(dir string, dbName ...string) (dbFile []string) { |
|
|
|
|
for _, v := range dbName { |
|
|
|
|
s, err := filepath.Glob(dir + v) |
|
|
|
|
if err != nil && len(s) == 0 { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
if len(s) > 0 { |
|
|
|
|
log.Debugf("Find %s File Success", v) |
|
|
|
|
log.Debugf("%s file location is %s", v, s[0]) |
|
|
|
|
dbFile = append(dbFile, s[0]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return dbFile |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func CopyDB(src, dst string) error { |
|
|
|
|
locals, _ := filepath.Glob("*") |
|
|
|
|
for _, v := range locals { |
|
|
|
@ -117,16 +68,6 @@ func TimeEpochFormat(epoch int64) time.Time { |
|
|
|
|
return t |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check time our range[1.9999]
|
|
|
|
|
func checkTimeRange(check time.Time) time.Time { |
|
|
|
|
end, _ := time.Parse(time.RFC3339, "9000-01-02T15:04:05Z07:00") |
|
|
|
|
if check.Before(end) { |
|
|
|
|
return check |
|
|
|
|
} else { |
|
|
|
|
return end |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func ReadFile(filename string) (string, error) { |
|
|
|
|
s, err := ioutil.ReadFile(filename) |
|
|
|
|
return string(s), err |
|
|
|
@ -152,74 +93,3 @@ func MakeDir(dirName string) { |
|
|
|
|
err = os.Mkdir(dirName, 0700) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func PaddingZero(s []byte, l int) []byte { |
|
|
|
|
h := l - len(s) |
|
|
|
|
if h <= 0 { |
|
|
|
|
return s |
|
|
|
|
} else { |
|
|
|
|
for i := len(s); i < l; i++ { |
|
|
|
|
s = append(s, 0) |
|
|
|
|
} |
|
|
|
|
return s |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func PKCS5UnPadding(src []byte) []byte { |
|
|
|
|
length := len(src) |
|
|
|
|
unpadding := int(src[length-1]) |
|
|
|
|
return src[:(length - unpadding)] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Des3Decrypt(key, iv []byte, src []byte) ([]byte, error) { |
|
|
|
|
block, err := des.NewTripleDESCipher(key) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
blockMode := cipher.NewCBCDecrypter(block, iv) |
|
|
|
|
sq := make([]byte, len(src)) |
|
|
|
|
blockMode.CryptBlocks(sq, src) |
|
|
|
|
return sq, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
SEQUENCE (3 elem) |
|
|
|
|
OCTET STRING (16 byte) |
|
|
|
|
SEQUENCE (2 elem) |
|
|
|
|
OBJECT IDENTIFIER 1.2.840.113549.3.7 des-EDE3-CBC (RSADSI encryptionAlgorithm) |
|
|
|
|
OCTET STRING (8 byte) |
|
|
|
|
OCTET STRING (16 byte) |
|
|
|
|
*/ |
|
|
|
|
type LoginPBE struct { |
|
|
|
|
CipherText []byte |
|
|
|
|
SequenceLogin |
|
|
|
|
Encrypted []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type SequenceLogin struct { |
|
|
|
|
asn1.ObjectIdentifier |
|
|
|
|
Iv []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func DecodeLogin(decodeItem []byte) (pbe LoginPBE, err error) { |
|
|
|
|
_, err = asn1.Unmarshal(decodeItem, &pbe) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
return pbe, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func aes128CBCDecrypt(key, iv, encryptPass []byte) ([]byte, error) { |
|
|
|
|
|
|
|
|
|
block, err := aes.NewCipher(key) |
|
|
|
|
if err != nil { |
|
|
|
|
return []byte{}, err |
|
|
|
|
} |
|
|
|
|
dst := make([]byte, len(encryptPass)) |
|
|
|
|
mode := cipher.NewCBCDecrypter(block, iv) |
|
|
|
|
mode.CryptBlocks(dst, encryptPass) |
|
|
|
|
dst = PKCS5UnPadding(dst) |
|
|
|
|
return dst, nil |
|
|
|
|
} |
|
|
|
|