Skip to content

Commit f91aba2

Browse files
authored
Merge pull request #75 from edoardottt/devel
Devel
2 parents 664e5a0 + 398fd86 commit f91aba2

12 files changed

Lines changed: 268 additions & 74 deletions

File tree

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ linters-settings:
5151
# Values always ignored: "1", "1.0", "0" and "0.0"
5252
# Default: []
5353
ignored-numbers:
54-
- '2'
54+
- '2'
55+
ignored-files:
56+
- 'utils/http.go'

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ usage: scilla subcommand { options }
128128
[-plain Print only results]
129129
[-db -no-check Don't check status codes for subdomains]
130130
[-db -vt Use VirusTotal as subdomains source]
131+
[-ua Set the User Agent]
132+
[-rua Generate a random user agent for each request]
131133
-target <target (URL)> REQUIRED
132134
- dir [-w wordlist]
133135
[-oj JSON output file]
@@ -137,6 +139,8 @@ usage: scilla subcommand { options }
137139
[-c use also a web crawler]
138140
[-plain Print only results]
139141
[-nr No follow redirects]
142+
[-ua Set the User Agent]
143+
[-rua Generate a random user agent for each request]
140144
-target <target (URL)> REQUIRED
141145
- report [-p <start-end> or ports divided by comma]
142146
[-ws subdomains wordlist]
@@ -152,6 +156,8 @@ usage: scilla subcommand { options }
152156
[-common scan common ports]
153157
[-nr No follow redirects]
154158
[-db -vt Use VirusTotal as subdomains source]
159+
[-ua Set the User Agent]
160+
[-rua Generate a random user agent for each request]
155161
-target <target (URL/IP)> REQUIRED
156162
- help
157163
- examples
@@ -183,6 +189,8 @@ Examples 💡
183189
- `scilla subdomain -plain -target target.domain`
184190
- `scilla subdomain -db -no-check -target target.domain`
185191
- `scilla subdomain -db -vt -target target.domain`
192+
- `scilla subdomain -ua "CustomUA" -target target.domain`
193+
- `scilla subdomain -rua -target target.domain`
186194

187195
- Directories enumeration:
188196

@@ -196,6 +204,8 @@ Examples 💡
196204
- `scilla dir -c -target target.domain`
197205
- `scilla dir -plain -target target.domain`
198206
- `scilla dir -nr -target target.domain`
207+
- `scilla dir -ua "CustomUA" -target target.domain`
208+
- `scilla dir -rua -target target.domain`
199209

200210
- Ports enumeration:
201211

@@ -234,6 +244,8 @@ Examples 💡
234244
- Specifying common ports `scilla report -common -target target.domain`
235245
- No follow redirects `scilla report -nr -target target.domain`
236246
- Use VirusTotal as subdomains source `scilla report -db -vt -target target.domain`
247+
- Set the User Agent `scilla report -ua "CustomUA" -target target.domain`
248+
- Generate a random user agent for each request `scilla report -rua -target target.domain`
237249

238250
Changelog 📌
239251
-------

crawler/colly.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/edoardottt/scilla/output"
3939
"github.com/edoardottt/scilla/utils"
4040
"github.com/gocolly/colly"
41+
"github.com/gocolly/colly/extensions"
4142
)
4243

4344
const (
@@ -49,7 +50,7 @@ const (
4950
// - only http, https or ftp protocols allowed.
5051
func SpawnCrawler(target string, scheme string, ignore []string, dirs map[string]output.Asset,
5152
subs map[string]output.Asset, outputFileJSON, outputFileHTML, outputFileTXT string,
52-
mutex *sync.Mutex, what string, plain bool) {
53+
mutex *sync.Mutex, what string, plain bool, ua string, rua bool) {
5354
ignoreBool := len(ignore) != 0
5455
//nolint:staticcheck // SA4006 ignore this!
5556
collector := colly.NewCollector()
@@ -71,6 +72,18 @@ func SpawnCrawler(target string, scheme string, ignore []string, dirs map[string
7172
collector.IgnoreRobotsTxt = true
7273
collector.AllowURLRevisit = false
7374

75+
if ua != "Go http/Client" {
76+
collector.UserAgent = ua
77+
} else {
78+
// Avoid using the default colly user agent
79+
collector.UserAgent = utils.GenerateRandomUserAgent()
80+
}
81+
82+
// Use a Random User Agent for each request if needed
83+
if rua {
84+
extensions.RandomUserAgent(collector)
85+
}
86+
7487
// Find and visit all links
7588
collector.OnHTML("a[href]", func(element *colly.HTMLElement) {
7689
link := element.Attr("href")

enumeration/dirs.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
// AsyncDir performs concurrent requests to the specified
4141
// urls and prints the results.
4242
func AsyncDir(urls []string, ignore []string, outputFileJSON, outputFileHTML, outputFileTXT string,
43-
dirs map[string]output.Asset, mutex *sync.Mutex, plain bool, redirect bool) {
43+
dirs map[string]output.Asset, mutex *sync.Mutex, plain bool, redirect bool, ua string, rua bool) {
4444
ignoreBool := len(ignore) != 0
4545
total := len(urls)
4646
client := http.Client{}
@@ -86,7 +86,23 @@ func AsyncDir(urls []string, ignore []string, outputFileJSON, outputFileHTML, ou
8686
defer waitgroup.Done()
8787
defer func() { <-limiter }()
8888

89-
resp, err := client.Get(domain)
89+
req, err := http.NewRequest("GET", domain, nil)
90+
if err != nil {
91+
return
92+
}
93+
94+
if ua != "Go http/Client" {
95+
req.Header.Set("User-Agent", ua)
96+
}
97+
98+
if rua {
99+
req.Header.Set("User-Agent", utils.GenerateRandomUserAgent())
100+
}
101+
102+
resp, err := client.Do(req)
103+
if err != nil {
104+
return
105+
}
90106

91107
count++
92108

enumeration/subs.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
// AsyncGet performs concurrent requests to the specified
4141
// urls and prints the results.
4242
func AsyncGet(protocol string, urls []string, ignore []string, outputFileJSON, outputFileHTML, outputFileTXT string,
43-
subs map[string]output.Asset, mutex *sync.Mutex, plain bool) {
43+
subs map[string]output.Asset, mutex *sync.Mutex, plain bool, ua string, rua bool) {
4444
ignoreBool := len(ignore) != 0
4545

4646
var count int
@@ -77,7 +77,23 @@ func AsyncGet(protocol string, urls []string, ignore []string, outputFileJSON, o
7777
defer waitgroup.Done()
7878
defer func() { <-limiter }()
7979

80-
resp, err := client.Get(protocol + "://" + domain)
80+
req, err := http.NewRequest("GET", protocol+"://"+domain, nil)
81+
if err != nil {
82+
return
83+
}
84+
85+
if ua != "Go http/Client" {
86+
req.Header.Set("User-Agent", ua)
87+
}
88+
89+
if rua {
90+
req.Header.Set("User-Agent", utils.GenerateRandomUserAgent())
91+
}
92+
93+
resp, err := client.Do(req)
94+
if err != nil {
95+
return
96+
}
8197

8298
count++
8399

input/check.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func ReportSubcommandCheckFlags(reportCommand flag.FlagSet, reportTargetPtr *str
4242
reportPortsPtr *string, reportCommonPtr *bool, reportVirusTotalPtr *bool, reportSubdomainDBPtr *bool,
4343
startPort int, endPort int, reportIgnoreDirPtr *string,
4444
reportIgnoreSubPtr *string, reportTimeoutPort *int,
45-
reportOutputJSON *string, reportOutputHTML *string, reportOutputTXT *string) (int, int,
46-
[]int, bool, []string, []string) {
45+
reportOutputJSON, reportOutputHTML, reportOutputTXT, reportUserAgentPtr *string,
46+
reportRandomUserAgentPtr *bool) (int, int, []int, bool, []string, []string) {
4747
// Required Flags
4848
if *reportTargetPtr == "" {
4949
reportCommand.PrintDefaults()
@@ -142,6 +142,11 @@ func ReportSubcommandCheckFlags(reportCommand flag.FlagSet, reportTargetPtr *str
142142
os.Exit(1)
143143
}
144144

145+
if *reportUserAgentPtr != DefaultUserAgent && *reportRandomUserAgentPtr {
146+
fmt.Println("You cannot specify both ua and rua.")
147+
os.Exit(1)
148+
}
149+
145150
return startPort, endPort, portsArray, portArrayBool, reportIgnoreDir, reportIgnoreSub
146151
}
147152

@@ -189,7 +194,8 @@ func DNSSubcommandCheckFlags(dnsCommand flag.FlagSet, dnsTargetPtr, dnsOutputJSO
189194
func SubdomainSubcommandCheckFlags(subdomainCommand flag.FlagSet, subdomainTargetPtr *string,
190195
subdomainNoCheckPtr *bool, subdomainDBPtr *bool, subdomainWordlistPtr *string,
191196
subdomainIgnorePtr *string, subdomainCrawlerPtr *bool, subdomainVirusTotalPtr *bool,
192-
subdomainOutputJSON, subdomainOutputHTML, subdomainOutputTXT *string) []string {
197+
subdomainOutputJSON, subdomainOutputHTML, subdomainOutputTXT, subdomainUserAgentPtr *string,
198+
subdomainRandomUserAgentPtr *bool) []string {
193199
// Required Flags
194200
if *subdomainTargetPtr == "" {
195201
subdomainCommand.PrintDefaults()
@@ -258,6 +264,11 @@ func SubdomainSubcommandCheckFlags(subdomainCommand flag.FlagSet, subdomainTarge
258264
subdomainIgnore = utils.CheckIgnore(toBeIgnored)
259265
}
260266

267+
if *subdomainUserAgentPtr != DefaultUserAgent && *subdomainRandomUserAgentPtr {
268+
fmt.Println("You cannot specify both ua and rua.")
269+
os.Exit(1)
270+
}
271+
261272
return subdomainIgnore
262273
}
263274

@@ -352,7 +363,8 @@ func PortSubcommandCheckFlags(portCommand flag.FlagSet, portTargetPtr *string, p
352363
// DirSubcommandCheckFlags performs all the necessary checks on the flags
353364
// for the dir subcommand.
354365
func DirSubcommandCheckFlags(dirCommand flag.FlagSet, dirTargetPtr *string,
355-
dirIgnorePtr *string, dirOutputJSON, dirOutputHTML, dirOutputTXT *string) []string {
366+
dirIgnorePtr *string, dirOutputJSON, dirOutputHTML, dirOutputTXT, dirUserAgentPtr *string,
367+
dirRandomUserAgentPtr *bool) []string {
356368
// Required Flags
357369
if *dirTargetPtr == "" {
358370
dirCommand.PrintDefaults()
@@ -394,5 +406,10 @@ func DirSubcommandCheckFlags(dirCommand flag.FlagSet, dirTargetPtr *string,
394406
dirIgnore = utils.CheckIgnore(toBeIgnored)
395407
}
396408

409+
if *dirUserAgentPtr != DefaultUserAgent && *dirRandomUserAgentPtr {
410+
fmt.Println("You cannot specify both ua and rua.")
411+
os.Exit(1)
412+
}
413+
397414
return dirIgnore
398415
}

0 commit comments

Comments
 (0)