feat: rename item temp filename

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent 580ff78ad3
commit 46f2610a0a
  1. 11
      internal/browingdata/bookmark.go
  2. 46
      internal/browingdata/browsingdata.go
  3. 11
      internal/browingdata/cookie.go
  4. 5
      internal/browingdata/creditcard.go
  5. 10
      internal/browingdata/download.go
  6. 9
      internal/browingdata/history.go
  7. 29
      internal/browingdata/password.go
  8. 40
      internal/browser/browser.go
  9. 160
      internal/browser/browser_test.go
  10. 76
      internal/browser/chromium/chromium.go
  11. 11
      internal/browser/chromium/chromium_darwin.go
  12. 11
      internal/browser/chromium/chromium_windows.go
  13. 241
      internal/browser/firefox/firefox.go
  14. 25
      internal/item/filename.go
  15. 145
      internal/item/item.go

@ -3,6 +3,7 @@ package browingdata
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"os"
"sort" "sort"
"time" "time"
@ -11,6 +12,8 @@ import (
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
"hack-browser-data/internal/utils" "hack-browser-data/internal/utils"
"hack-browser-data/internal/utils/fileutil" "hack-browser-data/internal/utils/fileutil"
_ "github.com/mattn/go-sqlite3"
) )
type ChromiumBookmark []bookmark type ChromiumBookmark []bookmark
@ -24,10 +27,11 @@ type bookmark struct {
} }
func (c *ChromiumBookmark) Parse(masterKey []byte) error { func (c *ChromiumBookmark) Parse(masterKey []byte) error {
bookmarks, err := fileutil.ReadFile("bookmark") bookmarks, err := fileutil.ReadFile(item.TempChromiumBookmark)
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(item.TempChromiumBookmark)
r := gjson.Parse(bookmarks) r := gjson.Parse(bookmarks)
if r.Exists() { if r.Exists() {
roots := r.Get("roots") roots := r.Get("roots")
@ -84,12 +88,13 @@ func (f *FirefoxBookmark) Parse(masterKey []byte) error {
keyDB *sql.DB keyDB *sql.DB
bookmarkRows *sql.Rows bookmarkRows *sql.Rows
) )
keyDB, err = sql.Open("sqlite3", item.FirefoxBookmarkFilename) keyDB, err = sql.Open("sqlite3", item.TempFirefoxBookmark)
if err != nil { if err != nil {
return err return err
} }
_, err = keyDB.Exec(closeJournalMode) defer os.RemoveAll(item.TempFirefoxBookmark)
defer keyDB.Close() defer keyDB.Close()
_, err = keyDB.Exec(closeJournalMode)
bookmarkRows, err = keyDB.Query(queryFirefoxBookMark) bookmarkRows, err = keyDB.Query(queryFirefoxBookMark)
if err != nil { if err != nil {

@ -6,8 +6,8 @@ import (
"hack-browser-data/internal/item" "hack-browser-data/internal/item"
) )
type BrowsingData struct { type Data struct {
sources map[item.Item]Source Sources map[item.Item]Source
} }
type Source interface { type Source interface {
@ -16,39 +16,49 @@ type Source interface {
Name() string Name() string
} }
func New(sources []item.Item) *BrowsingData { func New(sources []item.Item) *Data {
bd := &BrowsingData{ bd := &Data{
sources: make(map[item.Item]Source), Sources: make(map[item.Item]Source),
} }
bd.addSource(sources) bd.addSource(sources)
return bd return bd
} }
func (b *BrowsingData) addSource(sources []item.Item) { func (d *Data) Recovery(masterKey []byte) error {
for _, source := range sources {
for _, source := range d.Sources {
if err := source.Parse(masterKey); err != nil {
panic(err)
}
}
return nil
}
func (d *Data) addSource(Sources []item.Item) {
for _, source := range Sources {
switch source { switch source {
case item.ChromiumPassword: case item.ChromiumPassword:
b.sources[source] = &ChromiumPassword{} d.Sources[source] = &ChromiumPassword{}
case item.ChromiumCookie: case item.ChromiumCookie:
b.sources[source] = &ChromiumCookie{} d.Sources[source] = &ChromiumCookie{}
case item.ChromiumBookmark: case item.ChromiumBookmark:
b.sources[source] = &ChromiumBookmark{} d.Sources[source] = &ChromiumBookmark{}
case item.ChromiumHistory: case item.ChromiumHistory:
b.sources[source] = &ChromiumHistory{} d.Sources[source] = &ChromiumHistory{}
case item.ChromiumDownload: case item.ChromiumDownload:
b.sources[source] = &ChromiumDownload{} d.Sources[source] = &ChromiumDownload{}
case item.ChromiumCreditCard: case item.ChromiumCreditCard:
b.sources[source] = &ChromiumCreditCard{} d.Sources[source] = &ChromiumCreditCard{}
case item.FirefoxPassword: case item.FirefoxPassword:
b.sources[source] = &FirefoxPassword{} d.Sources[source] = &FirefoxPassword{}
case item.FirefoxCookie: case item.FirefoxCookie:
b.sources[source] = &FirefoxCookie{} d.Sources[source] = &FirefoxCookie{}
case item.FirefoxBookmark: case item.FirefoxBookmark:
b.sources[source] = &FirefoxBookmark{} d.Sources[source] = &FirefoxBookmark{}
case item.FirefoxHistory: case item.FirefoxHistory:
b.sources[source] = &FirefoxHistory{} d.Sources[source] = &FirefoxHistory{}
case item.FirefoxDownload: case item.FirefoxDownload:
b.sources[source] = &FirefoxDownload{} d.Sources[source] = &FirefoxDownload{}
} }
} }
} }

@ -3,23 +3,24 @@ package browingdata
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"os"
"sort" "sort"
"hack-browser-data/internal/browser/item" _ "github.com/mattn/go-sqlite3"
"hack-browser-data/internal/decrypter" "hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3"
) )
type ChromiumCookie []cookie type ChromiumCookie []cookie
func (c *ChromiumCookie) Parse(masterKey []byte) error { func (c *ChromiumCookie) Parse(masterKey []byte) error {
cookieDB, err := sql.Open("sqlite3", item.ChromiumCookieFilename) cookieDB, err := sql.Open("sqlite3", item.TempChromiumCookie)
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(item.TempChromiumCookie)
defer cookieDB.Close() defer cookieDB.Close()
rows, err := cookieDB.Query(queryChromiumCookie) rows, err := cookieDB.Query(queryChromiumCookie)
if err != nil { if err != nil {
@ -79,7 +80,7 @@ func (c *ChromiumCookie) Name() string {
type FirefoxCookie []cookie type FirefoxCookie []cookie
func (f *FirefoxCookie) Parse(masterKey []byte) error { func (f *FirefoxCookie) Parse(masterKey []byte) error {
cookieDB, err := sql.Open("sqlite3", item.FirefoxCookieFilename) cookieDB, err := sql.Open("sqlite3", item.TempFirefoxCookie)
if err != nil { if err != nil {
return err return err
} }

@ -6,15 +6,14 @@ import (
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"hack-browser-data/internal/browser/item"
"hack-browser-data/internal/decrypter" "hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
) )
type ChromiumCreditCard []card type ChromiumCreditCard []card
func (c *ChromiumCreditCard) Parse(masterKey []byte) error { func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
creditDB, err := sql.Open("sqlite3", item.TempChromiumCredit) creditDB, err := sql.Open("sqlite3", item.TempChromiumCreditCard)
if err != nil { if err != nil {
return err return err
} }

@ -6,19 +6,17 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/tidwall/gjson" "hack-browser-data/internal/item"
"hack-browser-data/internal/browser/item"
"hack-browser-data/internal/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson"
) )
type ChromiumDownload []download type ChromiumDownload []download
func (c *ChromiumDownload) Parse(masterKey []byte) error { func (c *ChromiumDownload) Parse(masterKey []byte) error {
historyDB, err := sql.Open("sqlite3", item.ChromiumDownloadFilename) historyDB, err := sql.Open("sqlite3", item.TempChromiumDownload)
if err != nil { if err != nil {
return err return err
} }
@ -64,7 +62,7 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
keyDB *sql.DB keyDB *sql.DB
downloadRows *sql.Rows downloadRows *sql.Rows
) )
keyDB, err = sql.Open("sqlite3", item.FirefoxDownloadFilename) keyDB, err = sql.Open("sqlite3", item.TempFirefoxDownload)
if err != nil { if err != nil {
return err return err
} }

@ -5,17 +5,16 @@ import (
"fmt" "fmt"
"sort" "sort"
"hack-browser-data/internal/browser/item" _ "github.com/mattn/go-sqlite3"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils" "hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3"
) )
type ChromiumHistory []history type ChromiumHistory []history
func (c *ChromiumHistory) Parse(masterKey []byte) error { func (c *ChromiumHistory) Parse(masterKey []byte) error {
historyDB, err := sql.Open("sqlite3", item.ChromiumHistoryFilename) historyDB, err := sql.Open("sqlite3", item.TempChromiumHistory)
if err != nil { if err != nil {
return err return err
} }
@ -61,7 +60,7 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
keyDB *sql.DB keyDB *sql.DB
historyRows *sql.Rows historyRows *sql.Rows
) )
keyDB, err = sql.Open("sqlite3", item.FirefoxHistoryFilename) keyDB, err = sql.Open("sqlite3", item.TempFirefoxHistory)
if err != nil { if err != nil {
return err return err
} }

@ -9,13 +9,12 @@ import (
"sort" "sort"
"time" "time"
"hack-browser-data/internal/browser/item"
decrypter2 "hack-browser-data/internal/decrypter"
"hack-browser-data/internal/utils"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils"
) )
type ChromiumPassword []loginData type ChromiumPassword []loginData
@ -48,12 +47,12 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error {
} }
if len(pwd) > 0 { if len(pwd) > 0 {
if masterKey == nil { if masterKey == nil {
password, err = decrypter2.DPApi(pwd) password, err = decrypter.DPApi(pwd)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
} else { } else {
password, err = decrypter2.ChromePass(masterKey, pwd) password, err = decrypter.ChromePass(masterKey, pwd)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -81,11 +80,11 @@ func (c *ChromiumPassword) Name() string {
type FirefoxPassword []loginData type FirefoxPassword []loginData
func (f *FirefoxPassword) Parse(masterKey []byte) error { func (f *FirefoxPassword) Parse(masterKey []byte) error {
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.FirefoxKey4Filename) globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4)
if err != nil { if err != nil {
return err return err
} }
metaPBE, err := decrypter2.NewASN1PBE(metaBytes) metaPBE, err := decrypter.NewASN1PBE(metaBytes)
if err != nil { if err != nil {
return err return err
} }
@ -98,7 +97,7 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
if bytes.Contains(k, []byte("password-check")) { if bytes.Contains(k, []byte("password-check")) {
m := bytes.Compare(nssA102, keyLin) m := bytes.Compare(nssA102, keyLin)
if m == 0 { if m == 0 {
nssPBE, err := decrypter2.NewASN1PBE(nssA11) nssPBE, err := decrypter.NewASN1PBE(nssA11)
if err != nil { if err != nil {
return err return err
} }
@ -107,16 +106,16 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
if err != nil { if err != nil {
return err return err
} }
allLogin, err := getFirefoxLoginData(item.FirefoxPasswordFilename) allLogin, err := getFirefoxLoginData(item.TempFirefoxPassword)
if err != nil { if err != nil {
return err return err
} }
for _, v := range allLogin { for _, v := range allLogin {
userPBE, err := decrypter2.NewASN1PBE(v.encryptUser) userPBE, err := decrypter.NewASN1PBE(v.encryptUser)
if err != nil { if err != nil {
return err return err
} }
pwdPBE, err := decrypter2.NewASN1PBE(v.encryptPass) pwdPBE, err := decrypter.NewASN1PBE(v.encryptPass)
if err != nil { if err != nil {
return err return err
} }
@ -130,8 +129,8 @@ func (f *FirefoxPassword) Parse(masterKey []byte) error {
} }
*f = append(*f, loginData{ *f = append(*f, loginData{
LoginUrl: v.LoginUrl, LoginUrl: v.LoginUrl,
UserName: string(decrypter2.PKCS5UnPadding(user)), UserName: string(decrypter.PKCS5UnPadding(user)),
Password: string(decrypter2.PKCS5UnPadding(pwd)), Password: string(decrypter.PKCS5UnPadding(pwd)),
CreateDate: v.CreateDate, CreateDate: v.CreateDate,
}) })
} }

@ -13,16 +13,9 @@ type Browser interface {
GetMasterKey() ([]byte, error) GetMasterKey() ([]byte, error)
GetBrowsingData() []browingdata.Source GetBrowsingData() (*browingdata.Data, error)
CopyItemFileToLocal() error
} }
var (
// home dir path for all platforms
homeDir, _ = os.UserHomeDir()
)
func PickBrowser(name string) []Browser { func PickBrowser(name string) []Browser {
var browsers []Browser var browsers []Browser
clist := pickChromium(name) clist := pickChromium(name)
@ -45,7 +38,7 @@ func pickChromium(name string) []Browser {
name = strings.ToLower(name) name = strings.ToLower(name)
if name == "all" { if name == "all" {
for _, c := range chromiumList { for _, c := range chromiumList {
if b, err := chromium.New(c.name, c.profilePath, c.storage, c.items); err == nil { if b, err := chromium.New(c.name, c.storage, c.profilePath, c.items); err == nil {
browsers = append(browsers, b) browsers = append(browsers, b)
} else { } else {
if strings.Contains(err.Error(), "profile path is not exist") { if strings.Contains(err.Error(), "profile path is not exist") {
@ -56,8 +49,8 @@ func pickChromium(name string) []Browser {
} }
return browsers return browsers
} }
if choice, ok := chromiumList[name]; ok { if c, ok := chromiumList[name]; ok {
b, err := newChromium(choice.browserInfo, choice.items) b, err := chromium.New(c.name, c.storage, c.profilePath, c.items)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -71,15 +64,15 @@ func pickFirefox(name string) []Browser {
var browsers []Browser var browsers []Browser
name = strings.ToLower(name) name = strings.ToLower(name)
if name == "all" || name == "firefox" { if name == "all" || name == "firefox" {
for _, f := range firefoxList { // for _, f := range firefoxList {
multiFirefox, err := newMultiFirefox(f.browserInfo, f.items) // multiFirefox, err := firefox(f.browserInfo, f.items)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
for _, browser := range multiFirefox { // for _, browser := range multiFirefox {
browsers = append(browsers, browser) // browsers = append(browsers, browser)
} // }
} // }
return browsers return browsers
} }
return nil return nil
@ -96,9 +89,10 @@ func ListBrowser() []string {
return l return l
} }
type browserInfo struct { var (
masterKey []byte // home dir path for all platforms
} homeDir, _ = os.UserHomeDir()
)
const ( const (
chromeName = "Chrome" chromeName = "Chrome"

@ -4,53 +4,71 @@ import (
"fmt" "fmt"
"testing" "testing"
"hack-browser-data/internal/log" "hack-browser-data/internal/browser/chromium"
"hack-browser-data/internal/item"
"hack-browser-data/internal/outputter" "hack-browser-data/internal/outputter"
) )
func TestPickChromium(t *testing.T) { func TestPickChromium(t *testing.T) {
browsers := pickChromium("chrome") // browsers := pickChromium("chrome")
log.InitLog("debug") // log.InitLog("debug")
filetype := "json" // filetype := "json"
dir := "result" // // dir := "result"
output := outputter.NewOutPutter(filetype) // output := outputter.NewOutPutter(filetype)
if err := output.MakeDir("result"); err != nil { // _ = output
panic(err) // for _, b := range browsers {
} // fmt.Printf("%+v\n", b)
for _, b := range browsers { // if err := b.CopyItemFileToLocal(); err != nil {
fmt.Printf("%+v\n", b) // panic(err)
if err := b.CopyItemFileToLocal(); err != nil { // }
panic(err) // _, err := b.GetMasterKey()
} // if err != nil {
masterKey, err := b.GetMasterKey() // fmt.Println(err)
if err != nil { // }
fmt.Println(err) // // browserName := b.GetName()
} // data, err := b.GetBrowsingData()
browserName := b.GetName() // fmt.Println(data)
multiData := b.GetBrowsingData() // // for _, data := range multiData {
for _, data := range multiData { // // if err := data.Parse(masterKey); err != nil {
if err := data.Parse(masterKey); err != nil { // // fmt.Println(err)
fmt.Println(err) // // }
} // // filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype)
filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype) // // file, err := output.CreateFile(dir, filename)
file, err := output.CreateFile(dir, filename) // // if err != nil {
if err != nil { // // panic(err)
panic(err) // // }
} // // if err := output.Write(data, file); err != nil {
if err := output.Write(data, file); err != nil { // // panic(err)
panic(err) // // }
} // // }
} // }
}
} }
func TestGetChromiumItemAbsPath(t *testing.T) { func TestGetChromiumItemAbsPath(t *testing.T) {
p := `/Library/Application Support/Google/Chrome/` p := `/Library/Application Support/Google/Chrome/`
s, err := getChromiumItemPath(p, defaultChromiumItems) p = homeDir + p
c, err := chromium.New("chrome", "Chrome", p, item.DefaultChromium)
if err != nil {
t.Error(err)
}
data, err := c.GetBrowsingData()
if err != nil {
t.Error(err)
}
output := outputter.NewOutPutter("json")
if err != nil { if err != nil {
panic(err) t.Error(err)
}
for _, v := range data.Sources {
f, err := output.CreateFile("result", v.Name()+".json")
if err != nil {
panic(err)
}
if err := output.Write(v, f); err != nil {
panic(err)
}
} }
fmt.Println(s)
} }
func TestPickBrowsers(t *testing.T) { func TestPickBrowsers(t *testing.T) {
@ -63,37 +81,37 @@ func TestPickBrowsers(t *testing.T) {
// output := outputter.NewOutPutter(filetype) // output := outputter.NewOutPutter(filetype)
} }
func TestPickFirefox(t *testing.T) { // func TestPickFirefox(t *testing.T) {
browsers := pickFirefox("all") // browsers := pickFirefox("all")
filetype := "json" // filetype := "json"
dir := "result" // dir := "result"
output := outputter.NewOutPutter(filetype) // output := outputter.NewOutPutter(filetype)
if err := output.MakeDir("result"); err != nil { // if err := output.MakeDir("result"); err != nil {
panic(err) // panic(err)
} // }
for _, b := range browsers { // for _, b := range browsers {
fmt.Printf("%+v\n", b) // fmt.Printf("%+v\n", b)
if err := b.CopyItemFileToLocal(); err != nil { // if err := b.CopyItemFileToLocal(); err != nil {
panic(err) // panic(err)
} // }
masterKey, err := b.GetMasterKey() // masterKey, err := b.GetMasterKey()
if err != nil { // if err != nil {
fmt.Println(err) // fmt.Println(err)
} // }
browserName := b.GetName() // browserName := b.GetName()
multiData := b.GetBrowsingData() // multiData := b.GetBrowsingData()
for _, data := range multiData { // for _, data := range multiData {
if err := data.Parse(masterKey); err != nil { // if err := data.Parse(masterKey); err != nil {
fmt.Println(err) // fmt.Println(err)
} // }
filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype) // filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype)
file, err := output.CreateFile(dir, filename) // file, err := output.CreateFile(dir, filename)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
if err := output.Write(data, file); err != nil { // if err := output.Write(data, file); err != nil {
panic(err) // panic(err)
} // }
} // }
} // }
} // }

@ -22,65 +22,65 @@ type chromium struct {
itemPaths map[item.Item]string itemPaths map[item.Item]string
} }
// New creates a new instance of chromium browser, fill item's path if item is exist. // New create instance of chromium browser, fill item's path if item is existed.
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) { func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
c := &chromium{
name: name,
storage: storage,
}
// TODO: Handle file path is not exist // TODO: Handle file path is not exist
if !fileutil.FolderExists(profilePath) { if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath) return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
} }
itemsPaths, err := getChromiumItemPath(profilePath, items) masterKey, err := c.GetMasterKey()
if err != nil { if err != nil {
return nil, err return nil, err
} }
itemsPaths, err := c.getItemPath(profilePath, items)
c := &chromium{ if err != nil {
name: name, return nil, err
storage: storage,
profilePath: profilePath,
items: typeutil.Keys(itemsPaths),
itemPaths: itemsPaths,
} }
// new browsing data c.masterKey = masterKey
c.profilePath = profilePath
c.itemPaths = itemsPaths
c.items = typeutil.Keys(itemsPaths)
return c, err return c, err
} }
func (c *chromium) GetItems() []item.Item {
return c.items
}
func (c *chromium) GetItemPaths() map[item.Item]string {
return c.itemPaths
}
func (c *chromium) GetName() string { func (c *chromium) GetName() string {
return c.name return c.name
} }
func (c *chromium) GetBrowsingData() []browingdata.Source { func (c *chromium) GetBrowsingData() (*browingdata.Data, error) {
var browsingData []browingdata.Source b := browingdata.New(c.items)
data := browingdata.New(c.items)
for item := range c.itemPaths { if err := c.copyItemToLocal(); err != nil {
d := item.NewBrowsingData() return nil, err
if d != nil { }
browsingData = append(browsingData, d) if err := b.Recovery(c.masterKey); err != nil {
} return nil, err
} }
return browsingData return b, nil
} }
func (c *chromium) CopyItemFileToLocal() error { func (c *chromium) copyItemToLocal() error {
for item, sourcePath := range c.itemPaths { for i, path := range c.itemPaths {
var dstFilename = item.TempName() // var dstFilename = item.TempName()
locals, _ := filepath.Glob("*") var filename = i.String()
for _, v := range locals {
if v == dstFilename {
err := os.Remove(dstFilename)
// TODO: Should Continue all iteration error
if err != nil {
return err
}
}
}
// TODO: Handle read file error // TODO: Handle read file error
sourceFile, err := ioutil.ReadFile(sourcePath) d, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
err = ioutil.WriteFile(dstFilename, sourceFile, 0777) err = ioutil.WriteFile(filename, d, 0777)
if err != nil { if err != nil {
return err return err
} }
@ -88,7 +88,7 @@ func (c *chromium) CopyItemFileToLocal() error {
return nil return nil
} }
func getChromiumItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) { func (c *chromium) getItemPath(profilePath string, items []item.Item) (map[item.Item]string, error) {
var itemPaths = make(map[item.Item]string) var itemPaths = make(map[item.Item]string)
err := filepath.Walk(profilePath, chromiumWalkFunc(items, itemPaths)) err := filepath.Walk(profilePath, chromiumWalkFunc(items, itemPaths))
return itemPaths, err return itemPaths, err
@ -102,7 +102,7 @@ func chromiumWalkFunc(items []item.Item, itemPaths map[item.Item]string) filepat
if it == item.ChromiumKey { if it == item.ChromiumKey {
itemPaths[it] = path itemPaths[it] = path
} }
// TODO: Handle file path is not in Default folder // TODO: check file path is not in Default folder
if strings.Contains(path, "Default") { if strings.Contains(path, "Default") {
itemPaths[it] = path itemPaths[it] = path
} }

@ -29,17 +29,16 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
if stderr.Len() > 0 { if stderr.Len() > 0 {
return nil, errors.New(stderr.String()) return nil, errors.New(stderr.String())
} }
temp := stdout.Bytes() chromeSecret := bytes.TrimSpace(stdout.Bytes())
chromeSecret := temp[:len(temp)-1]
if chromeSecret == nil { if chromeSecret == nil {
return nil, ErrWrongSecurityCommand return nil, ErrWrongSecurityCommand
} }
var chromeSalt = []byte("saltysalt") var chromeSalt = []byte("saltysalt")
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157 // @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_mac.mm;l=157
key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New) key := pbkdf2.Key(chromeSecret, chromeSalt, 1003, 16, sha1.New)
if key != nil { if key == nil {
c.browserInfo.masterKey = key return nil, ErrWrongSecurityCommand
return key, nil
} }
return nil, errors.New("macOS wrong security command") c.masterKey = key
return key, nil
} }

@ -4,8 +4,11 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"github.com/smallstep/cli/utils"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"hack-browser-data/internal/decrypter"
"hack-browser-data/internal/item"
"hack-browser-data/internal/utils/fileutil"
) )
var ( var (
@ -13,7 +16,7 @@ var (
) )
func (c *chromium) GetMasterKey() ([]byte, error) { func (c *chromium) GetMasterKey() ([]byte, error) {
keyFile, err := utils.ReadFile(item.TempChromiumKey) keyFile, err := fileutil.ReadFile(item.TempChromiumKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -23,8 +26,8 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
if err != nil { if err != nil {
return nil, errDecodeMasterKeyFailed return nil, errDecodeMasterKeyFailed
} }
c.browserInfo.masterKey, err = decrypter.DPApi(pureKey[5:]) c.masterKey, err = decrypter.DPApi(pureKey[5:])
return c.browserInfo.masterKey, err return c.masterKey, err
} }
return nil, nil return nil, nil
} }

@ -1,129 +1,116 @@
package firefox package firefox
import ( // type firefox struct {
"fmt" // name string
"io/fs" // storage string
"io/ioutil" // profilePath string
"os" // masterKey []byte
"path" // items []item.Item
"path/filepath" // itemPaths map[item.Item]string
"strings" // multiItemPaths map[string]map[item.Item]string
// }
"hack-browser-data/internal/browingdata" //
"hack-browser-data/internal/item" // // New
) // func New(info *browserInfo, items []item.Item) ([]*firefox, error) {
// f := &firefox{
type firefox struct { // browserInfo: info,
name string // items: items,
storage string // }
profilePath string // multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items)
masterKey []byte // if err != nil {
items []item.Item // if strings.Contains(err.Error(), "profile path is not exist") {
itemPaths map[item.Item]string // fmt.Println(err)
multiItemPaths map[string]map[item.Item]string // return nil, nil
} // }
// panic(err)
// New // }
func New(info *browserInfo, items []item.Item) ([]*firefox, error) { // var firefoxList []*firefox
f := &firefox{ // for name, value := range multiItemPaths {
browserInfo: info, // firefoxList = append(firefoxList, &firefox{
items: items, // browserInfo: &browserInfo{
} // name: name,
multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items) // masterKey: nil,
if err != nil { // },
if strings.Contains(err.Error(), "profile path is not exist") { // items: items,
fmt.Println(err) // itemPaths: value,
return nil, nil // })
} // }
panic(err) // return firefoxList, nil
} // }
var firefoxList []*firefox //
for name, value := range multiItemPaths { // func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
firefoxList = append(firefoxList, &firefox{ // var multiItemPaths = make(map[string]map[item.Item]string)
browserInfo: &browserInfo{ // absProfilePath := path.Join(homeDir, filepath.Clean(profilePath))
name: name, // // TODO: Handle read file error
masterKey: nil, // if !isFileExist(absProfilePath) {
}, // return nil, fmt.Errorf("%s profile path is not exist", absProfilePath)
items: items, // }
itemPaths: value, // err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths))
}) // return multiItemPaths, err
} // }
return firefoxList, nil //
} // func (f *firefox) CopyItemFileToLocal() error {
// for item, sourcePath := range f.itemPaths {
func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { // var dstFilename = item.TempName()
var multiItemPaths = make(map[string]map[item.Item]string) // locals, _ := filepath.Glob("*")
absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) // for _, v := range locals {
// TODO: Handle read file error // if v == dstFilename {
if !isFileExist(absProfilePath) { // err := os.Remove(dstFilename)
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) // // TODO: Should Continue all iteration error
} // if err != nil {
err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths)) // return err
return multiItemPaths, err // }
} // }
// }
func (f *firefox) CopyItemFileToLocal() error { //
for item, sourcePath := range f.itemPaths { // // TODO: Handle read file name error
var dstFilename = item.TempName() // sourceFile, err := ioutil.ReadFile(sourcePath)
locals, _ := filepath.Glob("*") // if err != nil {
for _, v := range locals { // fmt.Println(err.Error())
if v == dstFilename { // }
err := os.Remove(dstFilename) // err = ioutil.WriteFile(dstFilename, sourceFile, 0777)
// TODO: Should Continue all iteration error // if err != nil {
if err != nil { // return err
return err // }
} // }
} // return nil
} // }
//
// TODO: Handle read file name error // func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc {
sourceFile, err := ioutil.ReadFile(sourcePath) // return func(path string, info fs.FileInfo, err error) error {
if err != nil { // for _, v := range items {
fmt.Println(err.Error()) // if info.Name() == v.FileName() {
} // parentDir := getParentDir(path)
err = ioutil.WriteFile(dstFilename, sourceFile, 0777) // if _, exist := multiItemPaths[parentDir]; exist {
if err != nil { // multiItemPaths[parentDir][v] = path
return err // } else {
} // multiItemPaths[parentDir] = map[item.Item]string{v: path}
} // }
return nil // }
} // }
// return err
func firefoxWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc { // }
return func(path string, info fs.FileInfo, err error) error { // }
for _, v := range items { //
if info.Name() == v.FileName() { // func getParentDir(absPath string) string {
parentDir := getParentDir(path) // return filepath.Base(filepath.Dir(absPath))
if _, exist := multiItemPaths[parentDir]; exist { // }
multiItemPaths[parentDir][v] = path //
} else { // func (f *firefox) GetMasterKey() ([]byte, error) {
multiItemPaths[parentDir] = map[item.Item]string{v: path} // return f.masterKey, nil
} // }
} //
} // func (f *firefox) GetName() string {
return err // return f.name
} // }
} //
// func (f *firefox) GetBrowsingData() []browingdata.Source {
func getParentDir(absPath string) string { // var browsingData []browingdata.Source
return filepath.Base(filepath.Dir(absPath)) // for item := range f.itemPaths {
} // d := item.NewBrowsingData()
// if d != nil {
func (f *firefox) GetMasterKey() ([]byte, error) { // browsingData = append(browsingData, d)
return f.masterKey, nil // }
} // }
// return browsingData
func (f *firefox) GetName() string { // }
return f.name
}
func (f *firefox) GetBrowsingData() []browingdata.Source {
var browsingData []browingdata.Source
for item := range f.itemPaths {
d := item.NewBrowsingData()
if d != nil {
browsingData = append(browsingData, d)
}
}
return browsingData
}

@ -24,3 +24,28 @@ const (
UnknownItem = "unknown item" UnknownItem = "unknown item"
UnsupportedItem = "unsupported item" UnsupportedItem = "unsupported item"
) )
const (
TempChromiumKey = "chromiumKey"
TempChromiumPassword = "password"
TempChromiumCookie = "cookie"
TempChromiumBookmark = "bookmark"
TempChromiumHistory = "history"
TempChromiumDownload = "download"
TempChromiumCreditCard = "creditCard"
TempChromiumLocalStorage = "localStorage"
TempChromiumExtension = "extension"
TempYandexPassword = "yandexPassword"
TempYandexCreditCard = "yandexCreditCard"
TempFirefoxKey4 = "firefoxKey4"
TempFirefoxPassword = "firefoxPassword"
TempFirefoxCookie = "firefoxCookie"
TempFirefoxBookmark = "firefoxBookmark"
TempFirefoxHistory = "firefoxHistory"
TempFirefoxDownload = "firefoxDownload"
TempFirefoxCreditCard = ""
TempFirefoxLocalStorage = ""
TempFirefoxExtension = ""
)

@ -1,45 +1,5 @@
package item package item
import (
data2 "hack-browser-data/internal/browingdata"
)
var DefaultFirefox = []Item{
FirefoxKey4,
FirefoxPassword,
FirefoxCookie,
FirefoxBookmark,
FirefoxHistory,
FirefoxDownload,
FirefoxCreditCard,
FirefoxLocalStorage,
FirefoxExtension,
}
var DefaultYandex = []Item{
ChromiumKey,
ChromiumCookie,
ChromiumBookmark,
ChromiumHistory,
ChromiumDownload,
ChromiumLocalStorage,
ChromiumExtension,
YandexPassword,
YandexCreditCard,
}
var DefaultChromium = []Item{
ChromiumKey,
ChromiumPassword,
ChromiumCookie,
ChromiumBookmark,
ChromiumHistory,
ChromiumDownload,
ChromiumCreditCard,
ChromiumLocalStorage,
ChromiumExtension,
}
type Item int type Item int
const ( const (
@ -117,39 +77,39 @@ func (i Item) FileName() string {
func (i Item) String() string { func (i Item) String() string {
switch i { switch i {
case ChromiumKey: case ChromiumKey:
return "chromiumKey" return TempChromiumKey
case ChromiumPassword: case ChromiumPassword:
return "password" return TempChromiumPassword
case ChromiumCookie: case ChromiumCookie:
return "cookie" return TempChromiumCookie
case ChromiumBookmark: case ChromiumBookmark:
return "bookmark" return TempChromiumBookmark
case ChromiumDownload: case ChromiumDownload:
return "download" return TempChromiumDownload
case ChromiumLocalStorage: case ChromiumLocalStorage:
return "localStorage" return TempChromiumLocalStorage
case ChromiumCreditCard: case ChromiumCreditCard:
return "creditCard" return TempChromiumCreditCard
case ChromiumExtension: case ChromiumExtension:
return UnsupportedItem return UnsupportedItem
case ChromiumHistory: case ChromiumHistory:
return "history" return TempChromiumExtension
case YandexPassword: case YandexPassword:
return "yandexPassword" return TempYandexPassword
case YandexCreditCard: case YandexCreditCard:
return "yandexCreditCard" return TempYandexCreditCard
case FirefoxKey4: case FirefoxKey4:
return "firefoxKey4" return TempFirefoxKey4
case FirefoxPassword: case FirefoxPassword:
return "firefoxPassword" return TempFirefoxPassword
case FirefoxCookie: case FirefoxCookie:
return "firefoxCookie" return TempFirefoxPassword
case FirefoxBookmark: case FirefoxBookmark:
return "firefoxBookmark" return TempFirefoxBookmark
case FirefoxDownload: case FirefoxDownload:
return "firefoxDownload" return TempFirefoxDownload
case FirefoxHistory: case FirefoxHistory:
return "firefoxHistory" return TempFirefoxHistory
case FirefoxLocalStorage: case FirefoxLocalStorage:
return UnsupportedItem return UnsupportedItem
case FirefoxCreditCard: case FirefoxCreditCard:
@ -161,43 +121,38 @@ func (i Item) String() string {
} }
} }
// NewBrowsingData returns a new Source instance. var DefaultFirefox = []Item{
// TODO: remove this function FirefoxKey4,
func (i Item) NewBrowsingData() data2.Source { FirefoxPassword,
switch i { FirefoxCookie,
case ChromiumKey: FirefoxBookmark,
return nil FirefoxHistory,
case ChromiumPassword: FirefoxDownload,
return &data2.ChromiumPassword{} FirefoxCreditCard,
case ChromiumCookie: FirefoxLocalStorage,
return &data2.ChromiumCookie{} FirefoxExtension,
case ChromiumBookmark: }
return &data2.ChromiumBookmark{}
case ChromiumDownload: var DefaultYandex = []Item{
return &data2.ChromiumDownload{} ChromiumKey,
case ChromiumLocalStorage: ChromiumCookie,
return nil ChromiumBookmark,
case ChromiumCreditCard: ChromiumHistory,
return &data2.ChromiumCreditCard{} ChromiumDownload,
case ChromiumExtension: ChromiumLocalStorage,
return nil ChromiumExtension,
case ChromiumHistory: YandexPassword,
return &data2.ChromiumHistory{} YandexCreditCard,
case YandexPassword: }
return &data2.ChromiumPassword{}
case YandexCreditCard: var DefaultChromium = []Item{
return &data2.ChromiumCreditCard{} ChromiumKey,
case FirefoxPassword: ChromiumPassword,
return &data2.FirefoxPassword{} ChromiumCookie,
case FirefoxCookie: ChromiumBookmark,
return &data2.FirefoxCookie{} ChromiumHistory,
case FirefoxBookmark: ChromiumDownload,
return &data2.FirefoxBookmark{} ChromiumCreditCard,
case FirefoxDownload: ChromiumLocalStorage,
return &data2.FirefoxDownload{} ChromiumExtension,
case FirefoxHistory:
return &data2.FirefoxHistory{}
default:
return nil
}
} }

Loading…
Cancel
Save