mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent. varnamelen and staticcheck ST1020-22 now keep both from coming back.
66 lines
2.3 KiB
Go
66 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/app"
|
|
"github.com/moond4rk/hackbrowserdata/internal/log"
|
|
)
|
|
|
|
func dumpCmd() *cobra.Command {
|
|
var flags app.Flags
|
|
|
|
command := &cobra.Command{
|
|
Use: "dump",
|
|
Short: "Extract and decrypt browser data (default command)",
|
|
Example: ` hack-browser-data dump
|
|
hack-browser-data dump -b chrome -c password,cookie
|
|
hack-browser-data dump -b chrome -f json -d output
|
|
hack-browser-data dump -f cookie-editor
|
|
hack-browser-data dump --zip`,
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
return runDump(command.Context(), command.ErrOrStderr(), flags)
|
|
},
|
|
}
|
|
|
|
command.Flags().StringVarP(&flags.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
|
|
command.Flags().StringVarP(&flags.Categories, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
|
|
command.Flags().StringVarP(&flags.Format, "format", "f", "json", "output format: csv|json|cookie-editor")
|
|
command.Flags().StringVarP(&flags.Dir, "dir", "d", "results", "output directory")
|
|
command.Flags().StringVarP(&flags.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
|
keychainPasswordFlags(command, &flags)
|
|
command.Flags().BoolVar(&flags.Zip, "zip", false, "compress output to zip")
|
|
|
|
return command
|
|
}
|
|
|
|
func keychainPasswordFlags(command *cobra.Command, flags *app.Flags) {
|
|
command.Flags().StringVar(&flags.KeychainPassword, "keychain-pw", "", "macOS keychain password (visible in ps and shell history)")
|
|
command.Flags().BoolVar(&flags.KeychainPasswordStdin, "keychain-pw-stdin", false,
|
|
"read the macOS keychain password from the first line of stdin")
|
|
command.MarkFlagsMutuallyExclusive("keychain-pw", "keychain-pw-stdin")
|
|
}
|
|
|
|
func runDump(ctx context.Context, stderr io.Writer, flags app.Flags) error {
|
|
options, err := app.Validate(flags)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
discovery := app.Discover(options)
|
|
if len(discovery.Dirs) == 0 {
|
|
if len(discovery.Failed) > 0 {
|
|
report(stderr, app.Summary{Results: discovery.Failed})
|
|
}
|
|
log.Warnf("no browsers found")
|
|
return nil
|
|
}
|
|
summary, err := app.Execute(ctx, app.NewPlan(discovery, options), options)
|
|
if ctx.Err() == nil {
|
|
report(stderr, summary)
|
|
}
|
|
return err
|
|
}
|