Align UDP #recvfrom usage with the stdlib#21562
Conversation
|
Thanks for your pull request! As part of our landing process, we manually verify that all modules work as expected. We've added the |
9e909d9 to
89f3e9a
Compare
Temporarily source rex-socket from the fix/udp/recvfrom-api branch so the framework picks up the stdlib-aligned #recvfrom and the new #timed_recvfrom. Revert this commit once rex-socket is released to rubygems. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This pulls in changes from rapid7/rex-socket#83 which aligns #recvfrom to match the signature and behavior of the standard library in regards to it's arguments, return type and how it handles timeouts. The historical usage of #recvfrom was a timed read and can now be replaced with #timed_recvfrom.
f254716 to
22ba2eb
Compare
a050b7f to
e707971
Compare
| def recvfrom_nonblock(length, flags = 0) | ||
| data = super(length, flags)[0] | ||
| sockaddr = super(length, flags)[0] | ||
| sockaddr = super(MAX_SOCKADDR_LENGTH, flags)[0] |
There was a problem hiding this comment.
This fixes a different bug. What was going on here is that the socket address was being read from the peer (the other end of the socket pair), and the length argument was used for it, which caused a failure when the length wasn't sufficient for the address. The second read should always be for enough data to get the whole address.
|
Additional test pipeline started ⌛ |
|
Slice summary:
Note: build results only accessible to maintainers. |
Description
This requires the changes from rapid7/rex-socket#83 and incoporates them into the Metasploit framework to align the usage of
#recvfromon UDP sockets to behave the same as the standard library. This has the strong benefit of ensuring that developers do not need to worry about their socket beingUDPSocketorRex::Socket::Udpwhich by extension makes Metasploit compatible with libraries that need UDP sockets that have no knowledge of Rex.There are three issues with Rex's
#recvfromvs the standard libraryBreaking Changes
rapid7/rex-socket#83 is a breaking change. This PR brings framework inline so that nothing breakes on this side. There are no user-facing breaking changes.
Reviewer Notes
It's not really practical to re-test every single module that uses UDP. That's the main reason that
#timed_recvfromwas added, so methods could just be changed from#recvfrom->#timed_recvfromand not worry about points 1 and 3 from the list of issues above in the description section.Verification Steps
I ran through multiple tests of the most important modules which covered the main patterns. The new
#timed_recvfromis used in place of the old#recvfromwhere there was an expected timeout but the return value is aligned with the standard libraries#recvfrom.Things I tested include
auxiliary/scanner/snmp/snmp_loginauxiliary/gather/enum_dnsauxiliary/scanner/ntp/timeroastTest Evidence
AI Usage Disclosure
I was assisted by Claude Opus during this development.
Pre-Submission Checklist
rubocopon new files with no new offenses (net new files only)msftidyon changed module files with no new offenses (modules only)msftidy_docson changed documentation files with no new offenses (documentation files only)documentation/modules(new modules only)lib/changes)