@@ -43,18 +43,20 @@ def run_batch_size
43
43
datastore [ 'BATCHSIZE' ] . to_i
44
44
end
45
45
46
- def udp_socket ( ip , port )
46
+ def udp_socket ( ip , port , bind_peer : true )
47
+ key = "#{ ip } :#{ port } :#{ bind_peer ? 'bound' : 'unbound' } "
47
48
@udp_sockets_mutex . synchronize do
48
- key = "#{ ip } :#{ port } "
49
49
unless @udp_sockets . key? ( key )
50
- @udp_sockets [ key ] =
51
- Rex ::Socket ::Udp . create ( {
52
- 'LocalHost' => datastore [ 'CHOST' ] || nil ,
53
- 'LocalPort' => datastore [ 'CPORT' ] || 0 ,
54
- 'PeerHost' => ip ,
55
- 'PeerPort' => port ,
56
- 'Context' => { 'Msf' => framework , 'MsfExploit' => self }
57
- } )
50
+ sock_info = {
51
+ 'LocalHost' => datastore [ 'CHOST' ] || nil ,
52
+ 'LocalPort' => datastore [ 'CPORT' ] || 0 ,
53
+ 'Context' => { 'Msf' => framework , 'MsfExploit' => self }
54
+ }
55
+ if bind_peer
56
+ sock_info [ 'PeerHost' ] = ip
57
+ sock_info [ 'PeerPort' ] = port
58
+ end
59
+ @udp_sockets [ key ] = Rex ::Socket ::Udp . create ( sock_info )
58
60
add_socket ( @udp_sockets [ key ] )
59
61
end
60
62
return @udp_sockets [ key ]
@@ -123,10 +125,16 @@ def scanner_send(data, ip, port)
123
125
data = data . to_binary_s if data . respond_to? ( 'to_binary_s' )
124
126
125
127
resend_count = 0
126
- sock = nil
128
+
127
129
begin
128
- sock = udp_socket ( ip , port )
129
- sock . send ( data , 0 )
130
+ addrinfo = Addrinfo . ip ( ip )
131
+ unless addrinfo . ipv4_multicast? || addrinfo . ipv6_multicast?
132
+ sock = udp_socket ( ip , port , bind_peer : true )
133
+ sock . send ( data , 0 )
134
+ else
135
+ sock = udp_socket ( ip , port , bind_peer : false )
136
+ sock . sendto ( data , ip , port , 0 )
137
+ end
130
138
131
139
rescue ::Errno ::ENOBUFS
132
140
resend_count += 1
@@ -136,8 +144,7 @@ def scanner_send(data, ip, port)
136
144
end
137
145
138
146
scanner_recv ( 0.1 )
139
-
140
- ::IO . select ( nil , nil , nil , 0.25 )
147
+ sleep ( 0.25 )
141
148
142
149
retry
143
150
0 commit comments