You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a bug where whenever the scanner receives a reply from another port than the set destination SNMP port (161) all subsequently send probe packets will be send to this port.
This is because send and receive use the same sockaddr_in struct (remote_addr). Incoming replies from a rogue target device can alter the destination port in the next iteration and therefore make the scanner stop working correctly and send unsolicited packets.
I fixed this by setting the destination port before each send iteration together with the next destination address.
This PR fixes a bug that can cause scanner failure. Excellent catch, @f10d0!
The Bug
The scanner reuses the same remote_addr struct for both sending (sendto) and receiving (recvfrom). When recvfrom() is called at line 875, it overwrites the entire struct with the source address of the response - including the source port. If any device responds from a non-standard port (not 161), all subsequent probes get sent to the wrong port, breaking the scan for all remaining hosts.
The Fix
Moving remote_addr.sin_port = htons(o.port); inside the loop ensures the correct destination port is always set before each sendto(). This is the correct fix.
Why This Should Be Merged
Real Bug: This isn't theoretical - any device responding from a non-standard source port will corrupt the scanner's destination port for all subsequent hosts
Correct Fix: The solution properly addresses the root cause without side effects
Minimal Change: Just 1 line moved - perfectly matches onesixtyone's tight coding style
Zero Performance Impact: htons() is typically a macro doing bit-shifting; adds nanoseconds to operations taking milliseconds
No Breaking Changes: The change is isolated and maintains all existing behavior
Code Quality
The fix exemplifies onesixtyone's philosophy:
Extremely minimal (1 line moved)
No new variables or complexity
Clear and obvious what it does
Follows existing patterns
This is a textbook example of a good bug fix - minimal, correct, and essential.
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
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.
There is a bug where whenever the scanner receives a reply from another port than the set destination SNMP port (161) all subsequently send probe packets will be send to this port.
This is because send and receive use the same sockaddr_in struct (remote_addr). Incoming replies from a rogue target device can alter the destination port in the next iteration and therefore make the scanner stop working correctly and send unsolicited packets.
I fixed this by setting the destination port before each send iteration together with the next destination address.