feat: add history parse

pull/83/head
ᴍᴏᴏɴD4ʀᴋ 4 years ago
parent 000c4fe583
commit 7e472c5cee
  1. 56
      cmd/cmd.go
  2. 104
      core/common/common.go
  3. 2
      go.mod
  4. 79
      go.sum
  5. 2
      log/log.go
  6. 36
      main.go
  7. 40
      utils/utils.go
  8. 32
      utils/utils_darwin.go
  9. 12
      utils/utils_test.go

@ -0,0 +1,56 @@
package cmd
import (
"hack-browser-data/log"
"hack-browser-data/utils"
"os"
"runtime"
"github.com/urfave/cli/v2"
)
var (
browser string
exportData string
exportDir string
outputFormat string
verbose bool
)
func Execute() {
app := &cli.App{
Name: "hack-browser-data",
Usage: "export password/cookie/history/bookmark from browser",
Version: "0.0.1",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "verbose", Aliases: []string{"vv"}, Destination: &verbose, Value: false, Usage: "verbose"},
&cli.StringFlag{Name: "browser", Aliases: []string{"b"}, Destination: &browser, Value: "all", Usage: "browser name, all|chrome|safari"},
&cli.StringFlag{Name: "dir", Aliases: []string{"d"}, Destination: &exportDir, Value: "data", Usage: "export dir"},
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Destination: &outputFormat, Value: "csv", Usage: "result format, csv|json"},
&cli.StringFlag{Name: "export-data", Aliases: []string{"e"}, Destination: &exportData, Value: "all", Usage: "all|password|cookie|history|bookmark"},
},
Action: func(c *cli.Context) error {
log.InitLog()
switch runtime.GOOS {
case "darwin":
err := utils.InitChromeKey()
if err != nil {
}
case "windows":
}
switch {
case browser == "all":
case exportDir == "data":
case exportData == "all":
case outputFormat == "json":
}
return nil
},
}
err := app.Run(os.Args)
if err != nil {
panic(err)
return
}
}

@ -5,8 +5,10 @@ import (
"fmt" "fmt"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils" "hack-browser-data/utils"
"time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson"
) )
const ( const (
@ -14,26 +16,98 @@ const (
Safari = "Safari" Safari = "Safari"
) )
var (
browserData = new(BrowserData)
bookmarkList []*Bookmarks
)
const (
bookmarkID = "id"
bookmarkAdded = "date_added"
bookmarkUrl = "url"
bookmarkName = "name"
bookmarkType = "type"
bookmarkChildren = "children"
)
type ( type (
BrowserData struct { BrowserData struct {
BrowserName string BrowserName string
LoginData []LoginData LoginData []*LoginData
Bookmarks []*Bookmarks
} }
LoginData struct { LoginData struct {
UserName string UserName string
encryptPass []byte encryptPass []byte
Password string Password string
LoginUrl string LoginUrl string
CreateDate time.Time
} }
History struct { Bookmarks struct {
ID string `json:"id"`
DateAdded time.Time `json:"date_added"`
URL string `json:"url"`
Name string `json:"name"`
Type string `json:"type"`
} }
Cookie struct { Cookie struct {
} }
BookMark struct { History struct {
} }
) )
func ParseDB() (results []*LoginData) { 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()
}
}
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 {
getBookmarkValue(value)
return true
})
fmt.Println(len(bookmarkList))
}
}
func getBookmarkValue(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 = getBookmarkValue(v)
}
}
}
return children
}
func parseLogin() (results []*LoginData, err error) {
//datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch') //datetime(visit_time / 1000000 + (strftime('%s', '1601-01-01')), 'unixepoch')
loginD := &LoginData{} loginD := &LoginData{}
logins, err := sql.Open("sqlite3", utils.LoginData) logins, err := sql.Open("sqlite3", utils.LoginData)
@ -46,39 +120,47 @@ func ParseDB() (results []*LoginData) {
log.Println(err) log.Println(err)
} }
err = logins.Ping() err = logins.Ping()
log.Println(err) rows, err := logins.Query(`SELECT origin_url, username_value, password_value, date_created FROM logins`)
rows, err := logins.Query(`SELECT origin_url, username_value, password_value FROM logins`)
defer func() { defer func() {
if err := rows.Close(); err != nil { if err := rows.Close(); err != nil {
log.Println(err) log.Println(err)
} }
}() }()
log.Println(err)
for rows.Next() { for rows.Next() {
var ( var (
url string url string
username string username string
pwd []byte pwd []byte
password string password string
create int64
) )
err = rows.Scan(&url, &username, &pwd) err = rows.Scan(&url, &username, &pwd, &create)
loginD = &LoginData{ loginD = &LoginData{
UserName: username, UserName: username,
encryptPass: pwd, encryptPass: pwd,
LoginUrl: url, LoginUrl: url,
CreateDate: utils.TimeEpochFormat(create),
} }
if len(pwd) > 3 { if len(pwd) > 3 {
password, err = utils.Aes128CBCDecrypt(pwd[3:])
if err != nil { if err != nil {
panic(err) log.Println(err)
continue
} }
password, err = utils.Aes128CBCDecrypt(pwd[3:])
} }
loginD.Password = password loginD.Password = password
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
fmt.Printf("%+v\n", loginD)
results = append(results, loginD) results = append(results, loginD)
} }
return return
} }
func parseHistory() {
}
func parseCookie() {
}

@ -4,6 +4,8 @@ go 1.14
require ( require (
github.com/mattn/go-sqlite3 v1.14.0 github.com/mattn/go-sqlite3 v1.14.0
github.com/tidwall/gjson v1.6.0
github.com/urfave/cli/v2 v2.2.0
go.uber.org/zap v1.15.0 go.uber.org/zap v1.15.0
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
) )

@ -0,0 +1,79 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

@ -20,7 +20,7 @@ var (
} }
) )
func init() { func InitLog() {
logger := newLogger("debug") logger := newLogger("debug")
formatLogger = logger.Sugar() formatLogger = logger.Sugar()
} }

@ -5,26 +5,40 @@ import (
"hack-browser-data/core/common" "hack-browser-data/core/common"
"hack-browser-data/log" "hack-browser-data/log"
"hack-browser-data/utils" "hack-browser-data/utils"
"os" "path/filepath"
"runtime" "runtime"
) )
func main() { func main() {
log.InitLog()
parse()
}
func parse() {
osName := runtime.GOOS osName := runtime.GOOS
switch osName { switch osName {
case "darwin": case "darwin":
chromePath, err := utils.GetDBPath(utils.LoginData) //err := utils.InitChromeKey()
if err != nil { //if err != nil {
log.Error("can't find chrome.app in OS") // log.Println(err)
} // panic("init chrome key failed")
err = utils.CopyDB(chromePath, utils.LoginData) //}
case "windows":
fmt.Println("Windows")
}
//chromePath, err := utils.GetDBPath(utils.LoginData, utils.History, utils.BookMarks, utils.Cookies, utils.WebData)
chromePath, err := utils.GetDBPath(utils.Bookmarks)
if err != nil {
log.Error("can't find chrome.app in OS")
}
for _, v := range chromePath {
dst := filepath.Base(v)
err := utils.CopyDB(v, dst)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
continue
} }
utils.InitChromeKey() common.ParseDB(dst)
common.ParseDB()
case "windows":
fmt.Println("Windows")
} }
os.Remove(utils.LoginData)
} }

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time"
) )
const ( const (
@ -12,28 +13,53 @@ const (
History = "History" History = "History"
Cookies = "Cookies" Cookies = "Cookies"
WebData = "Web Data" WebData = "Web Data"
Bookmarks = "Bookmarks"
) )
func CopyDB(source, dest string) error { func CopyDB(src, dst string) error {
// remove current path db file first
locals, _ := filepath.Glob("*") locals, _ := filepath.Glob("*")
for _, v := range locals { for _, v := range locals {
if v == dest { if v == dst {
err := os.Remove(dest) err := os.Remove(dst)
if err != nil { if err != nil {
return err return err
} }
} }
} }
sourceFile, err := ioutil.ReadFile(source) sourceFile, err := ioutil.ReadFile(src)
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
err = ioutil.WriteFile(dest, sourceFile, 644) err = ioutil.WriteFile(dst, sourceFile, 0777)
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
err = os.Chmod(dest, 0777)
return err return err
} }
func ParseBookMarks() {
}
func RemoveFile() {
}
func TimeEpochFormat(epoch int64) time.Time {
t := time.Date(1601, 1, 1, 0, 0, 0, 0, time.UTC)
d := time.Duration(epoch)
for i := 0; i < 1000; i++ {
t = t.Add(d)
}
return t
}
func ReadFile(filename string) (string, error) {
s, err := ioutil.ReadFile(filename)
return string(s), err
}
//func MakeDir(dirName string) error {
//
//}

@ -5,6 +5,7 @@ import (
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
"crypto/sha1" "crypto/sha1"
"errors"
"hack-browser-data/log" "hack-browser-data/log"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -24,15 +25,20 @@ var (
chromePass []byte chromePass []byte
) )
func GetDBPath(dbName string) (string, error) { func GetDBPath(dbName ...string) (dbFile []string, err error) {
s, err := filepath.Glob(macChromeDir + dbName) for _, v := range dbName {
if err != nil && len(s) == 0 { s, err := filepath.Glob(macChromeDir + v)
return "", err if err != nil && len(s) == 0 {
continue
}
if len(s) > 0{
dbFile = append(dbFile, s[0])
}
} }
return s[0], nil return dbFile, nil
} }
func InitChromeKey() { func InitChromeKey() error {
var ( var (
cmd *exec.Cmd cmd *exec.Cmd
stdout, stderr bytes.Buffer stdout, stderr bytes.Buffer
@ -43,22 +49,26 @@ func InitChromeKey() {
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log.Println(err) log.Println(err)
panic(err) return err
} }
if stderr.Len() > 0 { if stderr.Len() > 0 {
panic(stderr.String()) log.Println(stderr.String())
err = errors.New(stderr.String())
} }
// replace /n
temp := stdout.Bytes() temp := stdout.Bytes()
chromePass = temp[:len(temp)-1] chromePass = temp[:len(temp)-1]
DecryptPass(chromePass) decryptPass(chromePass)
return err
} }
func DecryptPass(chromePass []byte) { func decryptPass(chromePass []byte) {
chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New) chromeKey = pbkdf2.Key(chromePass, chromeSalt, 1003, 16, sha1.New)
} }
func Aes128CBCDecrypt(encryptPass []byte) (string, error) { func Aes128CBCDecrypt(encryptPass []byte) (string, error) {
if chromeKey == nil {
return "", nil
}
block, err := aes.NewCipher(chromeKey) block, err := aes.NewCipher(chromeKey)
if err != nil { if err != nil {
return "", err return "", err

@ -0,0 +1,12 @@
package utils
import (
"fmt"
"testing"
)
func TestTimeEpochFormat(t *testing.T) {
dateAdded := int64(13220074277028707)
s := TimeEpochFormat(dateAdded)
fmt.Println(s)
}
Loading…
Cancel
Save