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.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/app"
|
|
"github.com/moond4rk/hackbrowserdata/internal/log"
|
|
)
|
|
|
|
func dumpKeysCmd() *cobra.Command {
|
|
var (
|
|
flags app.Flags
|
|
outputPath string
|
|
)
|
|
|
|
command := &cobra.Command{
|
|
Use: "dumpkeys",
|
|
Short: "Export Chromium master keys as JSON for cross-host decryption",
|
|
Example: ` hack-browser-data dumpkeys -o keys.json
|
|
hack-browser-data dumpkeys -b chrome`,
|
|
RunE: func(command *cobra.Command, args []string) error {
|
|
options, err := app.ValidateKeys(flags)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dump, err := app.DumpKeys(command.Context(), app.Discover(options), options)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Infof("Exported keys for %d vault(s)", len(dump.Vaults))
|
|
|
|
if outputPath == "" {
|
|
return dump.WriteJSON(os.Stdout)
|
|
}
|
|
file, err := os.OpenFile(outputPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
|
|
if err != nil {
|
|
return fmt.Errorf("create %s: %w", outputPath, err)
|
|
}
|
|
return errors.Join(dump.WriteJSON(file), file.Close())
|
|
},
|
|
}
|
|
|
|
command.Flags().StringVarP(&flags.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
|
|
command.Flags().StringVarP(&outputPath, "output", "o", "", "output file (default: stdout)")
|
|
keychainPasswordFlags(command, &flags)
|
|
|
|
return command
|
|
}
|