|
|
@ -1,66 +1,17 @@ |
|
|
|
package utils |
|
|
|
package utils |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"crypto/aes" |
|
|
|
|
|
|
|
"crypto/cipher" |
|
|
|
|
|
|
|
"crypto/des" |
|
|
|
|
|
|
|
"encoding/asn1" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"hack-browser-data/log" |
|
|
|
|
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"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 { |
|
|
|
"hack-browser-data/log" |
|
|
|
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" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
func CopyDB(src, dst string) error { |
|
|
|
locals, _ := filepath.Glob("*") |
|
|
|
locals, _ := filepath.Glob("*") |
|
|
|
for _, v := range locals { |
|
|
|
for _, v := range locals { |
|
|
@ -117,16 +68,6 @@ func TimeEpochFormat(epoch int64) time.Time { |
|
|
|
return t |
|
|
|
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) { |
|
|
|
func ReadFile(filename string) (string, error) { |
|
|
|
s, err := ioutil.ReadFile(filename) |
|
|
|
s, err := ioutil.ReadFile(filename) |
|
|
|
return string(s), err |
|
|
|
return string(s), err |
|
|
@ -152,74 +93,3 @@ func MakeDir(dirName string) { |
|
|
|
err = os.Mkdir(dirName, 0700) |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|