-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffuf.go
94 lines (76 loc) · 1.94 KB
/
ffuf.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
package gocdp
import (
"encoding/json"
"github.com/iancoleman/orderedmap"
)
type ffufOutput struct {
CommandLine string `json:"commandline"`
Time string `json:"time"`
Results []ffufResult `json:"results"`
Config interface{} `json:"config"`
}
type ffufResult struct {
URL string `json:"url"`
Status int `json:"status"`
Redirect string `json:"redirectlocation"`
ContentType string `json:"content-type"`
ContentLength int `json:"length"`
raw interface{}
}
type _ffufResult ffufResult
func (f *ffufResult) UnmarshalJSON(bytes []byte) (err error) {
foo := _ffufResult{}
if err = json.Unmarshal(bytes, &foo); err == nil {
*f = ffufResult(foo)
}
m := orderedmap.New()
if err = json.Unmarshal(bytes, &m); err == nil {
f.raw = m
}
return err
}
type FfufParser struct {
}
func (parser FfufParser) Parse(input string) (CDResults, error) {
var output ffufOutput
err := json.Unmarshal([]byte(input), &output)
if err != nil {
return nil, err
}
var results CDResults
for _, result := range output.Results {
results = append(results, CDResult{
Url: result.URL,
Status: result.Status,
Redirect: result.Redirect,
ContentType: result.ContentType,
ContentLength: result.ContentLength,
source: result.raw,
})
}
return results, nil
}
func (parser FfufParser) CanParse(input string) bool {
var output ffufOutput
err := json.Unmarshal([]byte(input), &output)
if err != nil {
return false
}
return output.CommandLine != ""
}
func (parser FfufParser) CanTransform() bool {
return true
}
func (p FfufParser) Transform(input string, filtered []interface{}) (string, error) {
output := orderedmap.New()
err := json.Unmarshal([]byte(input), output)
if err != nil {
return "", err
}
output.Set("results", filtered)
bytes, err := json.MarshalIndent(output, "", " ")
if err != nil {
return "", err
}
return string(bytes), nil
}