@@ -21,6 +21,7 @@ package scanner
21
21
22
22
import (
23
23
"fmt"
24
+ "math"
24
25
"sync"
25
26
26
27
"github.com/Chocapikk/wpprobe/internal/utils"
@@ -50,24 +51,26 @@ func ScanTargets(opts ScanOptions) {
50
51
}
51
52
targets = lines
52
53
} else {
53
- targets = append ( targets , opts .URL )
54
+ targets = [] string { opts .URL }
54
55
}
55
56
56
57
vulns , _ := wordfence .LoadVulnerabilities ("wordfence_vulnerabilities.json" )
57
- siteThreads := opts .Threads
58
58
59
- if siteThreads < 1 {
60
- siteThreads = 1
59
+ totalThreads := opts .Threads
60
+ if totalThreads < 1 {
61
+ totalThreads = 1
61
62
}
62
63
63
- if siteThreads > len (targets ) {
64
- siteThreads = len (targets )
65
- }
66
- sem := make (chan struct {}, siteThreads )
64
+ n := len (targets )
65
+
66
+ perSite := int (math .Max (1 , float64 (totalThreads )/ float64 (n )))
67
+ siteConcurrent := int (math .Min (float64 (totalThreads ), float64 (n )))
68
+
69
+ sem := make (chan struct {}, siteConcurrent )
67
70
68
71
var progress * utils.ProgressManager
69
72
if opts .File != "" {
70
- progress = utils .NewProgressBar (len ( targets ) , "🔎 Scanning..." )
73
+ progress = utils .NewProgressBar (n , "🔎 Scanning..." )
71
74
} else {
72
75
progress = utils .NewProgressBar (1 , "🔎 Scanning..." )
73
76
}
@@ -82,22 +85,24 @@ func ScanTargets(opts ScanOptions) {
82
85
for _ , target := range targets {
83
86
wg .Add (1 )
84
87
sem <- struct {}{}
88
+
85
89
go func (t string ) {
86
90
defer wg .Done ()
87
91
defer func () { <- sem }()
88
92
defer func () { _ = recover () }()
89
93
90
94
local := opts
91
- local .Threads = siteThreads
95
+ local .Threads = perSite
96
+
92
97
ScanSite (t , local , writer , progress , vulns )
93
98
94
99
if opts .File != "" && progress != nil {
95
100
progress .Increment ()
96
101
}
97
102
}(target )
98
103
}
99
- wg .Wait ()
100
104
105
+ wg .Wait ()
101
106
if progress != nil {
102
107
progress .Finish ()
103
108
}
0 commit comments