diff --git a/core/browser.go b/core/browser.go index d53c092..2749a25 100644 --- a/core/browser.go +++ b/core/browser.go @@ -46,7 +46,7 @@ const ( cookie = "cookie" history = "history" bookmark = "bookmark" - downloadHistory = "downloadHistory" + download = "download" password = "password" creditcard = "creditcard" ) @@ -75,9 +75,9 @@ var ( mainFile: data.ChromeHistoryFile, newItem: data.NewHistoryData, }, - downloadHistory: { - mainFile: data.ChromeHistoryFile, - newItem: data.NewDownloadHistoryData, + download: { + mainFile: data.ChromeDownloadFile, + newItem: data.NewDownloads, }, password: { mainFile: data.ChromePasswordFile, diff --git a/core/data/output.go b/core/data/output.go index 1596fdf..45b7a57 100644 --- a/core/data/output.go +++ b/core/data/output.go @@ -42,13 +42,13 @@ func (h *historyData) outPutJson(browser, dir string) error { return nil } -func (d *downloadHistoryData) outPutJson(browser, dir string) error { - filename := utils.FormatFileName(dir, browser, "download_history", "json") - err := writeToJson(filename, d.downloadHistory) +func (d *downloads) outPutJson(browser, dir string) error { + filename := utils.FormatFileName(dir, browser, "download", "json") + err := writeToJson(filename, d.downloads) if err != nil { return err } - fmt.Printf("%s Get %d history, filename is %s \n", utils.Prefix, len(d.downloadHistory), filename) + fmt.Printf("%s Get %d history, filename is %s \n", utils.Prefix, len(d.downloads), filename) return nil } @@ -121,12 +121,12 @@ func (h *historyData) outPutCsv(browser, dir string) error { return nil } -func (d *downloadHistoryData) outPutCsv(browser, dir string) error { - filename := utils.FormatFileName(dir, browser, "download_history", "csv") - if err := writeToCsv(filename, d.downloadHistory); err != nil { +func (d *downloads) outPutCsv(browser, dir string) error { + filename := utils.FormatFileName(dir, browser, "download", "csv") + if err := writeToCsv(filename, d.downloads); err != nil { return err } - fmt.Printf("%s Get %d download history, filename is %s \n", utils.Prefix, len(d.downloadHistory), filename) + fmt.Printf("%s Get %d download history, filename is %s \n", utils.Prefix, len(d.downloads), filename) return nil } @@ -205,8 +205,8 @@ func (h *historyData) outPutConsole() { } } -func (d *downloadHistoryData) outPutConsole() { - for _, v := range d.downloadHistory { +func (d *downloads) outPutConsole() { + for _, v := range d.downloads { fmt.Printf("%+v\n", v) } } diff --git a/core/data/parse.go b/core/data/parse.go index eaf8179..b7756bd 100644 --- a/core/data/parse.go +++ b/core/data/parse.go @@ -39,6 +39,7 @@ const ( ChromeCreditFile = "Web Data" ChromePasswordFile = "Login Data" ChromeHistoryFile = "History" + ChromeDownloadFile = "History" ChromeCookieFile = "Cookies" ChromeBookmarkFile = "Bookmarks" FirefoxCookieFile = "cookies.sqlite" @@ -48,17 +49,17 @@ const ( ) var ( - queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards` - queryChromiumLogin = `SELECT origin_url, username_value, password_value, date_created FROM logins` - queryChromiumHistory = `SELECT url, title, visit_count, last_visit_time FROM urls` - queryChromiumDownloadHistory = `SELECT target_path, tab_url, total_bytes, start_time, end_time 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` - queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks` - 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` + queryChromiumCredit = `SELECT guid, name_on_card, expiration_month, expiration_year, card_number_encrypted FROM credit_cards` + queryChromiumLogin = `SELECT origin_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` + queryFirefoxBookMarks = `SELECT id, fk, type, dateAdded, title FROM moz_bookmarks` + 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` ) const ( @@ -448,17 +449,17 @@ func (h *historyData) OutPut(format, browser, dir string) error { } } -type downloadHistoryData struct { - mainPath string - downloadHistory []downloadHistory +type downloads struct { + mainPath string + downloads []download } -func NewDownloadHistoryData(main, sub string) Item { - return &downloadHistoryData{mainPath: main} +func NewDownloads(main, sub string) Item { + return &downloads{mainPath: main} } -func (d *downloadHistoryData) ChromeParse(key []byte) error { - historyDB, err := sql.Open("sqlite3", ChromeHistoryFile) +func (d *downloads) ChromeParse(key []byte) error { + historyDB, err := sql.Open("sqlite3", ChromeDownloadFile) if err != nil { return err } @@ -467,49 +468,50 @@ func (d *downloadHistoryData) ChromeParse(key []byte) error { log.Error(err) } }() - rows, err := historyDB.Query(queryChromiumDownloadHistory) + rows, err := historyDB.Query(queryChromiumDownload) if err != nil { return err } defer func() { if err := rows.Close(); err != nil { - log.Debug(err) + log.Error(err) } }() for rows.Next() { var ( - target_path, tab_url string - total_bytes, start_time, end_time int64 + targetPath, tabUrl, mimeType string + totalBytes, startTime, endTime int64 ) - err := rows.Scan(&target_path, &tab_url, &total_bytes, &start_time, &end_time) - data := downloadHistory{ - TargetPath: target_path, - Url: tab_url, - TotalBytes: total_bytes, - StartTime: utils.TimeEpochFormat(start_time), - EndTime: utils.TimeEpochFormat(end_time), + err := rows.Scan(&targetPath, &tabUrl, &totalBytes, &startTime, &endTime, &mimeType) + data := download{ + TargetPath: targetPath, + Url: tabUrl, + TotalBytes: totalBytes, + StartTime: utils.TimeEpochFormat(startTime), + EndTime: utils.TimeEpochFormat(endTime), + MimiType: mimeType, } if err != nil { log.Error(err) } - d.downloadHistory = append(d.downloadHistory, data) + d.downloads = append(d.downloads, data) } return nil } -func (d *downloadHistoryData) FirefoxParse() error { +func (d *downloads) FirefoxParse() error { return nil } -func (d *downloadHistoryData) CopyDB() error { +func (d *downloads) CopyDB() error { return copyToLocalPath(d.mainPath, filepath.Base(d.mainPath)) } -func (d *downloadHistoryData) Release() error { +func (d *downloads) Release() error { return os.Remove(filepath.Base(d.mainPath)) } -func (d *downloadHistoryData) OutPut(format, browser, dir string) error { +func (d *downloads) OutPut(format, browser, dir string) error { switch format { case "csv": err := d.outPutCsv(browser, dir) @@ -673,6 +675,7 @@ func (p *passwords) Release() error { } func (p *passwords) OutPut(format, browser, dir string) error { + sort.Sort(p) switch format { case "csv": err := p.outPutCsv(browser, dir) @@ -881,12 +884,13 @@ type ( VisitCount int LastVisitTime time.Time } - downloadHistory struct { - TargetPath string - Url string - TotalBytes int64 - StartTime time.Time - EndTime time.Time + download struct { + TargetPath string + Url string + TotalBytes int64 + StartTime time.Time + EndTime time.Time + MimiType string } card struct { GUID string @@ -909,6 +913,18 @@ func (p passwords) Swap(i, j int) { p.logins[i], p.logins[j] = p.logins[j], p.logins[i] } +func (d downloads) Len() int { + return len(d.downloads) +} + +func (d downloads) Less(i, j int) bool { + return d.downloads[i].StartTime.After(d.downloads[j].StartTime) +} + +func (d downloads) Swap(i, j int) { + d.downloads[i], d.downloads[j] = d.downloads[j], d.downloads[i] +} + func copyToLocalPath(src, dst string) error { locals, _ := filepath.Glob("*") for _, v := range locals {