Skip to content

Commit 7ff941f

Browse files
committed
Fix thread calculation for bruteforce mode
1 parent 0d5d8f3 commit 7ff941f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

internal/scanner/scan.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package scanner
2121

2222
import (
2323
"fmt"
24+
"math"
2425
"sync"
2526

2627
"github.com/Chocapikk/wpprobe/internal/utils"
@@ -50,24 +51,26 @@ func ScanTargets(opts ScanOptions) {
5051
}
5152
targets = lines
5253
} else {
53-
targets = append(targets, opts.URL)
54+
targets = []string{opts.URL}
5455
}
5556

5657
vulns, _ := wordfence.LoadVulnerabilities("wordfence_vulnerabilities.json")
57-
siteThreads := opts.Threads
5858

59-
if siteThreads < 1 {
60-
siteThreads = 1
59+
totalThreads := opts.Threads
60+
if totalThreads < 1 {
61+
totalThreads = 1
6162
}
6263

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)
6770

6871
var progress *utils.ProgressManager
6972
if opts.File != "" {
70-
progress = utils.NewProgressBar(len(targets), "🔎 Scanning...")
73+
progress = utils.NewProgressBar(n, "🔎 Scanning...")
7174
} else {
7275
progress = utils.NewProgressBar(1, "🔎 Scanning...")
7376
}
@@ -82,22 +85,24 @@ func ScanTargets(opts ScanOptions) {
8285
for _, target := range targets {
8386
wg.Add(1)
8487
sem <- struct{}{}
88+
8589
go func(t string) {
8690
defer wg.Done()
8791
defer func() { <-sem }()
8892
defer func() { _ = recover() }()
8993

9094
local := opts
91-
local.Threads = siteThreads
95+
local.Threads = perSite
96+
9297
ScanSite(t, local, writer, progress, vulns)
9398

9499
if opts.File != "" && progress != nil {
95100
progress.Increment()
96101
}
97102
}(target)
98103
}
99-
wg.Wait()
100104

105+
wg.Wait()
101106
if progress != nil {
102107
progress.Finish()
103108
}

0 commit comments

Comments
 (0)