Socket#sendto removed in newer Ruby — affects dozens of call sites in lib/ and modules/
Steps to reproduce
- On a Ruby install where
Socket#sendto/UDPSocket#sendtohas been removed (confirmed removed as of Ruby 4.0.3; deprecated in earlier 3.x versions), run any module or library code path that calls.sendto(data, host, port, flags)on a UDP socket. - Observe either a deprecation warning (older Ruby) or a hard
NoMethodError: undefined method 'sendto' for an instance of UDPSocket(newer Ruby).
Minimal repro of the underlying Ruby behavior:
require 'socket'
s = UDPSocket.new
s.sendto('x', '127.0.0.1', 9)
# NoMethodError: undefined method 'sendto' for an instance of UDPSocketWere you following a specific guide/tutorial or reading documentation?
No.
Expected behavior
Metasploit's UDP send paths should work regardless of Ruby version, using send(mesg, flags, host, port) (or Socket#sendmsg) instead of the removed sendto.
Current behavior
Socket#sendto / UDPSocket#sendto is deprecated in recent Ruby 3.x and has been fully removed in Ruby 4.0 (confirmed via direct test on Ruby 4.0.3 — raises NoMethodError rather than a warning). metasploit-framework.gemspec only requires Ruby >= 3.1, so this will increasingly break as users run the framework on newer interpreters.
This is not limited to login_scanner/snmp.rb (originally reported here) — the same .sendto(...) pattern is used throughout the codebase on raw Ruby UDP sockets:
Library code:
lib/snmp/manager.rblib/msf/core/exploit/remote/wdbrpc_client.rb(multiple call sites)lib/msf/core/exploit/remote/ip.rblib/msf/core/auxiliary/udp_scanner.rblib/rex/proto/tftp/server.rblib/rex/proto/dhcp/server.rb(multiple call sites)lib/rex/proto/dns/server.rblib/rex/proto/ldap/server.rblib/rex/proto/iax2/client.rblib/rex/proto/tftp/client.rb(multiple call sites)lib/rex/proto/natpmp/packet.rblib/metasploit/framework/login_scanner/snmp.rb
Modules:
modules/post/multi/recon/multiport_egress_traffic.rbmodules/post/multi/escalate/metasploit_pcaplog.rbmodules/exploits/osx/mdns/upnp_location.rbmodules/exploits/multi/upnp/libupnp_ssdp_overflow.rbmodules/exploits/windows/misc/crosschex_device_bof.rbmodules/auxiliary/dos/scada/d20_tftp_overflow.rbmodules/auxiliary/server/capture/sip.rbmodules/auxiliary/scanner/vxworks/wdbrpc_version.rbmodules/auxiliary/scanner/vxworks/wdbrpc_bootline.rbmodules/auxiliary/scanner/scada/bacnet_l3.rbmodules/auxiliary/scanner/scada/koyo_login.rbmodules/auxiliary/scanner/tftp/netdecision_tftp.rbmodules/auxiliary/scanner/tftp/ipswitch_whatsupgold_tftp.rbmodules/auxiliary/scanner/tftp/tftpbrute.rbmodules/auxiliary/scanner/ike/cisco_ike_benigncertain.rbmodules/auxiliary/scanner/sip/enumerator.rbmodules/auxiliary/scanner/jenkins/jenkins_udp_broadcast_enum.rbmodules/auxiliary/scanner/ipmi/ipmi_dumphashes.rbmodules/auxiliary/scanner/natpmp/natpmp_portscan.rbmodules/auxiliary/fuzzers/ntp/ntp_protocol_fuzzer.rb
(Not affected: railgun.ws2_32.sendto calls are Windows API calls via Railgun, unrelated to Ruby's Socket#sendto.)
Each of these should be updated to use send(mesg, flags, host, port) instead of sendto(mesg, host, port, flags).
Metasploit version
Source install, git log -1 --pretty=oneline:
7fca144afc75d935a49ea5de56d822aee2e53b8d Merge pull request #21740 from dwelch-r7/fix-json-rpc-payload-testfAdditional Information
Not encountered inside msfconsole directly — surfaces as a Ruby warning (older Ruby) or hard crash (Ruby 4.0+) any time one of the affected UDP send paths is hit.
Source: rapid7/metasploit-framework