forked from awsassets/openredirectXD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
130 lines (114 loc) · 2.6 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
package main
import (
"bufio"
"crypto/tls"
"flag"
"fmt"
"net"
"net/http"
"net/url"
"os"
"sync"
"time"
)
//var proxyURL, _ = url.Parse("http://127.0.0.1:8080")
var transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: time.Second,
DualStack: true,
}).DialContext,
//Proxy: http.ProxyURL(proxyURL),
}
var httpClient = &http.Client{
Transport: transport,
}
func main() {
var payload string
flag.StringVar(&payload, "p", "none", "Specify payload to use")
var threads int
flag.IntVar(&threads, "t", 20, "Specify number of threads to run")
flag.Parse()
if payload != "none" {
if !isValidUrl(payload) {
fmt.Println("Invalid payload: Example: https://google.com")
return
}
}
var wg sync.WaitGroup
urls := make(chan string)
for i := 0; i < threads; i++ {
wg.Add(1)
go workers(urls, &wg, payload)
}
input := bufio.NewScanner(os.Stdin)
for input.Scan() {
parsed, err := url.Parse(input.Text())
if err != nil {
continue
}
if len(parsed.Query()) == 0 {
continue
}
urls <- input.Text()
}
close(urls)
wg.Wait()
}
func checkredirect(s, payload string) {
if payload != "none" {
parsed, _ := url.Parse(payload)
resp, err := httpClient.Get(changeparams(s, payload))
if err != nil {
return
}
defer resp.Body.Close()
final := resp.Request.URL.String()
redirectparse, _ := url.Parse(final)
if redirectparse.Host == parsed.Host {
fmt.Println(s, "is vulnerable to open redirect")
return
}
} else {
resp, err := httpClient.Get(changeparams(s, "http://evil.com"))
if err != nil {
return
}
defer resp.Body.Close()
final := resp.Request.URL.String()
redirectparse, _ := url.Parse(final)
if redirectparse.Host == "evil.com" {
fmt.Println(s, "is vulnerable to open redirect")
return
}
}
}
func changeparams(s, value string) string {
parsed, err := url.Parse(s)
if err != nil {
return ""
}
values := url.Values{}
for a := range parsed.Query() {
values.Add(a, value)
}
return parsed.Scheme + "://" + parsed.Host + parsed.Path + "?" + values.Encode()
}
func workers(cha chan string, wg *sync.WaitGroup, payload string) {
for i := range cha {
checkredirect(i, payload)
}
wg.Done()
}
func isValidUrl(toTest string) bool {
_, err := url.ParseRequestURI(toTest)
if err != nil {
return false
}
u, err := url.Parse(toTest)
if err != nil || u.Scheme == "" || u.Host == "" {
return false
}
return true
}