Skip to content

Commit

Permalink
feat: write crash to file
Browse files Browse the repository at this point in the history
  • Loading branch information
NSEcho committed Sep 13, 2023
1 parent ffe3945 commit 16db668
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/sha256"
_ "embed"
"errors"
"fmt"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}

0 comments on commit 16db668

Please sign in to comment.