You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
3.9 KiB
153 lines
3.9 KiB
3 years ago
|
package chromium
|
||
|
|
||
|
import (
|
||
3 years ago
|
"io/fs"
|
||
3 years ago
|
"path/filepath"
|
||
|
"strings"
|
||
|
|
||
2 years ago
|
"github.com/moond4rk/HackBrowserData/browingdata"
|
||
|
"github.com/moond4rk/HackBrowserData/item"
|
||
|
"github.com/moond4rk/HackBrowserData/utils/fileutil"
|
||
|
"github.com/moond4rk/HackBrowserData/utils/typeutil"
|
||
3 years ago
|
)
|
||
|
|
||
2 years ago
|
type Chromium struct {
|
||
3 years ago
|
name string
|
||
|
storage string
|
||
|
profilePath string
|
||
|
masterKey []byte
|
||
|
items []item.Item
|
||
|
itemPaths map[item.Item]string
|
||
|
}
|
||
|
|
||
2 years ago
|
// 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) {
|
||
|
c := &Chromium{
|
||
3 years ago
|
name: name,
|
||
|
storage: storage,
|
||
|
profilePath: profilePath,
|
||
|
items: items,
|
||
3 years ago
|
}
|
||
3 years ago
|
multiItemPaths, err := c.getMultiItemPath(c.profilePath, c.items)
|
||
3 years ago
|
if err != nil {
|
||
|
return nil, err
|
||
3 years ago
|
}
|
||
2 years ago
|
chromiumList := make([]*Chromium, 0, len(multiItemPaths))
|
||
3 years ago
|
for user, itemPaths := range multiItemPaths {
|
||
2 years ago
|
chromiumList = append(chromiumList, &Chromium{
|
||
3 years ago
|
name: fileutil.BrowserName(name, user),
|
||
|
items: typeutil.Keys(itemPaths),
|
||
|
itemPaths: itemPaths,
|
||
3 years ago
|
storage: storage,
|
||
3 years ago
|
})
|
||
|
}
|
||
|
return chromiumList, nil
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
func (c *Chromium) Name() string {
|
||
3 years ago
|
return c.name
|
||
|
}
|
||
|
|
||
2 years ago
|
func (c *Chromium) BrowsingData() (*browingdata.Data, error) {
|
||
3 years ago
|
b := browingdata.New(c.items)
|
||
|
|
||
|
if err := c.copyItemToLocal(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
3 years ago
|
|
||
|
masterKey, err := c.GetMasterKey()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
c.masterKey = masterKey
|
||
3 years ago
|
if err := b.Recovery(c.masterKey); err != nil {
|
||
|
return nil, err
|
||
3 years ago
|
}
|
||
3 years ago
|
return b, nil
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
func (c *Chromium) copyItemToLocal() error {
|
||
3 years ago
|
for i, path := range c.itemPaths {
|
||
3 years ago
|
filename := i.String()
|
||
|
var err error
|
||
|
switch {
|
||
|
case fileutil.FolderExists(path):
|
||
|
if i == item.ChromiumLocalStorage {
|
||
|
err = fileutil.CopyDir(path, filename, "lock")
|
||
3 years ago
|
}
|
||
3 years ago
|
if i == item.ChromiumExtension {
|
||
3 years ago
|
err = fileutil.CopyDirHasSuffix(path, filename, "manifest.json")
|
||
3 years ago
|
}
|
||
3 years ago
|
default:
|
||
|
err = fileutil.CopyFile(path, filename)
|
||
|
}
|
||
|
if err != nil {
|
||
|
return err
|
||
3 years ago
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
2 years ago
|
func (c *Chromium) getMultiItemPath(profilePath string, items []item.Item) (map[string]map[item.Item]string, error) {
|
||
3 years ago
|
// multiItemPaths is a map of user to item path, map[profile 1][item's name & path key pair]
|
||
|
multiItemPaths := make(map[string]map[item.Item]string)
|
||
3 years ago
|
parentDir := fileutil.ParentDir(profilePath)
|
||
3 years ago
|
err := filepath.Walk(parentDir, chromiumWalkFunc(items, multiItemPaths))
|
||
3 years ago
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var keyPath string
|
||
|
var dir string
|
||
|
for userDir, v := range multiItemPaths {
|
||
|
for _, p := range v {
|
||
|
if strings.HasSuffix(p, item.ChromiumKey.FileName()) {
|
||
|
keyPath = p
|
||
|
dir = userDir
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
t := make(map[string]map[item.Item]string)
|
||
|
for userDir, v := range multiItemPaths {
|
||
|
if userDir == dir {
|
||
|
continue
|
||
|
}
|
||
|
t[userDir] = v
|
||
|
t[userDir][item.ChromiumKey] = keyPath
|
||
3 years ago
|
fillLocalStoragePath(t[userDir], item.ChromiumLocalStorage)
|
||
3 years ago
|
}
|
||
|
return t, nil
|
||
|
}
|
||
|
|
||
3 years ago
|
func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc {
|
||
3 years ago
|
return func(path string, info fs.FileInfo, err error) error {
|
||
|
for _, v := range items {
|
||
|
if info.Name() == v.FileName() {
|
||
2 years ago
|
if strings.Contains(path, "System Profile") {
|
||
3 years ago
|
continue
|
||
|
}
|
||
2 years ago
|
profileFolder := fileutil.ParentBaseDir(path)
|
||
|
if strings.Contains(filepath.ToSlash(path), "/Network/Cookies") {
|
||
|
profileFolder = fileutil.BaseDir(strings.ReplaceAll(filepath.ToSlash(path), "/Network/Cookies", ""))
|
||
|
}
|
||
|
if _, exist := multiItemPaths[profileFolder]; exist {
|
||
|
multiItemPaths[profileFolder][v] = path
|
||
3 years ago
|
} else {
|
||
2 years ago
|
multiItemPaths[profileFolder] = map[item.Item]string{v: path}
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
func fillLocalStoragePath(itemPaths map[item.Item]string, storage item.Item) {
|
||
|
if p, ok := itemPaths[item.ChromiumHistory]; ok {
|
||
|
lsp := filepath.Join(filepath.Dir(p), storage.FileName())
|
||
|
if fileutil.FolderExists(lsp) {
|
||
|
itemPaths[item.ChromiumLocalStorage] = lsp
|
||
|
}
|
||
|
}
|
||
|
}
|