stubbing out more plugins
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
0f0ce2af37
commit
c02aa0e395
7 changed files with 171 additions and 62 deletions
4
Makefile
4
Makefile
|
@ -5,7 +5,7 @@ SOURCE_FILES := \
|
|||
$(wildcard walker/*.go) \
|
||||
$(wildcard walker/walkers/*/*.go)
|
||||
PLUGINS := \
|
||||
plugin-readFuzz.so
|
||||
$(patsubst walker/walkers/%,plugin-%.so,$(wildcard walker/walkers/*))
|
||||
|
||||
default: fuzz-walker $(PLUGINS)
|
||||
|
||||
|
@ -16,4 +16,4 @@ plugin-%.so:
|
|||
$(GO) build -o $@ -buildmode=plugin ./walker/walkers/$*/
|
||||
|
||||
clean:
|
||||
rm -f fuzz-walker *.so
|
||||
rm -f fuzz-walker *.so *~
|
||||
|
|
65
main.go
65
main.go
|
@ -11,13 +11,14 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
dirs = []string{"/sys", "/proc"}
|
||||
fuzzTimeout = 500 * time.Millisecond
|
||||
walkerPlugins []walker.Fuzzer
|
||||
)
|
||||
// This list is populated in the beforefunc of the application
|
||||
var 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"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -31,33 +32,47 @@ func appInit(c *cli.Context) error {
|
|||
}
|
||||
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{
|
||||
cli.StringFlag{
|
||||
Name: "plugins",
|
||||
Value: "*.so",
|
||||
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 {
|
||||
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 {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
case <-time.After(c.Duration("timeout") * time.Millisecond):
|
||||
logrus.Warnf("%s: %q fuzz timed out", path, wp.Name())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@ -74,17 +89,3 @@ func main() {
|
|||
|
||||
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
|
||||
|
|
23
walker/walkers/chmodFuzz/plugin.go
Normal file
23
walker/walkers/chmodFuzz/plugin.go
Normal 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
|
||||
}
|
28
walker/walkers/ioctlFuzz/plugin.go
Normal file
28
walker/walkers/ioctlFuzz/plugin.go
Normal 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
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -10,6 +9,7 @@ import (
|
|||
"git.thisco.de/vbatts/fuzz-walker/walker"
|
||||
)
|
||||
|
||||
// NewFuzzer creates the fuzzer for this plugin
|
||||
func NewFuzzer() (walker.Fuzzer, error) {
|
||||
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 {
|
||||
c1 := make(chan error, 1)
|
||||
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")
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
_, err = io.Copy(ioutil.Discard, fd)
|
||||
return err
|
||||
}
|
32
walker/walkers/writeBytesFuzz/plugin.go
Normal file
32
walker/walkers/writeBytesFuzz/plugin.go
Normal 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
|
||||
}
|
31
walker/walkers/writeNumFuzz/plugin.go
Normal file
31
walker/walkers/writeNumFuzz/plugin.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue