@@ -7,11 +7,11 @@ import (
77 "os"
88 "path/filepath"
99 "strings"
10+ "sync"
1011 "time"
1112
1213 "github.com/projectdiscovery/gologger"
1314 "github.com/projectdiscovery/naabu/pkg/scan"
14- "github.com/remeh/sizedwaitgroup"
1515)
1616
1717// Runner is an instance of the port enumeration
@@ -131,15 +131,17 @@ func (r *Runner) RunEnumeration() error {
131131
132132func (r * Runner ) ConnectVerification () {
133133 r .scanner .State = scan .Scan
134- swg := sizedwaitgroup .New (r .options .Rate )
134+ var swg sync.WaitGroup
135+ limiter := time .Tick (time .Second / time .Duration (r .options .Rate ))
135136
136137 for host , ports := range r .scanner .ScanResults .M {
137- swg .Add ()
138- go func (swg * sizedwaitgroup.SizedWaitGroup , host string , ports map [int ]struct {}) {
138+ <- limiter
139+ swg .Add (1 )
140+ go func (host string , ports map [int ]struct {}) {
139141 defer swg .Done ()
140142 results := r .scanner .ConnectVerify (host , ports )
141143 r .scanner .ScanResults .SetPorts (host , results )
142- }(& swg , host , ports )
144+ }(host , ports )
143145 }
144146
145147 swg .Wait ()
@@ -151,12 +153,14 @@ func (r *Runner) BackgroundWorkers() {
151153
152154func (r * Runner ) RawSocketEnumeration () {
153155 r .scanner .State = scan .Scan
154- swg := sizedwaitgroup .New (r .options .Rate )
156+ var swg sync.WaitGroup
157+ limiter := time .Tick (time .Second / time .Duration (r .options .Rate ))
155158
156159 for retry := 0 ; retry < r .options .Retries ; retry ++ {
157160 for port := range r .scanner .Ports {
158161 for target := range r .scanner .Targets {
159- swg .Add ()
162+ <- limiter
163+ swg .Add (1 )
160164 go r .handleHostPortSyn (& swg , target , port )
161165 }
162166 }
@@ -168,12 +172,14 @@ func (r *Runner) RawSocketEnumeration() {
168172func (r * Runner ) ConnectEnumeration () {
169173 r .scanner .State = scan .Scan
170174 // naive algorithm - ports spray
171- swg := sizedwaitgroup .New (r .options .Rate )
175+ var swg sync.WaitGroup
176+ limiter := time .Tick (time .Second / time .Duration (r .options .Rate ))
172177
173178 for retry := 0 ; retry < r .options .Retries ; retry ++ {
174179 for port := range r .scanner .Ports {
175180 for target := range r .scanner .Targets {
176- swg .Add ()
181+ <- limiter
182+ swg .Add (1 )
177183 go r .handleHostPort (& swg , target , port )
178184 }
179185 }
@@ -198,7 +204,7 @@ func (r *Runner) canIScanIfCDN(host string, port int) bool {
198204 return port == 80 || port == 443
199205}
200206
201- func (r * Runner ) handleHostPort (swg * sizedwaitgroup. SizedWaitGroup , host string , port int ) {
207+ func (r * Runner ) handleHostPort (swg * sync. WaitGroup , host string , port int ) {
202208 defer swg .Done ()
203209
204210 // performs cdn scan exclusions checks
@@ -217,7 +223,7 @@ func (r *Runner) handleHostPort(swg *sizedwaitgroup.SizedWaitGroup, host string,
217223 }
218224}
219225
220- func (r * Runner ) handleHostPortSyn (swg * sizedwaitgroup. SizedWaitGroup , host string , port int ) {
226+ func (r * Runner ) handleHostPortSyn (swg * sync. WaitGroup , host string , port int ) {
221227 defer swg .Done ()
222228
223229 // performs cdn scan exclusions checks
0 commit comments