-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
169 lines (143 loc) · 3.64 KB
/
main.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
"sync"
"context"
"crypto/tls"
)
const (
InfoColor = "\033[1;34m%s\033[0m"
NoticeColor = "\033[1;36m%s\033[0m"
WarningColor = "\033[1;33m%s\033[0m"
ErrorColor = "\033[1;31m%s\033[0m"
DebugColor = "\033[0;36m%s\033[0m"
)
type arrayFlags []string
var (
debug_on bool = false
)
func main() {
var headers arrayFlags
filepath := flag.String("i", "urls.txt", "Path to file containing urls to test")
debug := flag.Bool("d", false, "Debug, ex: -d=true")
flag.Var(&headers, "H" ,"Headers ex: -H='Cookie: PHPSESSID=shjhjdgvbhjhvnv'")
flag.Parse()
urls := getUrlsFromFile(string(*filepath))
if bool(*debug){
debug_on = true
}
var wg sync.WaitGroup
ctx := context.Background()
for i:=0;i<len(urls);i++{
wg.Add(1)
go worker(urls[i], headers, ctx, &wg)
}
wg.Wait()
fmt.Println("[+] Done")
}
func worker(url string, headers arrayFlags, ctx context.Context, wg *sync.WaitGroup){
defer wg.Done()
data, err := fetchURL(url ,headers, ctx)
if err != nil{
if debug_on{
fmt.Printf(WarningColor, err.Error()+"\n")
}
}else{
checkPostMessage(data, url)
}
}
func fetchURL(url string, headers arrayFlags, ctx context.Context) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil{
return nil, err
}
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(5 * time.Second))
defer cancel()
req.WithContext(ctx)
for _, header := range headers{
header = strings.ReplaceAll(header, " ", "")
h := strings.Split(header, ":")
req.Header.Add(h[0], h[1])
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := http.DefaultClient
client.Transport = tr
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
resp, err := client.Do(req)
if err != nil{
return nil, err
}
//defer resp.Body.Close()
bytes, _ := ioutil.ReadAll(resp.Body)
return bytes, nil
}
func checkPostMessage(bytes []byte, url string){
fmt.Printf("[*] Checking %s\n", url)
body := string(bytes)
lbody := strings.ToLower(body)
abody := strings.Split(lbody, "\n")
for i, line := range abody{
if strings.Contains(line, "addeventlistener(\"message"){
fmt.Println(url)
fmt.Printf("%d: postMessage event listener detected!\n", i+1)
out := strings.Trim(line, " ")
fmt.Printf(ErrorColor, out+"\n")
}
if strings.Contains(line, "addeventlistener('message"){
fmt.Println(url)
fmt.Printf("%d: postMessage event listener detected!\n", i+1)
out := strings.Trim(line, " ")
fmt.Printf(ErrorColor, out+"\n")
}
if strings.Contains(line, "window.attachevent(\"message"){
fmt.Println(url)
fmt.Printf("%d: postMessage event listener detected!\n", i+1)
out := strings.Trim(line, " ")
fmt.Printf(ErrorColor, out+"\n")
}
if strings.Contains(line, "window.attachevent('message"){
fmt.Println(url)
fmt.Printf("%d: postMessage event listener detected!\n", i+1)
out := strings.Trim(line, " ")
fmt.Printf(ErrorColor, out+"\n")
}
if strings.Contains(line, "onmessage"){
fmt.Println(url)
fmt.Printf("%d: postMessage function detected!\n", i+1)
out := strings.Trim(line, " ")
fmt.Printf(ErrorColor, out+"\n")
}
}
}
func getUrlsFromFile(path string) []string {
var urls []string
file, err := os.Open(path)
if err != nil{
log.Fatalln(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan(){
urls = append(urls, scanner.Text())
}
return urls
}
func (i *arrayFlags) String() string {
return ""
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}