Skip to content

Commit 0527d2e

Browse files
committed
add ratelimit option #251
1 parent 25376d2 commit 0527d2e

File tree

7 files changed

+39
-1
lines changed

7 files changed

+39
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ CONFIGURATIONS:
7171
-hash string[] Filter results having these favicon hashes (comma separated)
7272
-c, -concurrency int Concurrency level (default 50)
7373
-t, -timeout int Connection timeout in seconds (default 10)
74+
-rl, -rate-limit int Set a rate limit (per second)
7475

7576
OUTPUT:
7677
-o, -output string File to write output results

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111

1212
require (
1313
github.com/andybalholm/brotli v1.0.6 // indirect
14+
github.com/benbjohnson/clock v1.3.0 // indirect
1415
github.com/davecgh/go-spew v1.1.1 // indirect
1516
github.com/klauspost/compress v1.16.7 // indirect
1617
github.com/klauspost/pgzip v1.2.5 // indirect
@@ -45,6 +46,7 @@ require (
4546
github.com/twmb/murmur3 v1.1.8
4647
github.com/ulikunitz/xz v0.5.11 // indirect
4748
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
49+
go.uber.org/ratelimit v0.3.0
4850
golang.org/x/net v0.17.0 // indirect
4951
gopkg.in/djherbis/times.v1 v1.3.0 // indirect
5052
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3d
55
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
66
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
77
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
8+
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
9+
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
810
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08 h1:ox2F0PSMlrAAiAdknSRMDrAr8mfxPCfSZolH+/qQnyQ=
911
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08/go.mod h1:pCxVEbcm3AMg7ejXyorUXi6HQCzOIBf7zEDVPtw0/U4=
1012
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -77,6 +79,8 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
7779
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
7880
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
7981
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
82+
go.uber.org/ratelimit v0.3.0 h1:IdZd9wqvFXnvLvSEBo0KPcGfkoBGNkpTHlrE3Rcjkjw=
83+
go.uber.org/ratelimit v0.3.0/go.mod h1:So5LG7CV1zWpY1sHe+DXTJqQvOx+FFPFaAs2SnoyBaI=
8084
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
8185
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
8286
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=

pkg/favirecon/favirecon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ func pushInput(r *Runner) {
129129
func execute(r *Runner) {
130130
defer r.InWg.Done()
131131

132+
rl := rateLimiter(r)
133+
132134
for i := 0; i < r.Options.Concurrency; i++ {
133135
r.InWg.Add(1)
134136

@@ -145,6 +147,8 @@ func execute(r *Runner) {
145147
return
146148
}
147149

150+
rl.Take()
151+
148152
client := customClient(r.Options.Timeout)
149153

150154
result, err := getFavicon(targetURL, r.UserAgent, client)

pkg/favirecon/ratelimit.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
favirecon - Use favicon.ico to improve your target recon phase. Quickly detect technologies, WAF, exposed panels, known services.
3+
4+
This repository is under MIT License https://github.com/edoardottt/favirecon/blob/main/LICENSE
5+
*/
6+
7+
package favirecon
8+
9+
import "go.uber.org/ratelimit"
10+
11+
func rateLimiter(r *Runner) ratelimit.Limiter {
12+
var ratelimiter ratelimit.Limiter
13+
if r.Options.RateLimit > 0 {
14+
ratelimiter = ratelimit.New(r.Options.RateLimit)
15+
} else {
16+
ratelimiter = ratelimit.NewUnlimited()
17+
}
18+
19+
return ratelimiter
20+
}

pkg/input/check.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ func (options *Options) validateOptions() error {
2929
}
3030

3131
if options.Concurrency <= 0 {
32-
return fmt.Errorf("%w", ErrNegativeValue)
32+
return fmt.Errorf("concurrency: %w", ErrNegativeValue)
33+
}
34+
35+
if options.RateLimit != 0 && options.RateLimit <= 0 {
36+
return fmt.Errorf("rate limit: %w", ErrNegativeValue)
3337
}
3438

3539
return nil

pkg/input/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
const (
2121
DefaultTimeout = 10
2222
DefaultConcurrency = 50
23+
DefaultRateLimit = 0
2324
)
2425

2526
// Options struct specifies how the tool
@@ -35,6 +36,7 @@ type Options struct {
3536
Concurrency int
3637
Timeout int
3738
Cidr bool
39+
RateLimit int
3840
}
3941

4042
// configureOutput configures the output on the screen.
@@ -64,6 +66,7 @@ func ParseOptions() *Options {
6466
flagSet.StringSliceVarP(&options.Hash, "hash", "", nil, `Filter results having these favicon hashes (comma separated)`, goflags.CommaSeparatedStringSliceOptions),
6567
flagSet.IntVarP(&options.Concurrency, "concurrency", "c", DefaultConcurrency, `Concurrency level`),
6668
flagSet.IntVarP(&options.Timeout, "timeout", "t", DefaultTimeout, `Connection timeout in seconds`),
69+
flagSet.IntVarP(&options.RateLimit, "rate-limit", "rl", DefaultRateLimit, `Set a rate limit (per second)`),
6770
)
6871

6972
// Output

0 commit comments

Comments
 (0)