From 16db6685d77ddb47a45f09a100368b36820ffe04 Mon Sep 17 00:00:00 2001 From: NSEcho Date: Wed, 13 Sep 2023 17:46:35 +0200 Subject: [PATCH] feat: write crash to file --- main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main.go b/main.go index 216ed5e..c22e6c4 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "crypto/sha256" _ "embed" "errors" "fmt" @@ -105,8 +106,25 @@ var rootCmd = &cobra.Command{ return err } + var lastInput string + sess.On("detached", func(reason frida.SessionDetachReason, crash *frida.Crash) { l.Infof("session detached; reason=%s", reason.String()) + out := crashSHA256(lastInput) + err := func() error { + f, err := os.Create(out) + if err != nil { + return err + } + f.WriteString(lastInput) + return nil + }() + if err != nil { + l.Errorf("error writing crash file: %v", err) + } else { + l.Infof("written crash to: %s", out) + } + os.Exit(1) }) script, err := sess.CreateScript(scriptContent) @@ -131,6 +149,7 @@ var rootCmd = &cobra.Command{ } for mutated := range ch { + lastInput = mutated.Input l.Infof("[%s] %s\n", color.New(color.FgCyan).Sprintf("%s", mutated.Mutation), mutated.Input) _ = script.ExportsCall("fuzz", method, mutated.Input) if timeout > 0 { @@ -190,3 +209,9 @@ func readInputs(dirPath string) ([]string, error) { } return validInputs, nil } + +func crashSHA256(inp string) string { + h := sha256.New() + h.Write([]byte(inp)) + return fmt.Sprintf("%x", h.Sum(nil)) +}