2022-04-12 05:48:03 +00:00
package main
import (
"fmt"
"os"
2022-04-12 10:23:02 +00:00
"strings"
2022-04-12 05:48:03 +00:00
"hack-browser-data/internal/browser"
"hack-browser-data/internal/log"
"hack-browser-data/internal/outputter"
2022-04-14 15:36:11 +00:00
"hack-browser-data/internal/utils/fileutil"
2022-04-12 10:23:02 +00:00
"github.com/urfave/cli/v2"
2022-04-12 05:48:03 +00:00
)
var (
2022-04-14 15:36:11 +00:00
browserName string
outputDir string
outputFormat string
verbose bool
compress bool
profilePath string
2022-04-12 05:48:03 +00:00
)
func main ( ) {
Execute ( )
}
func Execute ( ) {
2022-04-12 10:23:02 +00:00
app := & cli . App {
2022-04-14 15:36:11 +00:00
Name : "hack-browser-data" ,
Usage : "Export passwords/cookies/history/bookmarks from browser" ,
UsageText : "[hack-browser-data -b chrome -f json -dir results -cc]\nGet all browingdata(password/cookie/history/bookmark) from browser" ,
Version : "0.4.0" ,
2022-04-12 10:23:02 +00:00
Flags : [ ] cli . Flag {
& cli . BoolFlag { Name : "verbose" , Aliases : [ ] string { "vv" } , Destination : & verbose , Value : false , Usage : "verbose" } ,
& cli . BoolFlag { Name : "compress" , Aliases : [ ] string { "cc" } , Destination : & compress , Value : false , Usage : "compress result to zip" } ,
& cli . StringFlag { Name : "browser" , Aliases : [ ] string { "b" } , Destination : & browserName , Value : "all" , Usage : "available browsers: all|" + strings . Join ( browser . ListBrowser ( ) , "|" ) } ,
2022-04-14 15:36:11 +00:00
& cli . StringFlag { Name : "results-dir" , Aliases : [ ] string { "dir" } , Destination : & outputDir , Value : "results" , Usage : "export dir" } ,
2022-04-12 10:23:02 +00:00
& cli . StringFlag { Name : "format" , Aliases : [ ] string { "f" } , Destination : & outputFormat , Value : "csv" , Usage : "format, csv|json|console" } ,
2022-04-15 19:57:19 +00:00
& cli . StringFlag { Name : "profile-path" , Aliases : [ ] string { "p" } , Destination : & profilePath , Value : "" , Usage : "custom profile dir path, get with chrome://version" } ,
2022-04-12 10:23:02 +00:00
} ,
HideHelpCommand : true ,
Action : func ( c * cli . Context ) error {
if verbose {
2022-04-15 19:57:19 +00:00
log . Init ( "debug" )
2022-04-12 10:23:02 +00:00
} else {
2022-04-15 19:57:19 +00:00
log . Init ( "error" )
2022-04-12 10:23:02 +00:00
}
2022-04-14 15:36:11 +00:00
var (
browsers [ ] browser . Browser
err error
)
2022-04-15 19:57:19 +00:00
log . Debugf ( "browser: %s" , browserName )
2022-04-14 15:36:11 +00:00
browsers , err = browser . PickBrowser ( browserName , profilePath )
2022-04-12 05:48:03 +00:00
if err != nil {
log . Error ( err )
}
2022-04-12 10:23:02 +00:00
output := outputter . New ( outputFormat )
for _ , b := range browsers {
data , err := b . GetBrowsingData ( )
if err != nil {
log . Error ( err )
}
var f * os . File
for _ , source := range data . Sources {
filename := fmt . Sprintf ( "%s_%s.%s" , b . Name ( ) , source . Name ( ) , outputFormat )
2022-04-14 15:36:11 +00:00
f , err = output . CreateFile ( outputDir , filename )
if err != nil {
log . Error ( err )
}
2022-04-12 10:23:02 +00:00
err = output . Write ( source , f )
if err != nil {
log . Error ( err )
}
}
}
if compress {
2022-04-14 15:36:11 +00:00
err = fileutil . CompressDir ( outputDir )
2022-04-12 10:23:02 +00:00
if err != nil {
log . Error ( err )
}
}
return nil
} ,
}
err := app . Run ( os . Args )
if err != nil {
log . Error ( err )
2022-04-12 05:48:03 +00:00
}
}