-
Notifications
You must be signed in to change notification settings - Fork 200
/
subover.go
221 lines (188 loc) · 5.93 KB
/
subover.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// SubOver is a tool for discovering subdomain takeovers
package main
import (
"bufio"
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"github.com/parnurzeal/gorequest"
"io/ioutil"
"log"
"net"
"os"
"strings"
"sync"
"time"
)
// Structure for each provider stored in providers.json file
type ProviderData struct {
Name string `json:"name"`
Cname []string `json:"cname"`
Response []string `json:"response"`
}
var Providers []ProviderData
var Targets []string
var (
HostsList string
Threads int
All bool
Verbose bool
ForceHTTPS bool
Timeout int
OutputFile string
)
func InitializeProviders() {
raw, err := ioutil.ReadFile("providers.json")
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
err = json.Unmarshal(raw, &Providers)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
}
func ReadFile(file string) (lines []string, err error) {
fileHandle, err := os.Open(file)
if err != nil {
return lines, err
}
defer fileHandle.Close()
fileScanner := bufio.NewScanner(fileHandle)
for fileScanner.Scan() {
lines = append(lines, fileScanner.Text())
}
return lines, nil
}
func Get(url string, timeout int, https bool) (resp gorequest.Response, body string, errs []error) {
if https == true {
url = fmt.Sprintf("https://%s/", url)
} else {
url = fmt.Sprintf("http://%s/", url)
}
resp, body, errs = gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
Timeout(time.Duration(timeout)*time.Second).Get(url).
Set("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0").
End()
return resp, body, errs
}
func ParseArguments() {
flag.IntVar(&Threads, "t", 20, "Number of threads to use")
flag.StringVar(&HostsList, "l", "", "List of hosts to check takeovers on")
flag.BoolVar(&All, "a", false, "Check all hosts regardless of CNAME")
flag.BoolVar(&Verbose, "v", false, "Show verbose output")
flag.BoolVar(&ForceHTTPS, "https", false, "Force HTTPS connections (Default: http://)")
flag.IntVar(&Timeout, "timeout", 10, "Seconds to wait before timeout")
flag.StringVar(&OutputFile, "o", "", "File to write enumeration output to")
flag.Parse()
}
func CNAMEExists(key string) bool {
for _, provider := range Providers {
for _, cname := range provider.Cname {
if strings.Contains(key, cname) {
return true
}
}
}
return false
}
func Check(target string, TargetCNAME string) {
_, body, errs := Get(target, Timeout, ForceHTTPS)
if len(errs) <= 0 {
if TargetCNAME == "ALL" {
for _, provider := range Providers {
for _, response := range provider.Response {
if strings.Contains(body, response) == true {
fmt.Printf("\n[\033[31;1;4m%s\033[0m] Takeover Possible At %s ", provider.Name, target)
return
}
}
}
} else {
// This is a less false positives way
for _, provider := range Providers {
for _, cname := range provider.Cname {
if strings.Contains(TargetCNAME, cname) {
for _, response := range provider.Response {
if strings.Contains(body, response) == true {
if provider.Name == "cloudfront" {
_, body2, _ := Get(target, 120, true)
if strings.Contains(body2, response) == true {
fmt.Printf("\n[\033[31;1;4m%s\033[0m] Takeover Possible At : %s", provider.Name, target)
}
} else {
fmt.Printf("\n[\033[31;1;4m%s\033[0m] Takeover Possible At %s with CNAME %s", provider.Name, target, TargetCNAME)
}
}
return
}
}
}
}
}
} else {
if Verbose == true {
log.Printf("[ERROR] Get: %s => %v", target, errs)
}
}
return
}
func Checker(target string) {
TargetCNAME, err := net.LookupCNAME(target)
if err != nil {
return
} else {
if All != true && CNAMEExists(TargetCNAME) == true {
if Verbose == true {
log.Printf("[SELECTED] %s => %s", target, TargetCNAME)
}
Check(target, TargetCNAME)
} else if All == true {
if Verbose == true {
log.Printf("[ALL] %s ", target)
}
Check(target, "ALL")
}
}
}
func main() {
ParseArguments()
fmt.Println("")
fmt.Println("SubOver v.1.2 Nizamul Rana (@Ice3man)")
fmt.Println("==================================================\n")
if HostsList == "" {
fmt.Printf("SubOver: No hosts list specified for testing!")
fmt.Printf("\nUse -h for usage options\n")
os.Exit(1)
}
InitializeProviders()
Hosts, err := ReadFile(HostsList)
if err != nil {
fmt.Printf("\nread: %s\n", err)
os.Exit(1)
}
Targets = append(Targets, Hosts...)
hosts := make(chan string, Threads)
processGroup := new(sync.WaitGroup)
processGroup.Add(Threads)
for i := 0; i < Threads; i++ {
go func() {
for {
host := <-hosts
if host == "" {
break
}
Checker(host)
}
processGroup.Done()
}()
}
for _, Host := range Targets {
hosts <- Host
}
close(hosts)
processGroup.Wait()
fmt.Printf("\n[~] Enjoy your hunt !\n")
}