mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
feat: update to v0.4.0, based by generics
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package browingdata
|
||||
package bookmark
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
@@ -82,6 +82,11 @@ func (c *ChromiumBookmark) Name() string {
|
||||
|
||||
type FirefoxBookmark []bookmark
|
||||
|
||||
const (
|
||||
queryFirefoxBookMark = `SELECT id, url, type, dateAdded, title FROM (SELECT * FROM moz_bookmarks INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id)`
|
||||
closeJournalMode = `PRAGMA journal_mode=off`
|
||||
)
|
||||
|
||||
func (f *FirefoxBookmark) Parse(masterKey []byte) error {
|
||||
var (
|
||||
err error
|
||||
|
||||
@@ -2,11 +2,15 @@ package browingdata
|
||||
|
||||
import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"hack-browser-data/internal/browingdata/bookmark"
|
||||
"hack-browser-data/internal/browingdata/cookie"
|
||||
"hack-browser-data/internal/browingdata/creditcard"
|
||||
"hack-browser-data/internal/browingdata/download"
|
||||
"hack-browser-data/internal/browingdata/history"
|
||||
"hack-browser-data/internal/browingdata/password"
|
||||
"hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/log"
|
||||
"hack-browser-data/internal/outputter"
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
)
|
||||
|
||||
@@ -38,18 +42,18 @@ func (d *Data) Recovery(masterKey []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Data) Output(dir, browserName, output string) {
|
||||
outputter := outputter.New(output)
|
||||
func (d *Data) Output(dir, browserName, flag string) {
|
||||
output := NewOutPutter(flag)
|
||||
|
||||
for _, source := range d.Sources {
|
||||
|
||||
filename := fileutil.Filename(browserName, source.Name(), outputter.Ext())
|
||||
filename := fileutil.Filename(browserName, source.Name(), output.Ext())
|
||||
|
||||
f, err := outputter.CreateFile(dir, filename)
|
||||
f, err := output.CreateFile(dir, filename)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
if err := outputter.Write(source, f); err != nil {
|
||||
if err := output.Write(source, f); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
log.Noticef("output to file %s success", path.Join(dir, filename))
|
||||
@@ -60,94 +64,31 @@ func (d *Data) addSource(Sources []item.Item) {
|
||||
for _, source := range Sources {
|
||||
switch source {
|
||||
case item.ChromiumPassword:
|
||||
d.Sources[source] = &ChromiumPassword{}
|
||||
d.Sources[source] = &password.ChromiumPassword{}
|
||||
case item.ChromiumCookie:
|
||||
d.Sources[source] = &ChromiumCookie{}
|
||||
d.Sources[source] = &cookie.ChromiumCookie{}
|
||||
case item.ChromiumBookmark:
|
||||
d.Sources[source] = &ChromiumBookmark{}
|
||||
d.Sources[source] = &bookmark.ChromiumBookmark{}
|
||||
case item.ChromiumHistory:
|
||||
d.Sources[source] = &ChromiumHistory{}
|
||||
d.Sources[source] = &history.ChromiumHistory{}
|
||||
case item.ChromiumDownload:
|
||||
d.Sources[source] = &ChromiumDownload{}
|
||||
d.Sources[source] = &download.ChromiumDownload{}
|
||||
case item.ChromiumCreditCard:
|
||||
d.Sources[source] = &ChromiumCreditCard{}
|
||||
d.Sources[source] = &creditcard.ChromiumCreditCard{}
|
||||
case item.YandexPassword:
|
||||
d.Sources[source] = &YandexPassword{}
|
||||
d.Sources[source] = &password.YandexPassword{}
|
||||
case item.YandexCreditCard:
|
||||
d.Sources[source] = &YandexCreditCard{}
|
||||
d.Sources[source] = &creditcard.YandexCreditCard{}
|
||||
case item.FirefoxPassword:
|
||||
d.Sources[source] = &FirefoxPassword{}
|
||||
d.Sources[source] = &password.FirefoxPassword{}
|
||||
case item.FirefoxCookie:
|
||||
d.Sources[source] = &FirefoxCookie{}
|
||||
d.Sources[source] = &cookie.FirefoxCookie{}
|
||||
case item.FirefoxBookmark:
|
||||
d.Sources[source] = &FirefoxBookmark{}
|
||||
d.Sources[source] = &bookmark.FirefoxBookmark{}
|
||||
case item.FirefoxHistory:
|
||||
d.Sources[source] = &FirefoxHistory{}
|
||||
d.Sources[source] = &history.FirefoxHistory{}
|
||||
case item.FirefoxDownload:
|
||||
d.Sources[source] = &FirefoxDownload{}
|
||||
d.Sources[source] = &download.FirefoxDownload{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, billing_address_id, nickname FROM credit_cards`
|
||||
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||||
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
||||
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||||
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
|
||||
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
||||
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places where title not null`
|
||||
queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content), url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id`
|
||||
queryFirefoxBookMark = `SELECT id, url, type, dateAdded, title FROM (SELECT * FROM moz_bookmarks INNER JOIN moz_places ON moz_bookmarks.fk=moz_places.id)`
|
||||
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||||
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
|
||||
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
|
||||
closeJournalMode = `PRAGMA journal_mode=off`
|
||||
)
|
||||
|
||||
type (
|
||||
loginData struct {
|
||||
UserName string
|
||||
encryptPass []byte
|
||||
encryptUser []byte
|
||||
Password string
|
||||
LoginUrl string
|
||||
CreateDate time.Time
|
||||
}
|
||||
cookie struct {
|
||||
Host string
|
||||
Path string
|
||||
KeyName string
|
||||
encryptValue []byte
|
||||
Value string
|
||||
IsSecure bool
|
||||
IsHTTPOnly bool
|
||||
HasExpire bool
|
||||
IsPersistent bool
|
||||
CreateDate time.Time
|
||||
ExpireDate time.Time
|
||||
}
|
||||
history struct {
|
||||
Title string
|
||||
Url string
|
||||
VisitCount int
|
||||
LastVisitTime time.Time
|
||||
}
|
||||
download struct {
|
||||
TargetPath string
|
||||
Url string
|
||||
TotalBytes int64
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
MimeType string
|
||||
}
|
||||
card struct {
|
||||
GUID string
|
||||
Name string
|
||||
ExpirationYear string
|
||||
ExpirationMonth string
|
||||
CardNumber string
|
||||
Address string
|
||||
NickName string
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package browingdata
|
||||
package cookie
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
@@ -15,6 +16,24 @@ import (
|
||||
|
||||
type ChromiumCookie []cookie
|
||||
|
||||
type cookie struct {
|
||||
Host string
|
||||
Path string
|
||||
KeyName string
|
||||
encryptValue []byte
|
||||
Value string
|
||||
IsSecure bool
|
||||
IsHTTPOnly bool
|
||||
HasExpire bool
|
||||
IsPersistent bool
|
||||
CreateDate time.Time
|
||||
ExpireDate time.Time
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumCookie = `SELECT name, encrypted_value, host_key, path, creation_utc, expires_utc, is_secure, is_httponly, has_expires, is_persistent FROM cookies`
|
||||
)
|
||||
|
||||
func (c *ChromiumCookie) Parse(masterKey []byte) error {
|
||||
cookieDB, err := sql.Open("sqlite3", item.TempChromiumCookie)
|
||||
if err != nil {
|
||||
@@ -77,6 +96,10 @@ func (c *ChromiumCookie) Name() string {
|
||||
|
||||
type FirefoxCookie []cookie
|
||||
|
||||
const (
|
||||
queryFirefoxCookie = `SELECT name, value, host, path, creationTime, expiry, isSecure, isHttpOnly FROM moz_cookies`
|
||||
)
|
||||
|
||||
func (f *FirefoxCookie) Parse(masterKey []byte) error {
|
||||
cookieDB, err := sql.Open("sqlite3", item.TempFirefoxCookie)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package browingdata
|
||||
package creditcard
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
@@ -13,6 +13,20 @@ import (
|
||||
|
||||
type ChromiumCreditCard []card
|
||||
|
||||
type card struct {
|
||||
GUID string
|
||||
Name string
|
||||
ExpirationYear string
|
||||
ExpirationMonth string
|
||||
CardNumber string
|
||||
Address string
|
||||
NickName string
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted, billing_address_id, nickname FROM credit_cards`
|
||||
)
|
||||
|
||||
func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
|
||||
creditDB, err := sql.Open("sqlite3", item.TempChromiumCreditCard)
|
||||
if err != nil {
|
||||
@@ -70,6 +84,7 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
|
||||
}
|
||||
defer os.Remove(item.TempYandexCreditCard)
|
||||
defer creditDB.Close()
|
||||
defer creditDB.Close()
|
||||
rows, err := creditDB.Query(queryChromiumCredit)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -77,17 +92,19 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var (
|
||||
name, month, year, guid string
|
||||
value, encryptValue []byte
|
||||
name, month, year, guid, address, nickname string
|
||||
value, encryptValue []byte
|
||||
)
|
||||
if err := rows.Scan(&guid, &name, &month, &year, &encryptValue); err != nil {
|
||||
if err := rows.Scan(&guid, &name, &month, &year, &encryptValue, &address, &nickname); err != nil {
|
||||
log.Warn(err)
|
||||
}
|
||||
creditCardInfo := card{
|
||||
ccInfo := card{
|
||||
GUID: guid,
|
||||
Name: name,
|
||||
ExpirationMonth: month,
|
||||
ExpirationYear: year,
|
||||
Address: address,
|
||||
NickName: nickname,
|
||||
}
|
||||
if masterKey == nil {
|
||||
value, err = decrypter.DPApi(encryptValue)
|
||||
@@ -100,8 +117,8 @@ func (c *YandexCreditCard) Parse(masterKey []byte) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
creditCardInfo.CardNumber = string(value)
|
||||
*c = append(*c, creditCardInfo)
|
||||
ccInfo.CardNumber = string(value)
|
||||
*c = append(*c, ccInfo)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package browingdata
|
||||
package download
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/log"
|
||||
@@ -16,6 +17,19 @@ import (
|
||||
|
||||
type ChromiumDownload []download
|
||||
|
||||
type download struct {
|
||||
TargetPath string
|
||||
Url string
|
||||
TotalBytes int64
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
MimeType string
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumDownload = `SELECT target_path, tab_url, total_bytes, start_time, end_time, mime_type FROM downloads`
|
||||
)
|
||||
|
||||
func (c *ChromiumDownload) Parse(masterKey []byte) error {
|
||||
historyDB, err := sql.Open("sqlite3", item.TempChromiumDownload)
|
||||
if err != nil {
|
||||
@@ -58,6 +72,11 @@ func (c *ChromiumDownload) Name() string {
|
||||
|
||||
type FirefoxDownload []download
|
||||
|
||||
const (
|
||||
queryFirefoxDownload = `SELECT place_id, GROUP_CONCAT(content), url, dateAdded FROM (SELECT * FROM moz_annos INNER JOIN moz_places ON moz_annos.place_id=moz_places.id) t GROUP BY place_id`
|
||||
closeJournalMode = `PRAGMA journal_mode=off`
|
||||
)
|
||||
|
||||
func (f *FirefoxDownload) Parse(masterKey []byte) error {
|
||||
var (
|
||||
err error
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package browingdata
|
||||
package history
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
@@ -14,6 +15,17 @@ import (
|
||||
|
||||
type ChromiumHistory []history
|
||||
|
||||
type history struct {
|
||||
Title string
|
||||
Url string
|
||||
VisitCount int
|
||||
LastVisitTime time.Time
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls`
|
||||
)
|
||||
|
||||
func (c *ChromiumHistory) Parse(masterKey []byte) error {
|
||||
historyDB, err := sql.Open("sqlite3", item.TempChromiumHistory)
|
||||
if err != nil {
|
||||
@@ -56,6 +68,11 @@ func (c *ChromiumHistory) Name() string {
|
||||
|
||||
type FirefoxHistory []history
|
||||
|
||||
const (
|
||||
queryFirefoxHistory = `SELECT id, url, last_visit_date, title, visit_count FROM moz_places where title not null`
|
||||
closeJournalMode = `PRAGMA journal_mode=off`
|
||||
)
|
||||
|
||||
func (f *FirefoxHistory) Parse(masterKey []byte) error {
|
||||
var (
|
||||
err error
|
||||
@@ -0,0 +1,76 @@
|
||||
package browingdata
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gocarina/gocsv"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type OutPutter struct {
|
||||
json bool
|
||||
csv bool
|
||||
}
|
||||
|
||||
func NewOutPutter(flag string) *OutPutter {
|
||||
o := &OutPutter{}
|
||||
if flag == "json" {
|
||||
o.json = true
|
||||
} else {
|
||||
o.csv = true
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *OutPutter) Write(data Source, writer io.Writer) error {
|
||||
switch o.json {
|
||||
case true:
|
||||
encoder := jsoniter.NewEncoder(writer)
|
||||
encoder.SetIndent(" ", " ")
|
||||
encoder.SetEscapeHTML(false)
|
||||
return encoder.Encode(data)
|
||||
default:
|
||||
gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter {
|
||||
writer := csv.NewWriter(w)
|
||||
writer.Comma = ','
|
||||
return gocsv.NewSafeCSVWriter(writer)
|
||||
})
|
||||
return gocsv.Marshal(data, writer)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *OutPutter) CreateFile(dir, filename string) (*os.File, error) {
|
||||
if filename == "" {
|
||||
return nil, errors.New("empty filename")
|
||||
}
|
||||
|
||||
if dir != "" {
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
err := os.MkdirAll(dir, 0777)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var file *os.File
|
||||
var err error
|
||||
p := filepath.Join(dir, filename)
|
||||
file, err = os.OpenFile(p, os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (o *OutPutter) Ext() string {
|
||||
if o.json {
|
||||
return "json"
|
||||
} else {
|
||||
return "csv"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package outputter
|
||||
package browingdata
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNewOutPutter(t *testing.T) {
|
||||
out := New("json")
|
||||
out := NewOutPutter("json")
|
||||
if out == nil {
|
||||
t.Error("New() returned nil")
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package browingdata
|
||||
package password
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -20,6 +20,19 @@ import (
|
||||
|
||||
type ChromiumPassword []loginData
|
||||
|
||||
type loginData struct {
|
||||
UserName string
|
||||
encryptPass []byte
|
||||
encryptUser []byte
|
||||
Password string
|
||||
LoginUrl string
|
||||
CreateDate time.Time
|
||||
}
|
||||
|
||||
const (
|
||||
queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins`
|
||||
)
|
||||
|
||||
func (c *ChromiumPassword) Parse(masterKey []byte) error {
|
||||
loginDB, err := sql.Open("sqlite3", item.TempChromiumPassword)
|
||||
if err != nil {
|
||||
@@ -79,6 +92,10 @@ func (c *ChromiumPassword) Name() string {
|
||||
|
||||
type YandexPassword []loginData
|
||||
|
||||
const (
|
||||
queryYandexLogin = `SELECT action_url, username_value, password_value, date_created FROM logins`
|
||||
)
|
||||
|
||||
func (c *YandexPassword) Parse(masterKey []byte) error {
|
||||
loginDB, err := sql.Open("sqlite3", item.TempYandexPassword)
|
||||
if err != nil {
|
||||
@@ -139,6 +156,11 @@ func (c *YandexPassword) Name() string {
|
||||
|
||||
type FirefoxPassword []loginData
|
||||
|
||||
const (
|
||||
queryMetaData = `SELECT item1, item2 FROM metaData WHERE id = 'password'`
|
||||
queryNssPrivate = `SELECT a11, a102 from nssPrivate`
|
||||
)
|
||||
|
||||
func (f *FirefoxPassword) Parse(masterKey []byte) error {
|
||||
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user