@@ -139,9 +139,7 @@ def dispatch_request(packet, rhost, src_port)
139
139
end
140
140
ip_pkt . recalc
141
141
142
- open_pcap
143
- capture_sendto ( ip_pkt , rhost . to_s , true )
144
- close_pcap
142
+ capture_sendto ( ip_pkt , rhost . to_s , true )
145
143
end
146
144
147
145
def monitor_socket
@@ -176,7 +174,10 @@ def should_print_reply?(host)
176
174
177
175
def run
178
176
check_pcaprub_loaded ( )
179
- ::Socket . do_not_reverse_lookup = true
177
+ ::Socket . do_not_reverse_lookup = true # Mac OS X workaround
178
+
179
+ # Avoid receiving extraneous traffic on our send socket
180
+ open_pcap ( { 'FILTER' => 'ether host f0:f0:f0:f0:f0:f0' } )
180
181
181
182
# Multicast Address for LLMNR
182
183
multicast_addr = ::IPAddr . new ( "224.0.0.252" )
@@ -191,12 +192,14 @@ def run
191
192
self . sock = Rex ::Socket . create_udp (
192
193
# This must be INADDR_ANY to receive multicast packets
193
194
'LocalHost' => "0.0.0.0" ,
194
- 'LocalPort' => 5355 )
195
+ 'LocalPort' => 5355 ,
196
+ 'Context' => { 'Msf' => framework , 'MsfExploit' => self }
197
+ )
195
198
self . sock . setsockopt ( ::Socket ::SOL_SOCKET , ::Socket ::SO_REUSEADDR , 1 )
196
199
self . sock . setsockopt ( ::Socket ::IPPROTO_IP , ::Socket ::IP_ADD_MEMBERSHIP , optval )
197
200
198
201
self . thread = Rex ::ThreadFactory . spawn ( "LLMNRServerMonitor" , false ) {
199
- monitor_socket
202
+ monitor_socket
200
203
}
201
204
202
205
print_status ( "LLMNR Spoofer started. Listening for LLMNR requests with REGEX \" #{ datastore [ 'REGEX' ] } \" ..." )
@@ -206,9 +209,13 @@ def run
206
209
while thread . alive?
207
210
select ( nil , nil , nil , 0.25 )
208
211
end
209
-
210
- self . thread . kill
211
- self . sock . close rescue nil
212
212
end
213
213
214
+ def cleanup
215
+ if self . thread and self . thread . alive?
216
+ self . thread . kill
217
+ self . thread = nil
218
+ end
219
+ close_pcap
220
+ end
214
221
end
0 commit comments