2017-08-04 20 views
1

我試圖修改下面的腳本,以便在檢測到與特定格式匹配的探針時能夠在終端中發出警報。我想匹配的格式是'KD - ????????????????'誰能幫我嗎?修改scapy以識別特定的探針

#!/usr/bin/env python 
# -- coding: utf-8 -- 

from scapy.all import * 

unique_probe = [] 

def Handler(pkt): 
    if pkt.haslayer(Dot11): # 802.11 
     if pkt.type == 0 and pkt.subtype == 4: # mgmt, probe request 
      if pkt.addr2 not in unique_probe : 
      unique_probe.append(pkt.addr2) 
#####need something here to match pkt.info to a condition e.g. if pkt.info=KD* then 
       print "MAC: %s probing for %s possible use of KarmaDetector" %(pkt.addr2, pkt.info) 

sniff(iface="wla0mon", count=0, prn=Handler, store=0) # sudo rfkill unblock wifi && sudo airmon-ng start wlan0 

回答

0

首先,如果你想唯一值不使用list對象。使用set對象。

其次,您可以使用Dot11 in pkt而不是pkt.haslayer(Dot11)

然後,你只需要解析Dot11Elt層找到了相關值:

from scapy.all import * 

unique_probes = set() 

def handle(pkt): 
    if Dot11 in pkt and (pkt.type, pkt.subtype) == (0, 4): 
     unique_probes.add(pkt.addr2) 
     try: 
      subpkt = pkt[Dot11Elt] 
     except KeyError: 
      pass 
     while isinstance(subpkt, Dot11Elt): 
      if subpkt.ID == 0: # SSID 
       if subpkt.info.startswith('KD-'): 
        print "MAC %s probing for %s possible use of KarmaDetector" % (pkt.addr2, subpkt.info) 
       break 
      pkt = pkt.payload 

sniff(iface="wla0mon", count=0, prn=handler, store=0) # sudo rfkill unblock wifi && sudo airmon-ng start wlan0