|
|
@ -2,11 +2,12 @@ package core |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"hack-browser-data/core/common" |
|
|
|
"hack-browser-data/core/data" |
|
|
|
"hack-browser-data/log" |
|
|
|
"hack-browser-data/log" |
|
|
|
"hack-browser-data/utils" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
@ -29,10 +30,10 @@ type Browser interface { |
|
|
|
GetSecretKey() []byte |
|
|
|
GetSecretKey() []byte |
|
|
|
|
|
|
|
|
|
|
|
// GetAllItems return all of items (password|bookmark|cookie|history)
|
|
|
|
// GetAllItems return all of items (password|bookmark|cookie|history)
|
|
|
|
GetAllItems() ([]common.Item, error) |
|
|
|
GetAllItems() ([]data.Item, error) |
|
|
|
|
|
|
|
|
|
|
|
// GetItem return single one from password|bookmark|cookie|history
|
|
|
|
// GetItem return single one from password|bookmark|cookie|history
|
|
|
|
GetItem(itemName string) (common.Item, error) |
|
|
|
GetItem(itemName string) (data.Item, error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
@ -52,46 +53,46 @@ var ( |
|
|
|
var ( |
|
|
|
var ( |
|
|
|
chromiumItems = map[string]struct { |
|
|
|
chromiumItems = map[string]struct { |
|
|
|
mainFile string |
|
|
|
mainFile string |
|
|
|
newItem func(mainFile, subFile string) common.Item |
|
|
|
newItem func(mainFile, subFile string) data.Item |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
bookmark: { |
|
|
|
bookmark: { |
|
|
|
mainFile: common.ChromeBookmarkFile, |
|
|
|
mainFile: data.ChromeBookmarkFile, |
|
|
|
newItem: common.NewBookmarks, |
|
|
|
newItem: data.NewBookmarks, |
|
|
|
}, |
|
|
|
}, |
|
|
|
cookie: { |
|
|
|
cookie: { |
|
|
|
mainFile: common.ChromeCookieFile, |
|
|
|
mainFile: data.ChromeCookieFile, |
|
|
|
newItem: common.NewCookies, |
|
|
|
newItem: data.NewCookies, |
|
|
|
}, |
|
|
|
}, |
|
|
|
history: { |
|
|
|
history: { |
|
|
|
mainFile: common.ChromeHistoryFile, |
|
|
|
mainFile: data.ChromeHistoryFile, |
|
|
|
newItem: common.NewHistoryData, |
|
|
|
newItem: data.NewHistoryData, |
|
|
|
}, |
|
|
|
}, |
|
|
|
password: { |
|
|
|
password: { |
|
|
|
mainFile: common.ChromePasswordFile, |
|
|
|
mainFile: data.ChromePasswordFile, |
|
|
|
newItem: common.NewCPasswords, |
|
|
|
newItem: data.NewCPasswords, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
firefoxItems = map[string]struct { |
|
|
|
firefoxItems = map[string]struct { |
|
|
|
mainFile string |
|
|
|
mainFile string |
|
|
|
subFile string |
|
|
|
subFile string |
|
|
|
newItem func(mainFile, subFile string) common.Item |
|
|
|
newItem func(mainFile, subFile string) data.Item |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
bookmark: { |
|
|
|
bookmark: { |
|
|
|
mainFile: common.FirefoxDataFile, |
|
|
|
mainFile: data.FirefoxDataFile, |
|
|
|
newItem: common.NewBookmarks, |
|
|
|
newItem: data.NewBookmarks, |
|
|
|
}, |
|
|
|
}, |
|
|
|
cookie: { |
|
|
|
cookie: { |
|
|
|
mainFile: common.FirefoxCookieFile, |
|
|
|
mainFile: data.FirefoxCookieFile, |
|
|
|
newItem: common.NewCookies, |
|
|
|
newItem: data.NewCookies, |
|
|
|
}, |
|
|
|
}, |
|
|
|
history: { |
|
|
|
history: { |
|
|
|
mainFile: common.FirefoxDataFile, |
|
|
|
mainFile: data.FirefoxDataFile, |
|
|
|
newItem: common.NewHistoryData, |
|
|
|
newItem: data.NewHistoryData, |
|
|
|
}, |
|
|
|
}, |
|
|
|
password: { |
|
|
|
password: { |
|
|
|
mainFile: common.FirefoxKey4File, |
|
|
|
mainFile: data.FirefoxKey4File, |
|
|
|
subFile: common.FirefoxLoginFile, |
|
|
|
subFile: data.FirefoxLoginFile, |
|
|
|
newItem: common.NewFPasswords, |
|
|
|
newItem: data.NewFPasswords, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
@ -104,6 +105,7 @@ type Chromium struct { |
|
|
|
secretKey []byte |
|
|
|
secretKey []byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewChromium return chromium browser interface
|
|
|
|
func NewChromium(profile, key, name, storage string) (Browser, error) { |
|
|
|
func NewChromium(profile, key, name, storage string) (Browser, error) { |
|
|
|
return &Chromium{profilePath: profile, keyPath: key, name: name, storage: storage}, nil |
|
|
|
return &Chromium{profilePath: profile, keyPath: key, name: name, storage: storage}, nil |
|
|
|
} |
|
|
|
} |
|
|
@ -116,10 +118,12 @@ func (c *Chromium) GetSecretKey() []byte { |
|
|
|
return c.secretKey |
|
|
|
return c.secretKey |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Chromium) GetAllItems() (Items []common.Item, err error) { |
|
|
|
// GetAllItems return all chromium items from browser
|
|
|
|
var items []common.Item |
|
|
|
// if can't find item path, log error then continue
|
|
|
|
|
|
|
|
func (c *Chromium) GetAllItems() ([]data.Item, error) { |
|
|
|
|
|
|
|
var items []data.Item |
|
|
|
for item, choice := range chromiumItems { |
|
|
|
for item, choice := range chromiumItems { |
|
|
|
m, err := utils.GetItemPath(c.profilePath, choice.mainFile) |
|
|
|
m, err := getItemPath(c.profilePath, choice.mainFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", c.name, item, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", c.name, item, err) |
|
|
|
continue |
|
|
|
continue |
|
|
@ -131,10 +135,11 @@ func (c *Chromium) GetAllItems() (Items []common.Item, err error) { |
|
|
|
return items, nil |
|
|
|
return items, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Chromium) GetItem(itemName string) (common.Item, error) { |
|
|
|
// GetItem return single item
|
|
|
|
|
|
|
|
func (c *Chromium) GetItem(itemName string) (data.Item, error) { |
|
|
|
itemName = strings.ToLower(itemName) |
|
|
|
itemName = strings.ToLower(itemName) |
|
|
|
if item, ok := chromiumItems[itemName]; ok { |
|
|
|
if item, ok := chromiumItems[itemName]; ok { |
|
|
|
m, err := utils.GetItemPath(c.profilePath, item.mainFile) |
|
|
|
m, err := getItemPath(c.profilePath, item.mainFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", c.name, item.mainFile, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", c.name, item.mainFile, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -151,25 +156,27 @@ type Firefox struct { |
|
|
|
keyPath string |
|
|
|
keyPath string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewFirefox return firefox browser interface
|
|
|
|
func NewFirefox(profile, key, name, storage string) (Browser, error) { |
|
|
|
func NewFirefox(profile, key, name, storage string) (Browser, error) { |
|
|
|
return &Firefox{profilePath: profile, keyPath: key, name: name}, nil |
|
|
|
return &Firefox{profilePath: profile, keyPath: key, name: name}, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (f *Firefox) GetAllItems() ([]common.Item, error) { |
|
|
|
//
|
|
|
|
var items []common.Item |
|
|
|
func (f *Firefox) GetAllItems() ([]data.Item, error) { |
|
|
|
|
|
|
|
var items []data.Item |
|
|
|
for item, choice := range firefoxItems { |
|
|
|
for item, choice := range firefoxItems { |
|
|
|
var ( |
|
|
|
var ( |
|
|
|
sub, main string |
|
|
|
sub, main string |
|
|
|
err error |
|
|
|
err error |
|
|
|
) |
|
|
|
) |
|
|
|
if choice.subFile != "" { |
|
|
|
if choice.subFile != "" { |
|
|
|
sub, err = utils.GetItemPath(f.profilePath, choice.subFile) |
|
|
|
sub, err = getItemPath(f.profilePath, choice.subFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
main, err = utils.GetItemPath(f.profilePath, choice.mainFile) |
|
|
|
main, err = getItemPath(f.profilePath, choice.mainFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item, err) |
|
|
|
continue |
|
|
|
continue |
|
|
@ -181,7 +188,7 @@ func (f *Firefox) GetAllItems() ([]common.Item, error) { |
|
|
|
return items, nil |
|
|
|
return items, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (f *Firefox) GetItem(itemName string) (common.Item, error) { |
|
|
|
func (f *Firefox) GetItem(itemName string) (data.Item, error) { |
|
|
|
itemName = strings.ToLower(itemName) |
|
|
|
itemName = strings.ToLower(itemName) |
|
|
|
if item, ok := firefoxItems[itemName]; ok { |
|
|
|
if item, ok := firefoxItems[itemName]; ok { |
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -189,12 +196,12 @@ func (f *Firefox) GetItem(itemName string) (common.Item, error) { |
|
|
|
err error |
|
|
|
err error |
|
|
|
) |
|
|
|
) |
|
|
|
if item.subFile != "" { |
|
|
|
if item.subFile != "" { |
|
|
|
sub, err = utils.GetItemPath(f.profilePath, item.subFile) |
|
|
|
sub, err = getItemPath(f.profilePath, item.subFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.subFile, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.subFile, err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
main, err = utils.GetItemPath(f.profilePath, item.mainFile) |
|
|
|
main, err = getItemPath(f.profilePath, item.mainFile) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.mainFile, err) |
|
|
|
log.Errorf("%s find %s file failed, ERR:%s", f.name, item.mainFile, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -210,14 +217,19 @@ func (f *Firefox) GetName() string { |
|
|
|
return f.name |
|
|
|
return f.name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetSecretKey for firefox is always nil
|
|
|
|
|
|
|
|
// this method use to implement Browser interface
|
|
|
|
func (f *Firefox) GetSecretKey() []byte { |
|
|
|
func (f *Firefox) GetSecretKey() []byte { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// InitSecretKey for firefox is always nil
|
|
|
|
|
|
|
|
// this method use to implement Browser interface
|
|
|
|
func (f *Firefox) InitSecretKey() error { |
|
|
|
func (f *Firefox) InitSecretKey() error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PickBrowser return a list of browser interface
|
|
|
|
func PickBrowser(name string) ([]Browser, error) { |
|
|
|
func PickBrowser(name string) ([]Browser, error) { |
|
|
|
var browsers []Browser |
|
|
|
var browsers []Browser |
|
|
|
name = strings.ToLower(name) |
|
|
|
name = strings.ToLower(name) |
|
|
@ -238,6 +250,17 @@ func PickBrowser(name string) ([]Browser, error) { |
|
|
|
return nil, errBrowserNotSupported |
|
|
|
return nil, errBrowserNotSupported |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getItemPath(profilePath, file string) (string, error) { |
|
|
|
|
|
|
|
p, err := filepath.Glob(profilePath + file) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(p) > 0 { |
|
|
|
|
|
|
|
return p[0], nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "", fmt.Errorf("find %s failed", file) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ListBrowser() []string { |
|
|
|
func ListBrowser() []string { |
|
|
|
var l []string |
|
|
|
var l []string |
|
|
|
for k := range browserList { |
|
|
|
for k := range browserList { |
|
|
|