-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
util.go
88 lines (73 loc) · 1.33 KB
/
util.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
package main
import (
"bufio"
"errors"
"net/http"
"net/url"
"os"
"strings"
)
func isStdin() bool {
f, e := os.Stdin.Stat()
if e != nil {
return false
}
if f.Mode()&os.ModeNamedPipe == 0 {
return false
}
return true
}
func isURL(s string) bool {
_, e := url.ParseRequestURI(s)
if e != nil {
return false
}
u, e := url.Parse(s)
if e != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}
func isVuln(r *http.Response) bool {
if r.StatusCode != http.StatusInternalServerError {
return false
}
for key, header := range r.Header {
if key == "X-CalculatedBETarget" {
for _, h := range header {
if strings.Contains(h, "localhost") {
return true
}
}
}
}
return false
}
func readList(p string) ([]string, error) {
keys := make(map[string]bool)
if isStdin() {
scanner = bufio.NewScanner(os.Stdin)
} else if p != "" {
file, err := os.Open(p)
if err != nil {
return nil, err
}
defer file.Close()
scanner = bufio.NewScanner(file)
} else {
return target, errors.New("no target provided")
}
for scanner.Scan() {
URL := scanner.Text()
if _, value := keys[URL]; !value {
if isURL(URL) {
keys[URL] = true
target = append(target, URL)
}
}
}
if len(target) < 1 {
return target, errors.New("no valid target URLs")
}
return target, scanner.Err()
}