2017-07-03 62 views
0

我正在使用scapy嗅探具有特定源ip/dest ip的IPv6數據包。Scapy中的IPv6過濾器

例子:

filter1 ="tcp port "+`port`+ " and ip6 host 2001::4 and tcp[tcpflags] & tcp-syn !=0 and !icmp and !arp and not host "+host_ip 

      a= sniff(count =1,filter=filter1,iface=eth) 

這會拋出一個異常,如下圖所示: scapy.error.Scapy_Exception:過濾解析錯誤

回答

1

我從來沒有使用Scapy的,而是我在你filter1表達注意到,您有:

+`port`+ 

...但你必須:

+host_ip 

也許你需要圍繞host_ip回來?

如果這不是問題,你也可以嘗試使用工具,如tcpdump,例如,tcpdump -d ${filter1}dumpcap,例如,dumpcap -d ${filter1}試圖在Scapy的使用它們之前驗證捕獲過濾器。

+0

反引號被用於端口蟒蛇不允許串聯地干擾(端口作爲一個整數)與字符串,而主機的IP是一個字符串 –

1

對於複雜的過濾器,Scapy的允許你使用Python函數作爲過濾器:

desiredip = "2001::4" 
undesiredip = host_ip 

def isMyPacket (pkt): 
    if IPv6 in pkt: 
     pktip6 = pkt[IPv6] 
     if pktip6.src == desiredip or pktip6.dst == desiredip: 
      if pktip6.src != undesiredip and pktip6.dst != undesiredip: 
       if TCP in pktip6: 
        if pktip6[TCP].flags & 0x02: #Check if it is a SYN 
         return True #If all conditions are met 
    return False 


a= sniff(count =1,lfilter=isMyPacket,iface=eth) 

反正你也不需要檢查它是否是ARP或ICMP:如果它是TCP你知道肯定它不是arp也不是icmp。

更多關於Scapy的TCP標誌位:Get TCP Flags with Scapy

+0

謝謝馬丁 –