def handle_read(self): # 802.11 maximum frame size is 2346 bytes (cf. RFC3580) # However, WiFi interfaces are always MTUed to 1500 dot11_rcvd_frame = self.fd.recv(2346) # WEP handling is automagicly done by Scapy if conf.wepkey is set # Nothing to do to decrypt (although not yet tested) # WEP frames have Dot11WEP layer, others don't #if DEBUG: # if dot11_rcvd_frame.haslayer(Dot11WEP): # WEP frame # os.write(1,"Received WEP from %s\n" % self._intf) # else: # Cleartext frame # os.write(1,"Received from %s\n" % self._intf) # if VERB: # os.write(1,"%s\n" % dot11_rcvd_frame.summary()) # if dot11_frame.getlayer(Dot11).FCfield & 1: # Frame is to-DS # For now, we only take care of to-DS frames... if dot11_rcvd_frame.getlayer(Dot11).addr1 != self._tap.bssid: return # One day, we'll try to take care of AP to DS trafic (cf. TODO) # else: # Frame is from-DS # if dot11_frame.getlayer(Dot11).addr2 != BSSID: # continue # eth_frame = Ether(dst=dot11_frame.getlayer(Dot11).addr1, # src=dot11_frame.getlayer(Dot11).addr3) if dot11_rcvd_frame.haslayer(SNAP): eth_sent_frame = Ether( dst=dot11_rcvd_frame.getlayer(Dot11).addr3, src=dot11_rcvd_frame.getlayer(Dot11).addr2, type=dot11_rcvd_frame.getlayer(SNAP).code) eth_sent_frame.payload = dot11_rcvd_frame.getlayer(SNAP).payload #if DEBUG: # os.write(1, "Sending to %s\n" % ifname) # if VERB: # os.write(1, "%s\n" % eth_sent_frame.summary()) # Add Tun/Tap header to frame, convert to string and send buf = "\x00\x00" + struct.pack("!H",eth_sent_frame.type) + str(eth_sent_frame) os.write(self.fd, buf)
def handle_read(self): # 802.11 maximum frame size is 2346 bytes (cf. RFC3580) # However, WiFi interfaces are always MTUed to 1500 dot11_rcvd_frame = self.fd.recv(2346) # WEP handling is automagicly done by Scapy if conf.wepkey is set # Nothing to do to decrypt (although not yet tested) # WEP frames have Dot11WEP layer, others don't #if DEBUG: # if dot11_rcvd_frame.haslayer(Dot11WEP): # WEP frame # os.write(1,"Received WEP from %s\n" % self._intf) # else: # Cleartext frame # os.write(1,"Received from %s\n" % self._intf) # if VERB: # os.write(1,"%s\n" % dot11_rcvd_frame.summary()) # if dot11_frame.getlayer(Dot11).FCfield & 1: # Frame is to-DS # For now, we only take care of to-DS frames... if dot11_rcvd_frame.getlayer(Dot11).addr1 != self._tap.bssid: return # One day, we'll try to take care of AP to DS trafic (cf. TODO) # else: # Frame is from-DS # if dot11_frame.getlayer(Dot11).addr2 != BSSID: # continue # eth_frame = Ether(dst=dot11_frame.getlayer(Dot11).addr1, # src=dot11_frame.getlayer(Dot11).addr3) if dot11_rcvd_frame.haslayer(SNAP): eth_sent_frame = Ether(dst=dot11_rcvd_frame.getlayer(Dot11).addr3, src=dot11_rcvd_frame.getlayer(Dot11).addr2, type=dot11_rcvd_frame.getlayer(SNAP).code) eth_sent_frame.payload = dot11_rcvd_frame.getlayer(SNAP).payload #if DEBUG: # os.write(1, "Sending to %s\n" % ifname) # if VERB: # os.write(1, "%s\n" % eth_sent_frame.summary()) # Add Tun/Tap header to frame, convert to string and send buf = "\x00\x00" + struct.pack( "!H", eth_sent_frame.type) + str(eth_sent_frame) os.write(self.fd, buf)
os.write(1, "Frame not to/from BSSID\n") continue # One day, we'll try to take care of AP to DS trafic (cf. TODO) # else: # Frame is from-DS # if dot11_frame.getlayer(Dot11).addr2 != BSSID: # continue # eth_frame = Ether(dst=dot11_frame.getlayer(Dot11).addr1, # src=dot11_frame.getlayer(Dot11).addr3) if dot11_rcvd_frame.haslayer(SNAP): eth_sent_frame = Ether( dst=dot11_rcvd_frame.getlayer(Dot11).addr3, src=dot11_rcvd_frame.getlayer(Dot11).addr2, type=dot11_rcvd_frame.getlayer(SNAP).code) eth_sent_frame.payload = dot11_rcvd_frame.getlayer( SNAP).payload if DEBUG: os.write(1, "Sending to %s\n" % ifname) if VERB: os.write(1, "%s\n" % eth_sent_frame.summary()) # Add Tun/Tap header to frame, convert to string and send buf = "\x00\x00" + struct.pack( "!H", eth_sent_frame.type) + str(eth_sent_frame) os.write(f, buf) # Program killed except KeyboardInterrupt: print "Stopped by user."
os.write(1,"Frame not to/from BSSID\n") continue # One day, we'll try to take care of AP to DS trafic (cf. TODO) # else: # Frame is from-DS # if dot11_frame.getlayer(Dot11).addr2 != BSSID: # continue # eth_frame = Ether(dst=dot11_frame.getlayer(Dot11).addr1, # src=dot11_frame.getlayer(Dot11).addr3) if dot11_rcvd_frame.haslayer(SNAP): eth_sent_frame = Ether( dst=dot11_rcvd_frame.getlayer(Dot11).addr3, src=dot11_rcvd_frame.getlayer(Dot11).addr2, type=dot11_rcvd_frame.getlayer(SNAP).code) eth_sent_frame.payload = dot11_rcvd_frame.getlayer(SNAP).payload if DEBUG: os.write(1, "Sending to %s\n" % ifname) if VERB: os.write(1, "%s\n" % eth_sent_frame.summary()) # Add Tun/Tap header to frame, convert to string and send buf = "\x00\x00" + struct.pack("!H",eth_sent_frame.type) + str(eth_sent_frame) os.write(f, buf) # Program killed except KeyboardInterrupt: print "Stopped by user." s.close()