2020-06-19 12:43:31 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2020-06-20 15:20:01 +00:00
|
|
|
"fmt"
|
2020-06-19 12:43:31 +00:00
|
|
|
"hack-browser-data/log"
|
|
|
|
"hack-browser-data/utils"
|
2020-06-22 09:23:18 +00:00
|
|
|
"time"
|
2020-06-19 12:43:31 +00:00
|
|
|
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2020-06-22 09:23:18 +00:00
|
|
|
"github.com/tidwall/gjson"
|
2020-06-19 12:43:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
Chrome = "Chrome"
|
|
|
|
Safari = "Safari"
|
|
|
|
)
|
|
|
|
|
2020-06-22 09:23:18 +00:00
|
|
|
var (
|
|
|
|
browserData = new(BrowserData)
|
|
|
|
bookmarkList []*Bookmarks
|
2020-06-22 10:34:41 +00:00
|
|
|
cookieList []*Cookies
|
2020-06-22 09:23:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
bookmarkID = "id"
|
|
|
|
bookmarkAdded = "date_added"
|
|
|
|
bookmarkUrl = "url"
|
|
|
|
bookmarkName = "name"
|
|
|
|
bookmarkType = "type"
|
|
|
|
bookmarkChildren = "children"
|
|
|
|
)
|
|
|
|
|
2020-06-22 10:34:41 +00:00
|
|
|
const (
|
|
|
|
queryHistory = ``
|
|
|
|
)
|
|
|
|
|
2020-06-19 12:43:31 +00:00
|
|
|
type (
|
|
|
|
BrowserData struct {
|
|
|
|
BrowserName string
|
2020-06-22 09:23:18 +00:00
|
|
|
LoginData []*LoginData
|
|
|
|
Bookmarks []*Bookmarks
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
|
|
|
LoginData struct {
|
2020-06-22 10:34:41 +00:00
|
|
|
UserName string `json:"user_name"`
|
|
|
|
encryptPass []byte `json:"-"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
LoginUrl string `json:"login_url"`
|
|
|
|
CreateDate time.Time `json:"create_date"`
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
2020-06-22 09:23:18 +00:00
|
|
|
Bookmarks struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
DateAdded time.Time `json:"date_added"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
2020-06-22 10:34:41 +00:00
|
|
|
Cookies struct {
|
|
|
|
KeyName string
|
|
|
|
encryptValue []byte
|
|
|
|
Value string
|
|
|
|
Host string
|
|
|
|
Path string
|
|
|
|
IsSecure bool
|
|
|
|
IsHTTPOnly bool
|
|
|
|
HasExpire bool
|
|
|
|
IsPersistent bool
|
|
|
|
CreateDate time.Time
|
|
|
|
ExpireDate time.Time
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
2020-06-22 09:23:18 +00:00
|
|
|
History struct {
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-06-22 09:23:18 +00:00
|
|
|
func ParseDB(dbname string) {
|
|
|
|
switch dbname {
|
|
|
|
case utils.LoginData:
|
|
|
|
r, err := parseLogin()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
for _, v := range r {
|
|
|
|
fmt.Printf("%+v\n", v)
|
|
|
|
}
|
|
|
|
case utils.Bookmarks:
|
|
|
|
parseBookmarks()
|
2020-06-22 10:34:41 +00:00
|
|
|
case utils.Cookies:
|
|
|
|
parseCookie()
|
2020-06-22 09:23:18 +00:00
|
|
|
}
|
2020-06-22 10:34:41 +00:00
|
|
|
|
2020-06-22 09:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseBookmarks() {
|
|
|
|
bookmarks, err := utils.ReadFile(utils.Bookmarks)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
r := gjson.Parse(bookmarks)
|
|
|
|
if r.Exists() {
|
|
|
|
roots := r.Get("roots")
|
|
|
|
roots.ForEach(func(key, value gjson.Result) bool {
|
2020-06-22 10:34:41 +00:00
|
|
|
getBookmarkChildren(value)
|
2020-06-22 09:23:18 +00:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
fmt.Println(len(bookmarkList))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 10:34:41 +00:00
|
|
|
var queryLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
2020-06-22 09:23:18 +00:00
|
|
|
|
|
|
|
func parseLogin() (results []*LoginData, err error) {
|
2020-06-19 12:43:31 +00:00
|
|
|
//datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch')
|
2020-06-22 10:34:41 +00:00
|
|
|
login := &LoginData{}
|
|
|
|
loginDB, err := sql.Open("sqlite3", utils.LoginData)
|
2020-06-19 12:43:31 +00:00
|
|
|
defer func() {
|
2020-06-22 10:34:41 +00:00
|
|
|
if err := loginDB.Close(); err != nil {
|
2020-06-19 12:43:31 +00:00
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2020-06-22 10:34:41 +00:00
|
|
|
err = loginDB.Ping()
|
|
|
|
rows, err := loginDB.Query(queryLogin)
|
2020-06-19 12:43:31 +00:00
|
|
|
defer func() {
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
for rows.Next() {
|
|
|
|
var (
|
2020-06-22 10:34:41 +00:00
|
|
|
url, username, password string
|
|
|
|
pwd []byte
|
|
|
|
create int64
|
2020-06-19 12:43:31 +00:00
|
|
|
)
|
2020-06-22 09:23:18 +00:00
|
|
|
err = rows.Scan(&url, &username, &pwd, &create)
|
2020-06-22 10:34:41 +00:00
|
|
|
login = &LoginData{
|
2020-06-19 12:43:31 +00:00
|
|
|
UserName: username,
|
|
|
|
encryptPass: pwd,
|
|
|
|
LoginUrl: url,
|
2020-06-22 09:23:18 +00:00
|
|
|
CreateDate: utils.TimeEpochFormat(create),
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
|
|
|
if len(pwd) > 3 {
|
2020-06-22 10:34:41 +00:00
|
|
|
// remove prefix 'v10'
|
2020-06-22 09:23:18 +00:00
|
|
|
password, err = utils.Aes128CBCDecrypt(pwd[3:])
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
2020-06-22 10:34:41 +00:00
|
|
|
login.Password = password
|
2020-06-19 12:43:31 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2020-06-22 10:34:41 +00:00
|
|
|
results = append(results, login)
|
2020-06-19 12:43:31 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-06-22 09:23:18 +00:00
|
|
|
|
2020-06-22 10:34:41 +00:00
|
|
|
var queryCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
|
|
|
func parseCookie() (results []*Cookies, err error) {
|
|
|
|
cookies := &Cookies{}
|
|
|
|
cookieDB, err := sql.Open("sqlite3", utils.Cookies)
|
|
|
|
defer func() {
|
|
|
|
if err := cookieDB.Close(); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
err = cookieDB.Ping()
|
|
|
|
rows, err := cookieDB.Query(queryCookie)
|
|
|
|
defer func() {
|
|
|
|
if err := rows.Close(); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
for rows.Next() {
|
|
|
|
var (
|
|
|
|
key, host, path, value string
|
|
|
|
isSecure, isHTTPOnly, hasExpire, isPersistent bool
|
|
|
|
createDate, expireDate int64
|
|
|
|
encryptValue []byte
|
|
|
|
)
|
|
|
|
err = rows.Scan(&key, &encryptValue, &host, &path, &createDate, &expireDate, &isSecure, &isHTTPOnly, &hasExpire, &isPersistent)
|
|
|
|
cookies = &Cookies{
|
|
|
|
KeyName: key,
|
|
|
|
Host: host,
|
|
|
|
Path: path,
|
|
|
|
encryptValue: encryptValue,
|
|
|
|
IsSecure: false,
|
|
|
|
IsHTTPOnly: false,
|
|
|
|
HasExpire: false,
|
|
|
|
IsPersistent: isPersistent,
|
|
|
|
CreateDate: utils.TimeEpochFormat(createDate),
|
|
|
|
ExpireDate: utils.TimeEpochFormat(expireDate),
|
|
|
|
}
|
|
|
|
if len(encryptValue) > 3 {
|
|
|
|
// remove prefix 'v10'
|
|
|
|
value, err = utils.Aes128CBCDecrypt(encryptValue[3:])
|
|
|
|
}
|
|
|
|
cookies.Value = value
|
|
|
|
cookieList = append(cookieList, cookies)
|
|
|
|
}
|
|
|
|
return cookieList, err
|
|
|
|
}
|
|
|
|
|
2020-06-22 09:23:18 +00:00
|
|
|
func parseHistory() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-22 10:34:41 +00:00
|
|
|
func getBookmarkChildren(value gjson.Result) (children gjson.Result) {
|
|
|
|
b := new(Bookmarks)
|
|
|
|
b.ID = value.Get(bookmarkID).String()
|
|
|
|
nodeType := value.Get(bookmarkType)
|
|
|
|
b.DateAdded = utils.TimeEpochFormat(value.Get(bookmarkAdded).Int())
|
|
|
|
b.URL = value.Get(bookmarkUrl).String()
|
|
|
|
b.Name = value.Get(bookmarkName).String()
|
|
|
|
children = value.Get(bookmarkChildren)
|
|
|
|
if nodeType.Exists() {
|
|
|
|
b.Type = nodeType.String()
|
|
|
|
bookmarkList = append(bookmarkList, b)
|
|
|
|
if children.Exists() && children.IsArray() {
|
|
|
|
for _, v := range children.Array() {
|
|
|
|
children = getBookmarkChildren(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return children
|
2020-06-22 09:23:18 +00:00
|
|
|
}
|