-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzzer.go
129 lines (120 loc) · 4.43 KB
/
fuzzer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"strings"
)
// Represents a Fuzzer and its state, as reported in the "fuzzer_stats" file
type Fuzzer struct {
afl_banner string
afl_directory string
}
// Creates a fuzzer from the given target path
func CreateFuzzer(target string) Fuzzer {
return Fuzzer{
afl_banner: path.Base(target),
afl_directory: target,
}
}
// Parses the "fuzzer_stats" file present in the given directory, and updates the gauges of the Fuzzer instance accordingly
func (f *Fuzzer) ParseStatsFile() error {
// Open file and read it
path := fmt.Sprintf("%s%cfuzzer_stats", f.afl_directory, os.PathSeparator)
fileBytes, fileReadErr := ioutil.ReadFile(path)
if fileReadErr != nil {
return fileReadErr
}
// Split file contents into lines
fileLines := strings.Split(string(fileBytes), "\n")
for _, l := range fileLines {
// Skip unparseable files
if !strings.Contains(l, ":") {
continue
}
// Convert line to key and value
parts := strings.SplitN(l, ":", 2)
key := strings.TrimSpace(parts[0])
val := strings.TrimSpace(parts[1])
switch key {
case "fuzzer_pid":
convVal, _ := strconv.ParseInt(val, 10, 64)
fuzzer_pid.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "cycles_done":
convVal, _ := strconv.ParseInt(val, 10, 64)
cycles_done.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "execs_done":
convVal, _ := strconv.ParseInt(val, 10, 64)
execs_done.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "execs_per_sec":
convVal, _ := strconv.ParseInt(val, 10, 64)
execs_per_sec.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "paths_total":
convVal, _ := strconv.ParseInt(val, 10, 64)
paths_total.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "paths_favored":
convVal, _ := strconv.ParseInt(val, 10, 64)
paths_favored.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "paths_found":
convVal, _ := strconv.ParseInt(val, 10, 64)
paths_found.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "paths_imported":
convVal, _ := strconv.ParseInt(val, 10, 64)
paths_imported.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "max_depth":
convVal, _ := strconv.ParseInt(val, 10, 64)
max_depth.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "cur_path":
convVal, _ := strconv.ParseInt(val, 10, 64)
cur_path.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "pending_favs":
convVal, _ := strconv.ParseInt(val, 10, 64)
pending_favs.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "pending_total":
convVal, _ := strconv.ParseInt(val, 10, 64)
pending_total.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "variable_paths":
convVal, _ := strconv.ParseInt(val, 10, 64)
variable_paths.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "stability":
val = strings.Replace(val, "%", "", 1)
convVal, _ := strconv.ParseFloat(val, 64)
stability.WithLabelValues(f.afl_banner).Set(convVal)
case "bitmap_cvg":
val = strings.Replace(val, "%", "", 1)
convVal, _ := strconv.ParseFloat(val, 64)
bitmap_cvg.WithLabelValues(f.afl_banner).Set(convVal)
case "unique_crashes":
convVal, _ := strconv.ParseInt(val, 10, 64)
unique_crashes.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "unique_hangs":
convVal, _ := strconv.ParseInt(val, 10, 64)
unique_hangs.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "last_path":
convVal, _ := strconv.ParseInt(val, 10, 64)
last_path.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "last_crash":
convVal, _ := strconv.ParseInt(val, 10, 64)
last_crash.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "last_hang":
convVal, _ := strconv.ParseInt(val, 10, 64)
last_hang.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "execs_since_crash":
convVal, _ := strconv.ParseInt(val, 10, 64)
execs_since_crash.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "exec_timeout":
convVal, _ := strconv.ParseInt(val, 10, 64)
exec_timeout.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "slowest_exec_ms":
convVal, _ := strconv.ParseInt(val, 10, 64)
slowest_exec_ms.WithLabelValues(f.afl_banner).Set(float64(convVal))
case "peak_rss_mb":
convVal, _ := strconv.ParseInt(val, 10, 64)
peak_rss_mb.WithLabelValues(f.afl_banner).Set(float64(convVal))
}
}
// [+] Done parsing. Have a nice day.
return nil
}