stubbing out more plugins

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2018-06-06 11:21:08 -04:00
parent 0f0ce2af37
commit c02aa0e395
Signed by: vbatts
GPG key ID: 10937E57733F1362
7 changed files with 171 additions and 62 deletions

View file

@ -5,7 +5,7 @@ SOURCE_FILES := \
$(wildcard walker/*.go) \ $(wildcard walker/*.go) \
$(wildcard walker/walkers/*/*.go) $(wildcard walker/walkers/*/*.go)
PLUGINS := \ PLUGINS := \
plugin-readFuzz.so $(patsubst walker/walkers/%,plugin-%.so,$(wildcard walker/walkers/*))
default: fuzz-walker $(PLUGINS) default: fuzz-walker $(PLUGINS)
@ -16,4 +16,4 @@ plugin-%.so:
$(GO) build -o $@ -buildmode=plugin ./walker/walkers/$*/ $(GO) build -o $@ -buildmode=plugin ./walker/walkers/$*/
clean: clean:
rm -f fuzz-walker *.so rm -f fuzz-walker *.so *~

65
main.go
View file

@ -11,13 +11,14 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
var ( // This list is populated in the beforefunc of the application
dirs = []string{"/sys", "/proc"} var walkerPlugins []walker.Fuzzer
fuzzTimeout = 500 * time.Millisecond
walkerPlugins []walker.Fuzzer
)
func appInit(c *cli.Context) error { func main() {
app := cli.NewApp()
app.Name = "fuzz-walker"
app.Usage = "a walker to poke and prod at /proc and /sys"
app.Before = func(c *cli.Context) error {
matches, err := filepath.Glob(c.String("plugins")) matches, err := filepath.Glob(c.String("plugins"))
if err != nil { if err != nil {
return err return err
@ -31,33 +32,47 @@ func appInit(c *cli.Context) error {
} }
return nil return nil
} }
func main() {
app := cli.NewApp()
app.Name = "fuzz-walker"
app.Usage = "a walker to poke and prod at /proc and /sys"
app.Before = appInit
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "plugins", Name: "plugins",
Value: "*.so",
Usage: "pattern to glob walker plugins", Usage: "pattern to glob walker plugins",
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",
},
}, },
} }
app.Action = func(c *cli.Context) error { app.Action = func(c *cli.Context) error {
hasError := false hasError := false
for _, dir := range dirs { for _, dir := range c.StringSlice("paths") {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if !info.Mode().IsRegular() {
return nil
}
for _, wp := range walkerPlugins { for _, wp := range walkerPlugins {
if err := wp.Func(path, info, fuzzTimeout); err != nil { 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) 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())
}
} }
return nil return nil
}) })
@ -74,17 +89,3 @@ func main() {
app.Run(os.Args) app.Run(os.Args)
} }
func writeNumFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
func writeBytesFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
func chmodFuzz(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}
// maybe have an ioctl fuzzer

View file

@ -0,0 +1,23 @@
package main
import (
"os"
"time"
"git.thisco.de/vbatts/fuzz-walker/walker"
)
// NewFuzzer creates the fuzzer for this plugin
func NewFuzzer() (walker.Fuzzer, error) {
return &myFuzzer{}, nil
}
type myFuzzer struct{}
func (mf myFuzzer) Name() string {
return "chmodFuzz"
}
func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error {
return nil
}

View file

@ -0,0 +1,28 @@
package main
import (
"os"
"time"
"git.thisco.de/vbatts/fuzz-walker/walker"
)
// NewFuzzer creates the fuzzer for this plugin
func NewFuzzer() (walker.Fuzzer, error) {
return &myFuzzer{}, nil
}
type myFuzzer struct{}
func (mf myFuzzer) Name() string {
return "ioctlFuzz"
}
func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error {
// check whether it is a device file
//if !info.Mode().IsRegular() {
// return nil
//}
return nil
}

View file

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -10,6 +9,7 @@ import (
"git.thisco.de/vbatts/fuzz-walker/walker" "git.thisco.de/vbatts/fuzz-walker/walker"
) )
// NewFuzzer creates the fuzzer for this plugin
func NewFuzzer() (walker.Fuzzer, error) { func NewFuzzer() (walker.Fuzzer, error) {
return &myFuzzer{}, nil return &myFuzzer{}, nil
} }
@ -21,22 +21,16 @@ func (mf myFuzzer) Name() string {
} }
func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error { func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error {
c1 := make(chan error, 1) if !info.Mode().IsRegular() {
go func() {
fd, err := os.Open(path)
if err != nil {
c1 <- err
}
defer fd.Close()
_, err = io.Copy(ioutil.Discard, fd)
c1 <- err
}()
select {
case err := <-c1:
return err
case <-time.After(timeout):
return fmt.Errorf("timeout reached")
}
return nil return nil
} }
fd, err := os.Open(path)
if err != nil {
return err
}
defer fd.Close()
_, err = io.Copy(ioutil.Discard, fd)
return err
}

View file

@ -0,0 +1,32 @@
package main
import (
"os"
"time"
"git.thisco.de/vbatts/fuzz-walker/walker"
)
// NewFuzzer creates the fuzzer for this plugin
func NewFuzzer() (walker.Fuzzer, error) {
return &myFuzzer{}, nil
}
type myFuzzer struct{}
func (mf myFuzzer) Name() string {
return "writeBytesFuzz"
}
func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error {
if !info.Mode().IsRegular() {
return nil
}
fd, err := os.Open(path)
if err != nil {
return err
}
defer fd.Close()
return nil
}

View file

@ -0,0 +1,31 @@
package main
import (
"os"
"time"
"git.thisco.de/vbatts/fuzz-walker/walker"
)
// NewFuzzer creates the fuzzer for this plugin
func NewFuzzer() (walker.Fuzzer, error) {
return &myFuzzer{}, nil
}
type myFuzzer struct{}
func (mf myFuzzer) Name() string {
return "writeNumFuzz"
}
func (mf myFuzzer) Func(path string, info os.FileInfo, timeout time.Duration) error {
if !info.Mode().IsRegular() {
return nil
}
fd, err := os.Open(path)
if err != nil {
return err
}
defer fd.Close()
return nil
}