-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (75 loc) · 1.98 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
package main
import (
"flag"
"fmt"
"net/http"
"sync"
)
func sendRequest(client *http.Client, req *http.Request) (*http.Response, error) {
return client.Do(req)
}
func newRequest(method, url, host, xHost, xForwardedHost string) (*http.Request, error) {
req, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, err
}
req.Host = host
if xHost != "" {
req.Header.Set("X-Host", xHost)
}
if xForwardedHost != "" {
req.Header.Set("X-Forwarded-Host", xForwardedHost)
}
return req, nil
}
func handleRedirects(client *http.Client, url, initialHost string) {
attempts := []struct {
host string
xHost string
xForwardedHost string
}{
{host: initialHost},
{host: initialHost, xHost: "google.com"},
{host: initialHost, xHost: "google.com", xForwardedHost: "google.com"},
}
var wg sync.WaitGroup
for i, attempt := range attempts {
wg.Add(1)
go func(i int, attempt struct {
host string
xHost string
xForwardedHost string
}) {
defer wg.Done()
req, err := newRequest("GET", url, attempt.host, attempt.xHost, attempt.xForwardedHost)
if err != nil {
fmt.Printf("Attempt %d: Error creating request: %v\n", i+1, err)
return
}
resp, err := sendRequest(client, req)
if err != nil {
fmt.Printf("Attempt %d: Error sending request: %v\n", i+1, err)
return
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusFound {
location := resp.Header.Get("Location")
fmt.Printf("Attempt %d: Redirected to: %s\n", i+1, location)
} else {
fmt.Printf("Attempt %d: Status code: %d\n", i+1, resp.StatusCode)
}
}(i, attempt)
}
wg.Wait()
}
func main() {
url := flag.String("url", "http://www.vulnerable.com", "URL to test")
initialHost := flag.String("host", "google.com", "Initial host")
flag.Parse()
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
handleRedirects(client, *url, *initialHost)
}