rex-socket 0.1.67 → 0.1.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rex/socket/udp.rb +76 -35
- data/lib/rex/socket/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06a8d5b9b8dff6b4e9ef66dbccf00522bacff3f3e7e7b011f13a3548cd595f6d
|
|
4
|
+
data.tar.gz: 3fb1e4a3d8a356468b9ff998d7001eacd001ff825d97bf7ffae41b88489d2be3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d75a50f35c0853ad85026916638d1cea6724d4fbdf52f704bc396872ee85228c0f1db096b443ad52bc1631fb52e220e6ef44c024352e958df50b554043a68930
|
|
7
|
+
data.tar.gz: cd78a56eec5f4b4e780cf496eca88452057786065d300a0db2cb7eba00fa962d94c9c0e0227e73cb78a3931f018ae58259546e874b945cd154829f397d635320
|
data/lib/rex/socket/udp.rb
CHANGED
|
@@ -97,57 +97,98 @@ module Rex::Socket::Udp
|
|
|
97
97
|
#
|
|
98
98
|
# Sends a datagram to the supplied host:port with optional flags.
|
|
99
99
|
#
|
|
100
|
+
# @deprecated Use {#send} with the stdlib 4-arg form send(mesg, flags, host, port) instead.
|
|
101
|
+
# Note the argument order differs: sendto(gram, host, port, flags) vs send(mesg, flags, host, port).
|
|
102
|
+
#
|
|
100
103
|
def sendto(gram, peerhost, peerport, flags = 0)
|
|
104
|
+
warn "#{self.class}#sendto is deprecated; use send(mesg, flags, host, port) instead", uplevel: 1
|
|
105
|
+
send(gram, flags, peerhost, peerport)
|
|
106
|
+
end
|
|
101
107
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
#
|
|
109
|
+
# Sends a datagram using the stdlib 4-arg form send(mesg, flags, host, port).
|
|
110
|
+
#
|
|
111
|
+
# The 4-arg form handles IPv6/IPv4 address mapping and dispatches via
|
|
112
|
+
# BasicSocket#send with a packed sockaddr, so channel/pivoted sockets that
|
|
113
|
+
# override sendto are not involved. Also accepts the 3-arg sockaddr form used
|
|
114
|
+
# by lower-level callers, and the 2-arg connected-socket form.
|
|
115
|
+
#
|
|
116
|
+
def send(mesg, flags, host = nil, port = nil)
|
|
117
|
+
if host && port
|
|
118
|
+
# Catch unconnected IPv6 sockets talking to IPv4 addresses
|
|
119
|
+
peer = Rex::Socket.resolv_nbo(host)
|
|
120
|
+
if peer.length == 4 && self.ipv == 6
|
|
121
|
+
host_address = Rex::Socket.getaddress(host, true)
|
|
122
|
+
host = '::ffff:' + host_address unless host_address.downcase.start_with?('::ffff:')
|
|
108
123
|
end
|
|
124
|
+
begin
|
|
125
|
+
super(mesg, flags, Rex::Socket.to_sockaddr(host, port))
|
|
126
|
+
rescue ::Errno::EHOSTUNREACH, ::Errno::ENETDOWN, ::Errno::ENETUNREACH, ::Errno::ENETRESET,
|
|
127
|
+
::Errno::EHOSTDOWN, ::Errno::EACCES, ::Errno::EINVAL, ::Errno::EADDRNOTAVAIL
|
|
128
|
+
nil
|
|
129
|
+
end
|
|
130
|
+
elsif host
|
|
131
|
+
super(mesg, flags, host)
|
|
132
|
+
else
|
|
133
|
+
super(mesg, flags)
|
|
109
134
|
end
|
|
135
|
+
end
|
|
110
136
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
137
|
+
#
|
|
138
|
+
# Receives a datagram and returns the data and sender address information as
|
|
139
|
+
# [ data, [address_family, port, host, host] ], matching stdlib
|
|
140
|
+
# UDPSocket#recvfrom. Like the stdlib method, this blocks until a datagram is
|
|
141
|
+
# available and has no timeout of its own (see #timed_recvfrom for a variant
|
|
142
|
+
# that does). The host appears in both the hostname and numeric address
|
|
143
|
+
# positions; no reverse-DNS lookup is performed.
|
|
144
|
+
#
|
|
145
|
+
# @param maxlen [Integer] maximum number of bytes to receive
|
|
146
|
+
# @param flags [Integer] flags passed to the underlying recvfrom(2) call (default: 0)
|
|
147
|
+
# @return [Array(String, Array)] the datagram and the sender address information
|
|
148
|
+
#
|
|
149
|
+
def recvfrom(maxlen, flags = 0)
|
|
150
|
+
# Block until the socket is readable to mirror the stdlib's blocking
|
|
151
|
+
# UDPSocket#recvfrom; a nil timeout waits indefinitely.
|
|
152
|
+
::IO.select([ fd ], nil, nil, nil)
|
|
153
|
+
data, saddr = recvfrom_nonblock(maxlen, flags)
|
|
154
|
+
[ data, sender_addr_info(saddr) ]
|
|
117
155
|
end
|
|
118
156
|
|
|
119
157
|
#
|
|
120
|
-
# Receives a datagram
|
|
121
|
-
#
|
|
158
|
+
# Receives a datagram like #recvfrom but waits at most +timeout+ seconds for
|
|
159
|
+
# one to arrive, returning nil if the timeout elapses first. The return value
|
|
160
|
+
# otherwise matches #recvfrom: [ data, [address_family, port, host, host] ].
|
|
122
161
|
#
|
|
123
|
-
|
|
162
|
+
# @param maxlen [Integer] maximum number of bytes to receive
|
|
163
|
+
# @param timeout [Numeric] seconds to wait for a datagram before giving up
|
|
164
|
+
# @return [Array(String, Array), nil] the datagram and sender address
|
|
165
|
+
# information, or nil if no datagram arrived within +timeout+ seconds
|
|
166
|
+
#
|
|
167
|
+
def timed_recvfrom(maxlen = 65535, timeout = def_read_timeout)
|
|
168
|
+
return nil unless ::IO.select([ fd ], nil, nil, timeout)
|
|
124
169
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
af, host, port = Rex::Socket.from_sockaddr(saddr)
|
|
170
|
+
data, saddr = recvfrom_nonblock(maxlen)
|
|
171
|
+
[ data, sender_addr_info(saddr) ]
|
|
172
|
+
rescue ::Timeout::Error, ::Errno::ECONNREFUSED
|
|
173
|
+
nil
|
|
174
|
+
end
|
|
131
175
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
rescue ::Exception
|
|
141
|
-
return [ '', nil, nil ]
|
|
142
|
-
end
|
|
176
|
+
#
|
|
177
|
+
# Converts a packed sockaddr into the stdlib UDPSocket#recvfrom-style sender
|
|
178
|
+
# address tuple [ address_family, port, host, host ].
|
|
179
|
+
#
|
|
180
|
+
def sender_addr_info(saddr)
|
|
181
|
+
af, host, port = Rex::Socket.from_sockaddr(saddr)
|
|
182
|
+
af_name = ::Socket.constants.grep(/^AF_/).find { |c| ::Socket.const_get(c) == af }.to_s
|
|
183
|
+
[ af_name, port, host, host ]
|
|
143
184
|
end
|
|
185
|
+
private :sender_addr_info
|
|
144
186
|
|
|
145
187
|
#
|
|
146
|
-
# Calls
|
|
188
|
+
# Calls #timed_read and returns the data
|
|
147
189
|
#
|
|
148
190
|
def get(timeout=nil)
|
|
149
|
-
|
|
150
|
-
return data
|
|
191
|
+
timed_read(65535, timeout)
|
|
151
192
|
end
|
|
152
193
|
|
|
153
194
|
#
|
data/lib/rex/socket/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rex-socket
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.69
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Metasploit Hackers
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|