feat: add copy file to local

This commit is contained in:
ᴍᴏᴏɴD4ʀᴋ
2022-04-11 19:57:40 +08:00
parent 46f2610a0a
commit dc06b1d69b
18 changed files with 83 additions and 258 deletions
+2
View File
@@ -3,6 +3,7 @@ package browingdata
import (
"database/sql"
"fmt"
"os"
_ "github.com/mattn/go-sqlite3"
@@ -17,6 +18,7 @@ func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempChromiumCreditCard)
defer creditDB.Close()
rows, err := creditDB.Query(queryChromiumCredit)
if err != nil {
+4
View File
@@ -3,6 +3,7 @@ package browingdata
import (
"database/sql"
"fmt"
"os"
"sort"
"strings"
@@ -20,6 +21,7 @@ func (c *ChromiumDownload) Parse(masterKey []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempChromiumDownload)
defer historyDB.Close()
rows, err := historyDB.Query(queryChromiumDownload)
if err != nil {
@@ -66,6 +68,8 @@ func (f *FirefoxDownload) Parse(masterKey []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxDownload)
defer keyDB.Close()
_, err = keyDB.Exec(closeJournalMode)
if err != nil {
return err
+2
View File
@@ -3,6 +3,7 @@ package browingdata
import (
"database/sql"
"fmt"
"os"
"sort"
_ "github.com/mattn/go-sqlite3"
@@ -18,6 +19,7 @@ func (c *ChromiumHistory) Parse(masterKey []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempChromiumHistory)
defer historyDB.Close()
rows, err := historyDB.Query(queryChromiumHistory)
if err != nil {
+2
View File
@@ -6,6 +6,7 @@ import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"sort"
"time"
@@ -24,6 +25,7 @@ func (c *ChromiumPassword) Parse(masterKey []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempChromiumPassword)
defer loginDB.Close()
rows, err := loginDB.Query(queryChromiumLogin)
if err != nil {
+14 -9
View File
@@ -1,6 +1,7 @@
package browser
import (
"fmt"
"os"
"strings"
@@ -9,10 +10,10 @@ import (
)
type Browser interface {
GetName() string
Name() string
GetMasterKey() ([]byte, error)
// GetBrowsingData returns the browsing data for the browser.
GetBrowsingData() (*browingdata.Data, error)
}
@@ -52,7 +53,11 @@ func pickChromium(name string) []Browser {
if c, ok := chromiumList[name]; ok {
b, err := chromium.New(c.name, c.storage, c.profilePath, c.items)
if err != nil {
panic(err)
if strings.Contains(err.Error(), "profile path is not exist") {
fmt.Println(err.Error())
} else {
panic(err)
}
}
browsers = append(browsers, b)
return browsers
@@ -97,13 +102,13 @@ var (
const (
chromeName = "Chrome"
chromeBetaName = "Chrome Beta"
chromiumName = "ChromiumBookmark"
chromiumName = "Chromium"
edgeName = "Microsoft Edge"
firefoxName = "FirefoxBookmark"
firefoxBetaName = "FirefoxBookmark Beta"
firefoxDevName = "FirefoxBookmark Dev"
firefoxNightlyName = "FirefoxBookmark Nightly"
firefoxESRName = "FirefoxBookmark ESR"
firefoxName = "Firefox"
firefoxBetaName = "Firefox Beta"
firefoxDevName = "Firefox Dev"
firefoxNightlyName = "Firefox Nightly"
firefoxESRName = "Firefox ESR"
speed360Name = "360speed"
qqBrowserName = "QQ"
braveName = "Brave"
+2
View File
@@ -1,3 +1,5 @@
//go:build darwin
package browser
import (
+2
View File
@@ -1 +1,3 @@
//go:build linux
package browser
+6 -37
View File
@@ -10,38 +10,7 @@ import (
)
func TestPickChromium(t *testing.T) {
// browsers := pickChromium("chrome")
// log.InitLog("debug")
// filetype := "json"
// // dir := "result"
// output := outputter.NewOutPutter(filetype)
// _ = output
// for _, b := range browsers {
// fmt.Printf("%+v\n", b)
// if err := b.CopyItemFileToLocal(); err != nil {
// panic(err)
// }
// _, err := b.GetMasterKey()
// if err != nil {
// fmt.Println(err)
// }
// // browserName := b.GetName()
// data, err := b.GetBrowsingData()
// fmt.Println(data)
// // for _, data := range multiData {
// // if err := data.Parse(masterKey); err != nil {
// // fmt.Println(err)
// // }
// // filename := fmt.Sprintf("%s_%s.%s", browserName, data.Name(), filetype)
// // file, err := output.CreateFile(dir, filename)
// // if err != nil {
// // panic(err)
// // }
// // if err := output.Write(data, file); err != nil {
// // panic(err)
// // }
// // }
// }
}
func TestGetChromiumItemAbsPath(t *testing.T) {
@@ -55,7 +24,7 @@ func TestGetChromiumItemAbsPath(t *testing.T) {
if err != nil {
t.Error(err)
}
output := outputter.NewOutPutter("json")
output := outputter.New("json")
if err != nil {
t.Error(err)
@@ -74,18 +43,18 @@ func TestGetChromiumItemAbsPath(t *testing.T) {
func TestPickBrowsers(t *testing.T) {
browsers := PickBrowser("all")
for _, v := range browsers {
fmt.Println(v.GetName())
fmt.Println(v.Name())
}
// filetype := "json"
// dir := "result"
// output := outputter.NewOutPutter(filetype)
// output := outputter.New(filetype)
}
// func TestPickFirefox(t *testing.T) {
// browsers := pickFirefox("all")
// filetype := "json"
// dir := "result"
// output := outputter.NewOutPutter(filetype)
// output := outputter.New(filetype)
// if err := output.MakeDir("result"); err != nil {
// panic(err)
// }
@@ -98,7 +67,7 @@ func TestPickBrowsers(t *testing.T) {
// if err != nil {
// fmt.Println(err)
// }
// browserName := b.GetName()
// browserName := b.Name()
// multiData := b.GetBrowsingData()
// for _, data := range multiData {
// if err := data.Parse(masterKey); err != nil {
+2
View File
@@ -1,3 +1,5 @@
//go:build windows
package browser
import (
+8 -14
View File
@@ -32,30 +32,17 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
if !fileutil.FolderExists(profilePath) {
return nil, fmt.Errorf("%s profile path is not exist: %s", name, profilePath)
}
masterKey, err := c.GetMasterKey()
if err != nil {
return nil, err
}
itemsPaths, err := c.getItemPath(profilePath, items)
if err != nil {
return nil, err
}
c.masterKey = masterKey
c.profilePath = profilePath
c.itemPaths = itemsPaths
c.items = typeutil.Keys(itemsPaths)
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) Name() string {
return c.name
}
@@ -65,6 +52,13 @@ func (c *chromium) GetBrowsingData() (*browingdata.Data, error) {
if err := c.copyItemToLocal(); err != nil {
return nil, err
}
masterKey, err := c.GetMasterKey()
if err != nil {
return nil, err
}
c.masterKey = masterKey
if err := b.Recovery(c.masterKey); err != nil {
return nil, err
}
+13 -1
View File
@@ -4,13 +4,18 @@ import (
"bytes"
"crypto/sha1"
"errors"
"os"
"os/exec"
"strings"
"golang.org/x/crypto/pbkdf2"
"hack-browser-data/internal/item"
)
var (
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
ErrWrongSecurityCommand = errors.New("macOS wrong security command")
ErrCouldNotFindInKeychain = errors.New("macOS could not find in keychain")
)
func (c *chromium) GetMasterKey() ([]byte, error) {
@@ -18,6 +23,10 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
cmd *exec.Cmd
stdout, stderr bytes.Buffer
)
// don't need chromium key file for macOS
defer os.Remove(item.TempChromiumKey)
// defer os.Remove(item.TempChromiumKey)
// Get the master key from the keychain
// $ security find-generic-password -wa 'Chrome'
cmd = exec.Command("security", "find-generic-password", "-wa", c.storage)
cmd.Stdout = &stdout
@@ -27,6 +36,9 @@ func (c *chromium) GetMasterKey() ([]byte, error) {
return nil, err
}
if stderr.Len() > 0 {
if strings.Contains(stderr.String(), "could not be found") {
return nil, ErrCouldNotFindInKeychain
}
return nil, errors.New(stderr.String())
}
chromeSecret := bytes.TrimSpace(stdout.Bytes())
+1 -1
View File
@@ -100,7 +100,7 @@ package firefox
// return f.masterKey, nil
// }
//
// func (f *firefox) GetName() string {
// func (f *firefox) Name() string {
// return f.name
// }
//
+1 -1
View File
@@ -93,7 +93,7 @@ func (i Item) String() string {
case ChromiumExtension:
return UnsupportedItem
case ChromiumHistory:
return TempChromiumExtension
return TempChromiumHistory
case YandexPassword:
return TempYandexPassword
case YandexCreditCard:
+1 -1
View File
@@ -18,7 +18,7 @@ type outPutter struct {
csv bool
}
func NewOutPutter(flag string) *outPutter {
func New(flag string) *outPutter {
o := &outPutter{}
if flag == "json" {
o.json = true
+2 -2
View File
@@ -6,9 +6,9 @@ import (
)
func TestNewOutPutter(t *testing.T) {
out := NewOutPutter("json")
out := New("json")
if out == nil {
t.Error("NewOutPutter() returned nil")
t.Error("New() returned nil")
}
f, err := out.CreateFile("results", "test.json")
if err != nil {
+21
View File
@@ -1,8 +1,11 @@
package fileutil
import (
"fmt"
"io/ioutil"
"os"
"hack-browser-data/internal/item"
)
// FileExists checks if the file exists in the provided path
@@ -34,3 +37,21 @@ func ReadFile(filename string) (string, error) {
s, err := ioutil.ReadFile(filename)
return string(s), err
}
// CopyItemToLocal copies the file from the provided path to the local path
func CopyItemToLocal(itemPaths map[item.Item]string) error {
for i, path := range itemPaths {
// var dstFilename = item.TempName()
var filename = i.String()
// TODO: Handle read file error
d, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err.Error())
}
err = ioutil.WriteFile(filename, d, 0777)
if err != nil {
return err
}
}
return nil
}