feat: add firefox decrypt

pull/125/head
ᴍᴏᴏɴD4ʀᴋ 3 years ago
parent dc06b1d69b
commit e0a3fd3ca2
  1. 2
      internal/browingdata/bookmark.go
  2. 1
      internal/browingdata/cookie.go
  3. 2
      internal/browingdata/history.go
  4. 2
      internal/browingdata/password.go
  5. 19
      internal/browser/browser.go
  6. 237
      internal/browser/firefox/firefox.go
  7. 2
      internal/item/item.go

@ -92,7 +92,7 @@ func (f *FirefoxBookmark) Parse(masterKey []byte) error {
if err != nil { if err != nil {
return err return err
} }
defer os.RemoveAll(item.TempFirefoxBookmark) defer os.Remove(item.TempFirefoxBookmark)
defer keyDB.Close() defer keyDB.Close()
_, err = keyDB.Exec(closeJournalMode) _, err = keyDB.Exec(closeJournalMode)

@ -84,6 +84,7 @@ func (f *FirefoxCookie) Parse(masterKey []byte) error {
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(item.TempFirefoxCookie)
defer cookieDB.Close() defer cookieDB.Close()
rows, err := cookieDB.Query(queryFirefoxCookie) rows, err := cookieDB.Query(queryFirefoxCookie)
if err != nil { if err != nil {

@ -66,6 +66,8 @@ func (f *FirefoxHistory) Parse(masterKey []byte) error {
if err != nil { if err != nil {
return err return err
} }
defer os.Remove(item.TempFirefoxHistory)
defer keyDB.Close()
_, err = keyDB.Exec(closeJournalMode) _, err = keyDB.Exec(closeJournalMode)
if err != nil { if err != nil {
return err return err

@ -156,6 +156,7 @@ func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err
if err != nil { if err != nil {
return nil, nil, nil, nil, err return nil, nil, nil, nil, err
} }
defer os.Remove(key4file)
defer keyDB.Close() defer keyDB.Close()
if err = keyDB.QueryRow(queryMetaData).Scan(&item1, &item2); err != nil { if err = keyDB.QueryRow(queryMetaData).Scan(&item1, &item2); err != nil {
@ -173,6 +174,7 @@ func getFirefoxLoginData(loginJson string) (l []loginData, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer os.Remove(loginJson)
h := gjson.GetBytes(s, "logins") h := gjson.GetBytes(s, "logins")
if h.Exists() { if h.Exists() {
for _, v := range h.Array() { for _, v := range h.Array() {

@ -7,6 +7,7 @@ import (
"hack-browser-data/internal/browingdata" "hack-browser-data/internal/browingdata"
"hack-browser-data/internal/browser/chromium" "hack-browser-data/internal/browser/chromium"
"hack-browser-data/internal/browser/firefox"
) )
type Browser interface { type Browser interface {
@ -69,15 +70,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 _, v := range firefoxList {
// multiFirefox, err := firefox(f.browserInfo, f.items) multiFirefox, err := firefox.New(v.name, v.storage, v.profilePath, v.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

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

@ -103,7 +103,7 @@ func (i Item) String() string {
case FirefoxPassword: case FirefoxPassword:
return TempFirefoxPassword return TempFirefoxPassword
case FirefoxCookie: case FirefoxCookie:
return TempFirefoxPassword return TempFirefoxCookie
case FirefoxBookmark: case FirefoxBookmark:
return TempFirefoxBookmark return TempFirefoxBookmark
case FirefoxDownload: case FirefoxDownload:

Loading…
Cancel
Save