2018-05-30 17:28:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
|
2018-06-05 20:53:08 +00:00
|
|
|
"git.thisco.de/vbatts/fuzz-walker/walker"
|
2018-05-30 17:28:42 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-06-05 20:53:08 +00:00
|
|
|
"github.com/urfave/cli"
|
2018-05-30 17:28:42 +00:00
|
|
|
)
|
|
|
|
|
2018-06-06 15:21:08 +00:00
|
|
|
// This list is populated in the beforefunc of the application
|
|
|
|
var walkerPlugins []walker.Fuzzer
|
2018-06-05 21:34:58 +00:00
|
|
|
|
2018-05-30 17:28:42 +00:00
|
|
|
func main() {
|
2018-06-05 20:53:08 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "fuzz-walker"
|
|
|
|
app.Usage = "a walker to poke and prod at /proc and /sys"
|
2018-06-06 15:21:08 +00:00
|
|
|
app.Before = func(c *cli.Context) error {
|
|
|
|
matches, err := filepath.Glob(c.String("plugins"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, match := range matches {
|
|
|
|
ff, err := walker.LoadPlugin(match)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
walkerPlugins = append(walkerPlugins, ff)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-06-05 21:34:58 +00:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "plugins",
|
|
|
|
Usage: "pattern to glob walker plugins",
|
2018-06-06 15:21:08 +00:00
|
|
|
Value: "*.so",
|
|
|
|
},
|
|
|
|
cli.DurationFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Usage: "timeout in milliseconds for each fuzz function",
|
|
|
|
Value: 500,
|
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "paths",
|
|
|
|
Usage: "system paths to poke at with fuzzer plugins",
|
|
|
|
Value: &cli.StringSlice{
|
|
|
|
"/proc",
|
|
|
|
"/sys",
|
|
|
|
},
|
2018-06-05 21:34:58 +00:00
|
|
|
},
|
|
|
|
}
|
2018-06-05 20:53:08 +00:00
|
|
|
app.Action = func(c *cli.Context) error {
|
|
|
|
hasError := false
|
2018-06-06 15:21:08 +00:00
|
|
|
for _, dir := range c.StringSlice("paths") {
|
2018-06-05 20:53:08 +00:00
|
|
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-06-06 15:21:08 +00:00
|
|
|
|
2018-06-06 14:42:39 +00:00
|
|
|
for _, wp := range walkerPlugins {
|
2018-06-06 15:21:08 +00:00
|
|
|
c1 := make(chan error, 1)
|
|
|
|
go func() {
|
|
|
|
c1 <- wp.Func(path, info, c.Duration("timeout")*time.Millisecond)
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case err := <-c1:
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("%s: %q fuzz failed with: %v", path, wp.Name(), err)
|
|
|
|
}
|
|
|
|
case <-time.After(c.Duration("timeout") * time.Millisecond):
|
|
|
|
logrus.Warnf("%s: %q fuzz timed out", path, wp.Name())
|
2018-06-05 20:53:08 +00:00
|
|
|
}
|
2018-05-30 17:28:42 +00:00
|
|
|
}
|
2018-06-05 20:53:08 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("%s: %v", dir, err)
|
|
|
|
hasError = true
|
2018-05-30 17:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 20:53:08 +00:00
|
|
|
if hasError {
|
|
|
|
return fmt.Errorf("errors reported")
|
|
|
|
}
|
|
|
|
return nil
|
2018-05-30 17:28:42 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 20:53:08 +00:00
|
|
|
app.Run(os.Args)
|
|
|
|
}
|