/
subs.go
120 lines (89 loc) · 2.92 KB
/
subs.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
/*
=======================
Scilla - Information Gathering Tool
=======================
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
@Repository: https://github.com/edoardottt/scilla
@Author: edoardottt, https://www.edoardoottavianelli.it
@License: https://github.com/edoardottt/scilla/blob/main/LICENSE
*/
package enumeration
import (
"fmt"
"net/http"
"os"
"sync"
"github.com/edoardottt/scilla/output"
"github.com/edoardottt/scilla/utils"
)
// AsyncGet performs concurrent requests to the specified
// urls and prints the results.
func AsyncGet(protocol string, urls []string, ignore []string, outputFileJSON, outputFileHTML, outputFileTXT string,
subs map[string]output.Asset, mutex *sync.Mutex, plain bool, ua string, rua bool) {
ignoreBool := len(ignore) != 0
var count int
var total = len(urls)
client := http.Client{
Timeout: utils.Seconds10,
}
channels := 10
limiter := make(chan string, channels) // Limits simultaneous requests
waitgroup := sync.WaitGroup{} // Needed to not prematurely exit before all requests have been finished
for _, domain := range urls {
limiter <- domain
waitgroup.Add(1)
if count%50 == 0 { // update counter
if !plain {
fmt.Fprint(os.Stdout, "\r \r")
}
output.PrintSubs(subs, ignore, outputFileJSON, outputFileHTML, outputFileTXT, mutex, plain)
}
if !plain && count%100 == 0 { // update counter
fmt.Fprint(os.Stdout, "\r \r")
fmt.Printf("%0.2f%% : %d / %d", utils.Percentage(count, total), count, total)
}
go func(domain string) {
defer waitgroup.Done()
defer func() { <-limiter }()
req, err := http.NewRequest("GET", protocol+"://"+domain, nil)
if err != nil {
return
}
if ua != "Go http/Client" {
req.Header.Set("User-Agent", ua)
}
if rua {
req.Header.Set("User-Agent", utils.GenerateRandomUserAgent())
}
resp, err := client.Do(req)
if err != nil {
return
}
count++
if err != nil {
return
}
if ignoreBool {
if utils.IgnoreResponse(resp.StatusCode, ignore) {
return
}
}
output.AddSubs(domain, resp.Status, subs, mutex)
resp.Body.Close()
}(domain)
}
output.PrintSubs(subs, ignore, outputFileJSON, outputFileHTML, outputFileTXT, mutex, plain)
waitgroup.Wait()
output.PrintSubs(subs, ignore, outputFileJSON, outputFileHTML, outputFileTXT, mutex, plain)
fmt.Fprint(os.Stdout, "\r \r")
fmt.Println()
}