Skip directed-broadcast addresses silently in iteration mode - #6
Open
grisutheguru wants to merge 1 commit into
Open
Conversation
When iterating a CIDR range (e.g. /24), nbtscan tries to sendto() every address including the directed-broadcast (.255). Without SO_BROADCAST on the socket, the Linux kernel rejects this with EACCES, which is surfaced as the misleading "Sendto failed: Permission denied" error. The wording suggests a privileges problem and routinely sends users chasing sudo / setcap fixes that do not apply. Treat EACCES from sendto as a "skip this address silently" signal rather than print the error. Default iteration semantics for all other addresses are unchanged. An explicit broadcast probe (single packet with SO_BROADCAST set, opt-in via flag) would be a separate feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When iterating a CIDR range,
nbtscansends a NetBIOS query to every address in the range, including the directed-broadcast (e.g..255for a/24). WithoutSO_BROADCASTset on the UDP socket, Linux rejectssendto()to such addresses withEACCES, which is surfaced as:The wording suggests a privileges problem and routinely sends users chasing
sudo/setcapfixes that don't apply.Fix
Treat
EACCESfromsendto()as a "skip this address silently" signal rather than print an error. Default iteration semantics are unchanged for all non-broadcast addresses.Behaviour comparison
Before:
After:
For ranges whose broadcast is not directly connected (e.g.
nbtscan 192.168.68.0/23from a host on192.168.69.0/24), behaviour is unchanged: only the locally-connected.255was raisingEACCES, and that's the only address now being silently skipped.Verified that the kernel mechanism is
SO_BROADCASTFuture work (separate PR)
An opt-in
-B/--broadcastflag that setsSO_BROADCASTand sends a single query to the directed-broadcast of the input range (no iteration) would be a meaningful speedup for the common/24case. Happy to follow up with a separate PR for that if this one lands.