parent
5e02db0b66
commit
4f7adf3db7
@ -1 +1,129 @@ |
||||
package firefox |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io/fs" |
||||
"io/ioutil" |
||||
"os" |
||||
"path" |
||||
"path/filepath" |
||||
"strings" |
||||
|
||||
"hack-browser-data/internal/browser/data" |
||||
"hack-browser-data/internal/item" |
||||
) |
||||
|
||||
type firefox struct { |
||||
name string |
||||
storage string |
||||
profilePath string |
||||
masterKey []byte |
||||
items []item.Item |
||||
itemPaths map[item.Item]string |
||||
multiItemPaths map[string]map[item.Item]string |
||||
} |
||||
|
||||
// New
|
||||
func New(info *browserInfo, items []item.Item) ([]*firefox, error) { |
||||
f := &firefox{ |
||||
browserInfo: info, |
||||
items: items, |
||||
} |
||||
multiItemPaths, err := getFirefoxItemAbsPath(f.browserInfo.profilePath, f.items) |
||||
if err != nil { |
||||
if strings.Contains(err.Error(), "profile path is not exist") { |
||||
fmt.Println(err) |
||||
return nil, nil |
||||
} |
||||
panic(err) |
||||
} |
||||
var firefoxList []*firefox |
||||
for name, value := range multiItemPaths { |
||||
firefoxList = append(firefoxList, &firefox{ |
||||
browserInfo: &browserInfo{ |
||||
name: name, |
||||
masterKey: nil, |
||||
}, |
||||
items: items, |
||||
itemPaths: value, |
||||
}) |
||||
} |
||||
return firefoxList, nil |
||||
} |
||||
|
||||
func getFirefoxItemAbsPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) { |
||||
var multiItemPaths = make(map[string]map[item.Item]string) |
||||
absProfilePath := path.Join(homeDir, filepath.Clean(profilePath)) |
||||
// TODO: Handle read file error
|
||||
if !isFileExist(absProfilePath) { |
||||
return nil, fmt.Errorf("%s profile path is not exist", absProfilePath) |
||||
} |
||||
err := filepath.Walk(absProfilePath, firefoxWalkFunc(items, multiItemPaths)) |
||||
return multiItemPaths, err |
||||
} |
||||
|
||||
func (f *firefox) CopyItemFileToLocal() error { |
||||
for item, sourcePath := range f.itemPaths { |
||||
var dstFilename = item.TempName() |
||||
locals, _ := filepath.Glob("*") |
||||
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 name error
|
||||
sourceFile, err := ioutil.ReadFile(sourcePath) |
||||
if err != nil { |
||||
fmt.Println(err.Error()) |
||||
} |
||||
err = ioutil.WriteFile(dstFilename, sourceFile, 0777) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
} |
||||
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 { |
||||
for _, v := range items { |
||||
if info.Name() == v.FileName() { |
||||
parentDir := getParentDir(path) |
||||
if _, exist := multiItemPaths[parentDir]; exist { |
||||
multiItemPaths[parentDir][v] = path |
||||
} else { |
||||
multiItemPaths[parentDir] = map[item.Item]string{v: path} |
||||
} |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
} |
||||
|
||||
func getParentDir(absPath string) string { |
||||
return filepath.Base(filepath.Dir(absPath)) |
||||
} |
||||
|
||||
func (f *firefox) GetMasterKey() ([]byte, error) { |
||||
return f.masterKey, nil |
||||
} |
||||
|
||||
func (f *firefox) GetName() string { |
||||
return f.name |
||||
} |
||||
|
||||
func (f *firefox) GetBrowsingData() []data.BrowsingData { |
||||
var browsingData []data.BrowsingData |
||||
for item := range f.itemPaths { |
||||
d := item.NewBrowsingData() |
||||
if d != nil { |
||||
browsingData = append(browsingData, d) |
||||
} |
||||
} |
||||
return browsingData |
||||
} |
||||
|
@ -1,47 +0,0 @@ |
||||
package item |
||||
|
||||
// item's default filename
|
||||
const ( |
||||
FileChromiumKey = "Local State" |
||||
FileChromiumCredit = "Web Data" |
||||
FileChromiumPassword = "Login Data" |
||||
FileChromiumHistory = "History" |
||||
FileChromiumDownload = "History" |
||||
FileChromiumCookie = "Cookies" |
||||
FileChromiumBookmark = "Bookmarks" |
||||
FileChromiumLocalStorage = "chromiumLocalStorage" |
||||
|
||||
FileYandexPassword = "Ya PassMan Data" |
||||
FileYandexCredit = "Ya Credit Cards" |
||||
|
||||
FileFirefoxKey4 = "key4.db" |
||||
FileFirefoxCookie = "cookies.sqlite" |
||||
FileFirefoxPassword = "logins.json" |
||||
FileFirefoxData = "places.sqlite" |
||||
|
||||
FileUnknownItem = "unknown item" |
||||
FileUnsupportedItem = "unsupported item" |
||||
) |
||||
|
||||
// item's renamed filename
|
||||
const ( |
||||
TempChromiumKey = "TempChromiumKey" |
||||
TempChromiumCredit = "TempChromiumCredit" |
||||
TempChromiumPassword = "TempChromiumPassword" |
||||
TempChromiumHistory = "TempChromiumHistory" |
||||
TempChromiumDownload = "TempChromiumDownload" |
||||
TempChromiumCookie = "TempChromiumCookie" |
||||
TempChromiumBookmark = "TempChromiumBookmark" |
||||
TempChromiumLocalStorage = "TempChromiumLocalStorage" |
||||
|
||||
TempYandexPassword = "TempYandexPassword" |
||||
TempYandexCredit = "TempYandexCredit" |
||||
|
||||
TempFirefoxKey4 = "TempFirefoxKey4" |
||||
TempFirefoxCookie = "TempFirefoxCookie" |
||||
TempFirefoxPassword = "TempFirefoxPassword" |
||||
TempFirefoxDownload = "TempFirefoxDownload" |
||||
TempFirefoxHistory = "TempFirefoxHistory" |
||||
TempFirefoxBookmark = "TempFirefoxBookmark" |
||||
TempFirefoxData = "TempFirefoxData" |
||||
) |
@ -1,165 +0,0 @@ |
||||
package item |
||||
|
||||
import ( |
||||
data2 "hack-browser-data/internal/browser/data" |
||||
) |
||||
|
||||
type Item int |
||||
|
||||
const ( |
||||
ItemChromiumKey Item = iota |
||||
ItemChromiumPassword |
||||
ItemChromiumCookie |
||||
ItemChromiumBookmark |
||||
ItemChromiumHistory |
||||
ItemChromiumDownload |
||||
ItemChromiumCreditCard |
||||
ItemChromiumLocalStorage |
||||
ItemChromiumExtension |
||||
|
||||
ItemYandexPassword |
||||
ItemYandexCreditCard |
||||
|
||||
ItemFirefoxKey4 |
||||
ItemFirefoxPassword |
||||
ItemFirefoxCookie |
||||
ItemFirefoxBookmark |
||||
ItemFirefoxHistory |
||||
ItemFirefoxDownload |
||||
ItemFirefoxCreditCard |
||||
ItemFirefoxLocalStorage |
||||
ItemFirefoxExtension |
||||
) |
||||
|
||||
func (i Item) DefaultName() string { |
||||
switch i { |
||||
case ItemChromiumKey: |
||||
return ChromiumKey |
||||
case ItemChromiumPassword: |
||||
return ChromiumPassword |
||||
case ItemChromiumCookie: |
||||
return ChromiumCookie |
||||
case ItemChromiumBookmark: |
||||
return ChromiumBookmark |
||||
case ItemChromiumDownload: |
||||
return ChromiumDownload |
||||
case ItemChromiumLocalStorage: |
||||
return ChromiumLocalStorage |
||||
case ItemChromiumCreditCard: |
||||
return ChromiumCredit |
||||
case ItemChromiumExtension: |
||||
return UnknownItem |
||||
case ItemChromiumHistory: |
||||
return ChromiumHistory |
||||
case ItemYandexPassword: |
||||
return YandexPassword |
||||
case ItemYandexCreditCard: |
||||
return YandexCredit |
||||
case ItemFirefoxKey4: |
||||
return FirefoxKey4 |
||||
case ItemFirefoxPassword: |
||||
return FirefoxPassword |
||||
case ItemFirefoxCookie: |
||||
return FirefoxCookie |
||||
case ItemFirefoxBookmark: |
||||
return FirefoxData |
||||
case ItemFirefoxDownload: |
||||
return FirefoxData |
||||
case ItemFirefoxLocalStorage: |
||||
return UnsupportedItem |
||||
case ItemFirefoxCreditCard: |
||||
return UnsupportedItem |
||||
case ItemFirefoxHistory: |
||||
return FirefoxData |
||||
case ItemFirefoxExtension: |
||||
return UnsupportedItem |
||||
default: |
||||
return UnknownItem |
||||
} |
||||
} |
||||
|
||||
func (i Item) FileName() string { |
||||
switch i { |
||||
case chromiumKey: |
||||
return TempChromiumKey |
||||
case chromiumPassword: |
||||
return TempChromiumPassword |
||||
case chromiumCookie: |
||||
return ChromiumCookieFilename |
||||
case chromiumBookmark: |
||||
return ChromiumBookmarkFilename |
||||
case chromiumDownload: |
||||
return ChromiumDownloadFilename |
||||
case chromiumLocalStorage: |
||||
return ChromiumLocalStorageFilename |
||||
case chromiumCreditCard: |
||||
return TempChromiumCredit |
||||
case chromiumHistory: |
||||
return TempChromiumHistory |
||||
case chromiumExtension: |
||||
return UnsupportedItem |
||||
case yandexPassword: |
||||
return TempChromiumPassword |
||||
case yandexCreditCard: |
||||
return TempChromiumCredit |
||||
case firefoxKey4: |
||||
return FirefoxKey4Filename |
||||
case firefoxPassword: |
||||
return FirefoxPasswordFilename |
||||
case firefoxCookie: |
||||
return FirefoxCookieFilename |
||||
case firefoxBookmark: |
||||
return FirefoxBookmarkFilename |
||||
case firefoxDownload: |
||||
return FirefoxDownloadFilename |
||||
case firefoxLocalStorage: |
||||
return UnsupportedItem |
||||
case firefoxCreditCard: |
||||
return UnsupportedItem |
||||
case firefoxHistory: |
||||
return FirefoxHistoryFilename |
||||
case firefoxExtension: |
||||
return UnsupportedItem |
||||
default: |
||||
return UnknownItem |
||||
} |
||||
} |
||||
|
||||
func (i Item) NewBrowsingData() data2.BrowsingData { |
||||
switch i { |
||||
case chromiumKey: |
||||
return nil |
||||
case chromiumPassword: |
||||
return &data2.ChromiumPassword{} |
||||
case chromiumCookie: |
||||
return &data2.ChromiumCookie{} |
||||
case chromiumBookmark: |
||||
return &data2.ChromiumBookmark{} |
||||
case chromiumDownload: |
||||
return &data2.ChromiumDownload{} |
||||
case chromiumLocalStorage: |
||||
return nil |
||||
case chromiumCreditCard: |
||||
return &data2.ChromiumCreditCard{} |
||||
case chromiumExtension: |
||||
return nil |
||||
case chromiumHistory: |
||||
return &data2.ChromiumHistory{} |
||||
case yandexPassword: |
||||
return &data2.ChromiumPassword{} |
||||
case yandexCreditCard: |
||||
return &data2.ChromiumCreditCard{} |
||||
case firefoxPassword: |
||||
return &data2.FirefoxPassword{} |
||||
case firefoxCookie: |
||||
return &data2.FirefoxCookie{} |
||||
case firefoxBookmark: |
||||
return &data2.FirefoxBookmark{} |
||||
case firefoxDownload: |
||||
return &data2.FirefoxDownload{} |
||||
case firefoxHistory: |
||||
return &data2.FirefoxHistory{} |
||||
default: |
||||
return nil |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
package item |
||||
|
||||
// item's default filename
|
||||
const ( |
||||
fileChromiumKey = "Local State" |
||||
fileChromiumCredit = "Web Data" |
||||
fileChromiumPassword = "Login Data" |
||||
fileChromiumHistory = "History" |
||||
fileChromiumDownload = "History" |
||||
fileChromiumCookie = "Cookies" |
||||
fileChromiumBookmark = "Bookmarks" |
||||
fileChromiumLocalStorage = "chromiumLocalStorage" |
||||
|
||||
fileYandexPassword = "Ya PassMan Data" |
||||
fileYandexCredit = "Ya Credit Cards" |
||||
|
||||
fileFirefoxKey4 = "key4.db" |
||||
fileFirefoxCookie = "cookies.sqlite" |
||||
fileFirefoxPassword = "logins.json" |
||||
fileFirefoxData = "places.sqlite" |
||||
) |
||||
|
||||
const ( |
||||
UnknownItem = "unknown item" |
||||
UnsupportedItem = "unsupported item" |
||||
) |
@ -0,0 +1,201 @@ |
||||
package item |
||||
|
||||
import ( |
||||
"hack-browser-data/internal/browser/data" |
||||
) |
||||
|
||||
type Item int |
||||
|
||||
const ( |
||||
ChromiumKey Item = iota |
||||
ChromiumPassword |
||||
ChromiumCookie |
||||
ChromiumBookmark |
||||
ChromiumHistory |
||||
ChromiumDownload |
||||
ChromiumCreditCard |
||||
ChromiumLocalStorage |
||||
ChromiumExtension |
||||
|
||||
YandexPassword |
||||
YandexCreditCard |
||||
|
||||
FirefoxKey4 |
||||
FirefoxPassword |
||||
FirefoxCookie |
||||
FirefoxBookmark |
||||
FirefoxHistory |
||||
FirefoxDownload |
||||
FirefoxCreditCard |
||||
FirefoxLocalStorage |
||||
FirefoxExtension |
||||
) |
||||
|
||||
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, |
||||
} |
||||
|
||||
func (i Item) FileName() string { |
||||
switch i { |
||||
case ChromiumKey: |
||||
return fileChromiumKey |
||||
case ChromiumPassword: |
||||
return fileChromiumPassword |
||||
case ChromiumCookie: |
||||
return fileChromiumCookie |
||||
case ChromiumBookmark: |
||||
return fileChromiumBookmark |
||||
case ChromiumDownload: |
||||
return fileChromiumDownload |
||||
case ChromiumLocalStorage: |
||||
return fileChromiumLocalStorage |
||||
case ChromiumCreditCard: |
||||
return fileChromiumCredit |
||||
case ChromiumExtension: |
||||
return UnknownItem |
||||
case ChromiumHistory: |
||||
return fileChromiumHistory |
||||
case YandexPassword: |
||||
return fileYandexPassword |
||||
case YandexCreditCard: |
||||
return fileYandexCredit |
||||
case FirefoxKey4: |
||||
return fileFirefoxKey4 |
||||
case FirefoxPassword: |
||||
return fileFirefoxPassword |
||||
case FirefoxCookie: |
||||
return fileFirefoxCookie |
||||
case FirefoxBookmark: |
||||
return fileFirefoxData |
||||
case FirefoxDownload: |
||||
return fileFirefoxData |
||||
case FirefoxLocalStorage: |
||||
return UnsupportedItem |
||||
case FirefoxCreditCard: |
||||
return UnsupportedItem |
||||
case FirefoxHistory: |
||||
return fileFirefoxData |
||||
case FirefoxExtension: |
||||
return UnsupportedItem |
||||
default: |
||||
return UnknownItem |
||||
} |
||||
} |
||||
|
||||
func (i Item) String() string { |
||||
switch i { |
||||
case ChromiumKey: |
||||
return "chromiumKey" |
||||
case ChromiumPassword: |
||||
return "password" |
||||
case ChromiumCookie: |
||||
return "cookie" |
||||
case ChromiumBookmark: |
||||
return "bookmark" |
||||
case ChromiumDownload: |
||||
return "download" |
||||
case ChromiumLocalStorage: |
||||
return "localStorage" |
||||
case ChromiumCreditCard: |
||||
return "creditCard" |
||||
case ChromiumExtension: |
||||
return UnsupportedItem |
||||
case ChromiumHistory: |
||||
return "history" |
||||
case YandexPassword: |
||||
return "yandexPassword" |
||||
case YandexCreditCard: |
||||
return "yandexCreditCard" |
||||
case FirefoxKey4: |
||||
return "firefoxKey4" |
||||
case FirefoxPassword: |
||||
return "firefoxPassword" |
||||
case FirefoxCookie: |
||||
return "firefoxCookie" |
||||
case FirefoxBookmark: |
||||
return "firefoxBookmark" |
||||
case FirefoxDownload: |
||||
return "firefoxDownload" |
||||
case FirefoxHistory: |
||||
return "firefoxHistory" |
||||
case FirefoxLocalStorage: |
||||
return UnsupportedItem |
||||
case FirefoxCreditCard: |
||||
return UnsupportedItem |
||||
case FirefoxExtension: |
||||
return UnsupportedItem |
||||
default: |
||||
return UnknownItem |
||||
} |
||||
} |
||||
|
||||
func (i Item) NewBrowsingData() data.BrowsingData { |
||||
switch i { |
||||
case ChromiumKey: |
||||
return nil |
||||
case ChromiumPassword: |
||||
return &data.ChromiumPassword{} |
||||
case ChromiumCookie: |
||||
return &data.ChromiumCookie{} |
||||
case ChromiumBookmark: |
||||
return &data.ChromiumBookmark{} |
||||
case ChromiumDownload: |
||||
return &data.ChromiumDownload{} |
||||
case ChromiumLocalStorage: |
||||
return nil |
||||
case ChromiumCreditCard: |
||||
return &data.ChromiumCreditCard{} |
||||
case ChromiumExtension: |
||||
return nil |
||||
case ChromiumHistory: |
||||
return &data.ChromiumHistory{} |
||||
case YandexPassword: |
||||
return &data.ChromiumPassword{} |
||||
case YandexCreditCard: |
||||
return &data.ChromiumCreditCard{} |
||||
case FirefoxPassword: |
||||
return &data.FirefoxPassword{} |
||||
case FirefoxCookie: |
||||
return &data.FirefoxCookie{} |
||||
case FirefoxBookmark: |
||||
return &data.FirefoxBookmark{} |
||||
case FirefoxDownload: |
||||
return &data.FirefoxDownload{} |
||||
case FirefoxHistory: |
||||
return &data.FirefoxHistory{} |
||||
default: |
||||
return nil |
||||
} |
||||
} |
Loading…
Reference in new issue