forked from xdxdxdxdxd/ffufxxxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
executable file
·66 lines (53 loc) · 1.43 KB
/
time.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
package filter
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"github.com/ffuf/ffuf/v2/pkg/ffuf"
)
type TimeFilter struct {
ms int64 // milliseconds since first response byte
gt bool // filter if response time is greater than
lt bool // filter if response time is less than
valueRaw string
}
func NewTimeFilter(value string) (ffuf.FilterProvider, error) {
var milliseconds int64
gt, lt := false, false
gt = strings.HasPrefix(value, ">")
lt = strings.HasPrefix(value, "<")
if (!lt && !gt) || (lt && gt) {
return &TimeFilter{}, fmt.Errorf("Time filter or matcher (-ft / -mt): invalid value: %s", value)
}
milliseconds, err := strconv.ParseInt(value[1:], 10, 64)
if err != nil {
return &TimeFilter{}, fmt.Errorf("Time filter or matcher (-ft / -mt): invalid value: %s", value)
}
return &TimeFilter{ms: milliseconds, gt: gt, lt: lt, valueRaw: value}, nil
}
func (f *TimeFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Value string `json:"value"`
}{
Value: f.valueRaw,
})
}
func (f *TimeFilter) Filter(response *ffuf.Response) (bool, error) {
if f.gt {
if response.Time.Milliseconds() > f.ms {
return true, nil
}
} else if f.lt {
if response.Time.Milliseconds() < f.ms {
return true, nil
}
}
return false, nil
}
func (f *TimeFilter) Repr() string {
return f.valueRaw
}
func (f *TimeFilter) ReprVerbose() string {
return fmt.Sprintf("Response time: %s", f.Repr())
}