mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
feat(firefox): decrypt profiles with a primary password (#704)
Profiles protected by a Firefox primary password could not be decrypted; --firefox-pw and --firefox-pw-stdin supply it, read once per run, and new 48-byte NSS salts hash with SHA-384. Closes #109
This commit is contained in:
1 parent
c733ac9d6d
commit
b14b2c021a
15 files changed
+332
-69
No files matched your search
@@ -14,6 +14,7 @@ func newDumpCommand() *cobra.Command {
|
||||
var (
|
||||
flags app.DumpFlags
|
||||
keychain keychainFlags
|
||||
firefox firefoxFlags
|
||||
)
|
||||
|
||||
command := &cobra.Command{
|
||||
@@ -25,7 +26,7 @@ func newDumpCommand() *cobra.Command {
|
||||
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, keychain)
|
||||
return runDump(command.Context(), command.ErrOrStderr(), flags, keychain, firefox)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -35,14 +36,16 @@ func newDumpCommand() *cobra.Command {
|
||||
command.Flags().StringVarP(&flags.OutputDir, "dir", "d", "results", "output directory")
|
||||
command.Flags().StringVarP(&flags.ProfilePath, "profile-path", "p", "", "custom profile dir path, get with chrome://version")
|
||||
addKeychainPasswordFlags(command, &keychain)
|
||||
addFirefoxPasswordFlags(command, &firefox)
|
||||
command.Flags().BoolVar(&flags.Zip, "zip", false, "compress output to zip")
|
||||
command.Flags().IntVar(&flags.MaxStorageValue, "max-storage-value", app.DefaultMaxStorageValue, "max storage value chars, 0=unlimited")
|
||||
command.MarkFlagsMutuallyExclusive("keychain-pw-stdin", "firefox-pw-stdin")
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychain keychainFlags) error {
|
||||
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin))
|
||||
func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychain keychainFlags, firefox firefoxFlags) error {
|
||||
options, err := app.ValidateDump(flags, keychainPasswordFunc(keychain, os.Stdin), firefoxPasswordFunc(firefox, os.Stdin))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -50,7 +53,7 @@ func runDump(ctx context.Context, stderr io.Writer, flags app.DumpFlags, keychai
|
||||
if warnIfNothingFound(stderr, discovery, "no browsers found") {
|
||||
return nil
|
||||
}
|
||||
summary, err := app.Execute(ctx, discovery, options.Categories, options.Output, options.Keychain)
|
||||
summary, err := app.Execute(ctx, discovery, options.Categories, options.Output, options.Keychain, options.FirefoxPassword)
|
||||
announceExport(stderr, summary.Exported)
|
||||
if ctx.Err() == nil {
|
||||
report(stderr, summary)
|
||||
|
||||
@@ -26,6 +26,34 @@ func addKeychainPasswordFlags(command *cobra.Command, flags *keychainFlags) {
|
||||
command.MarkFlagsMutuallyExclusive("keychain-pw", "keychain-pw-stdin")
|
||||
}
|
||||
|
||||
// firefoxFlags say where a Firefox primary password comes from; both empty means the empty password, the common case.
|
||||
type firefoxFlags struct {
|
||||
password string
|
||||
passwordStdin bool
|
||||
}
|
||||
|
||||
func addFirefoxPasswordFlags(command *cobra.Command, flags *firefoxFlags) {
|
||||
command.Flags().StringVar(&flags.password, "firefox-pw", "", "Firefox primary password (visible in ps and shell history)")
|
||||
command.Flags().BoolVar(&flags.passwordStdin, "firefox-pw-stdin", false,
|
||||
"read the Firefox primary password from the first line of stdin")
|
||||
command.MarkFlagsMutuallyExclusive("firefox-pw", "firefox-pw-stdin")
|
||||
}
|
||||
|
||||
// firefoxPasswordFunc reads a flag, else the first line of stdin; nil means the empty password, and it never prompts.
|
||||
func firefoxPasswordFunc(flags firefoxFlags, stdin *os.File) func(context.Context) (string, error) {
|
||||
switch {
|
||||
case flags.password != "":
|
||||
password := flags.password
|
||||
return func(context.Context) (string, error) { return password, nil }
|
||||
case flags.passwordStdin:
|
||||
return func(ctx context.Context) (string, error) {
|
||||
return untilDone(ctx, func() (string, error) { return firstLine(stdin) })
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var errNoPassword = errors.New("macOS login password not given and stdin is not a terminal")
|
||||
|
||||
// keychainPasswordFunc is read lazily: a flag, else a no-echo prompt on a terminal, else none (metadata only).
|
||||
|
||||
+4
@@ -1,6 +1,8 @@
|
||||
hack-browser-data --browser -b string "all"
|
||||
hack-browser-data --category -c string "all"
|
||||
hack-browser-data --dir -d string "results"
|
||||
hack-browser-data --firefox-pw string ""
|
||||
hack-browser-data --firefox-pw-stdin bool "false"
|
||||
hack-browser-data --format -f string "json"
|
||||
hack-browser-data --help -h bool "false"
|
||||
hack-browser-data --keychain-pw string ""
|
||||
@@ -17,6 +19,8 @@ hack-browser-data archive --verbose -v bool "false" inherited
|
||||
hack-browser-data dump --browser -b string "all"
|
||||
hack-browser-data dump --category -c string "all"
|
||||
hack-browser-data dump --dir -d string "results"
|
||||
hack-browser-data dump --firefox-pw string ""
|
||||
hack-browser-data dump --firefox-pw-stdin bool "false"
|
||||
hack-browser-data dump --format -f string "json"
|
||||
hack-browser-data dump --help -h bool "false"
|
||||
hack-browser-data dump --keychain-pw string ""
|
||||
|
||||
Reference in new issue
Block a user