forked from hahwul/dalfox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
99 lines (84 loc) 路 1.9 KB
/
utils.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
package scanning
import (
"bufio"
"os"
"strings"
"github.com/hahwul/dalfox/v2/pkg/model"
)
// a slice of strings, returning the slice and any error
func readLines(filename string) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return []string{}, err
}
defer f.Close()
lines := make([]string, 0)
sc := bufio.NewScanner(f)
for sc.Scan() {
lines = append(lines, sc.Text())
}
return lines, sc.Err()
}
// readLinesOrLiteral tries to read lines from a file, returning
// the arg in a string slice if the file doesn't exist, unless
// the arg matches its default value
func readLinesOrLiteral(arg string) ([]string, error) {
if isFile(arg) {
return readLines(arg)
}
// if the argument isn't a file, but it is the default, don't
// treat it as a literal value
return []string{arg}, nil
}
// isFile returns true if its argument is a regular file
func isFile(path string) bool {
f, err := os.Stat(path)
return err == nil && f.Mode().IsRegular()
}
// unique is ..
func unique(intSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range intSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
func indexOf(element string, data []string) int {
for k, v := range data {
if element == v {
return k
}
}
return -1 //not found.
}
func duplicatedResult(result []model.PoC, rst model.PoC) bool {
for _, v := range result {
if v.Type == rst.Type {
return true
}
}
return false
}
func containsFromArray(slice []string, item string) bool {
set := make(map[string]struct{}, len(slice))
t := strings.Split(item, "(")
i := t[0]
for _, s := range slice {
set[s] = struct{}{}
}
_, ok := set[i]
return ok
}
func checkPType(str string) bool {
if strings.Contains(str, "toBlind") {
return false
}
if strings.Contains(str, "toGrepping") {
return false
}
return true
}