@@ -139,9 +139,7 @@ def dispatch_request(packet, rhost, src_port)
139139 end
140140 ip_pkt . recalc
141141
142- open_pcap
143- capture_sendto ( ip_pkt , rhost . to_s , true )
144- close_pcap
142+ capture_sendto ( ip_pkt , rhost . to_s , true )
145143 end
146144
147145 def monitor_socket
@@ -176,7 +174,10 @@ def should_print_reply?(host)
176174
177175 def run
178176 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' } )
180181
181182 # Multicast Address for LLMNR
182183 multicast_addr = ::IPAddr . new ( "224.0.0.252" )
@@ -191,12 +192,14 @@ def run
191192 self . sock = Rex ::Socket . create_udp (
192193 # This must be INADDR_ANY to receive multicast packets
193194 'LocalHost' => "0.0.0.0" ,
194- 'LocalPort' => 5355 )
195+ 'LocalPort' => 5355 ,
196+ 'Context' => { 'Msf' => framework , 'MsfExploit' => self }
197+ )
195198 self . sock . setsockopt ( ::Socket ::SOL_SOCKET , ::Socket ::SO_REUSEADDR , 1 )
196199 self . sock . setsockopt ( ::Socket ::IPPROTO_IP , ::Socket ::IP_ADD_MEMBERSHIP , optval )
197200
198201 self . thread = Rex ::ThreadFactory . spawn ( "LLMNRServerMonitor" , false ) {
199- monitor_socket
202+ monitor_socket
200203 }
201204
202205 print_status ( "LLMNR Spoofer started. Listening for LLMNR requests with REGEX \" #{ datastore [ 'REGEX' ] } \" ..." )
@@ -206,9 +209,13 @@ def run
206209 while thread . alive?
207210 select ( nil , nil , nil , 0.25 )
208211 end
209-
210- self . thread . kill
211- self . sock . close rescue nil
212212 end
213213
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
214221end
0 commit comments