MassDNS wrapper written in go to enumerate valid subdomains using active bruteforce as well as resolve subdomains with wildcard filtering and easy input-output support.
Bufio.Writer is not safe when shared between goroutines without custom synchronization. Not sure how common this crash is or I was just very very unlucky. Happy to submit a PR that wraps the writer in a mutex. This issue only occurs when writing the results to a file.
var w *bufio.Writer
store.Iterate(func(ip string, hostnames []string, counter int) {
for _, hostname := range hostnames {
// SNIP
go func(hostname string) {
//SNIP
if output != nil {
_, _ = w.WriteString(data) // Here
}
// SNIP
}(hostname)
}
})
If two goroutines are unlucky enough to land here at the same time b.n += n then the internal tracker of the buffer size becomes incorrect and we get the OOB error.
Describe the bug
Bufio.Writer is not safe when shared between goroutines without custom synchronization. Not sure how common this crash is or I was just very very unlucky. Happy to submit a PR that wraps the writer in a mutex. This issue only occurs when writing the results to a file.
Shuffledns version
Complete command you used to reproduce this
Screenshots
We've got a writer that is shared between many go routines https://github.com/projectdiscovery/shuffledns/blob/1e45a1b42a7910fa6af00bf6071e107af73fab48/pkg/massdns/process.go#L260
If two goroutines are unlucky enough to land here at the same time
b.n += n
then the internal tracker of the buffer size becomes incorrect and we get the OOB error.https://github.com/golang/go/blob/d8c7230c97ca5639389917cc235175bfe2dc50ab/src/bufio/bufio.go#L762
https://github.com/projectdiscovery/shuffledns/blob/1e45a1b42a7910fa6af00bf6071e107af73fab48/pkg/massdns/process.go#L337