-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (80 loc) · 2.28 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
package main
import (
"flag"
"fmt"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"strconv"
"strings"
"sync"
)
var subdomains = make(map[string]struct{})
var subMu sync.Mutex
var directories = make(map[string]struct{})
var dirMu sync.Mutex
var outFile *os.File
var isAuthorised bool
var auth string
func main() {
domainPtr := flag.String("d", "", "the ip of target")
wordlistPtr := flag.String("w", "", "the wordlist for subdomain enumeration")
customSubdomainsPtr := flag.String("c", "", "the wordlist of subdomains you have found")
outFilePtr := flag.String("o", "", "output file of program")
authPtr := flag.String("a", "", "cooke for auth in the form name:cookie")
flag.Parse()
domain := *domainPtr
wordlist := *wordlistPtr
customSubdomains := *customSubdomainsPtr
outFileName := *outFilePtr
authStr := *authPtr
var wg sync.WaitGroup
if domain == "" {
fmt.Fprintln(os.Stderr, "[x] ERROR: please specify a domain or ip address with -d")
os.Exit(1)
}
jar, err := cookiejar.New(nil)
handleErr(err)
var cookies []*http.Cookie
auth = authStr
if authStr != "" {
isAuthorised = true
domainPath := strings.Split(domain, "/")
path := ""
for i := 3; i < len(domainPath)-1; i++ {
path += "/" + domainPath[i]
}
mainDomain := domainPath[2]
mainDomainArr := strings.Split(mainDomain, ".")
cookieDomain := "." + mainDomainArr[len(mainDomainArr)-2] + "." + mainDomainArr[len(mainDomainArr)-1]
authCookie := &http.Cookie{
Name: strings.Split(authStr, ":")[0],
Value: strings.Split(authStr, ":")[1],
Path: path,
Domain: cookieDomain,
}
cookies = append(cookies, authCookie)
} else {
isAuthorised = false
}
url, _ := url.Parse(domain)
jar.SetCookies(url, cookies)
client := &http.Client{
Jar: jar,
}
outFile = os.Stdout
if outFileName == "" {
fmt.Fprintln(os.Stderr, "[!] No out file specified - output will be set to stdout")
} else {
var err error
outFile, err = os.OpenFile(outFileName, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
handleErr(err)
}
compileSubdomains(domain, wordlist, customSubdomains)
fmt.Fprintln(os.Stderr, "[.] found "+strconv.Itoa(len(subdomains))+" subdomains! Launching workers...")
for subdomain := range subdomains {
recursivelyAttackDirectory(subdomain, domain, subdomain, client, &wg)
}
wg.Wait()
}