繁体   English   中英

使用python检测ARP扫描

[英]Detect ARP scan using python

我想检测是否有人在网络上执行ARP扫描并显示源IP。 意外的ARP请求数量不足以检测ARP扫描。 这是我的代码-

import pyshark

cap = pyshark.FileCapture('arpscan.pcap',display_filter='arp.opcode==1 && arp.dst.hw_mac==00:00:00:00:00:00',only_summaries=True)
count=0
for pkt in cap:
    count=count+1

if count>10:
    print (" ")
    print ("Someone is scanning your network!\n\n")
    print ("For Attacker's Ip, visit 'Tell' section in summary below\n\n ")
    print("----Further details----")
    print "No of ARP Request Packet Received: ", count
    print("----Summary of ARP packet Received---")
    for pkt in cap:
        print (pkt)
else: 
    print ("No ARP scan identified!")

我想提取源IP,即数据包的Tell部分中的IP。 我没有这样做。 有人可以告诉我如何显示源IP吗?

我找到了解决方案。 可以使用scapy代替pyshark!

from scapy.all import *


packets = sniff(offline=filename,filter='arp')
source='' 
source_mac=''
count=0

for pkt in packets:
    if pkt[ARP].op==1:
        count=count+1
        if count==5:
            source = pkt.sprintf("%ARP.psrc%")
            source_mac = pkt.sprintf("%ARP.hwsrc%")


if count>10:
    print "\nSomeone is scanning your network!"
    print "Source (IP): ",source
    print "Mac Address of Attacker: ",source_mac

else:
    print ("No Scan Identified!")

另外,我们可以使用scapy访问is_atTell字段:

operation = packet.sprintf("%ARP.op%")
if operation=="is_at":
   #do stuff

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM