【问题标题】:Detect ARP scan using python使用python检测ARP扫描
【发布时间】:2018-03-26 17:01:23
【问题描述】:

我想检测是否有人在网络上执行 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 吗?

【问题讨论】:

  • 应该是print(pkt.ip.src)...
  • pkt.ip.src 给出属性错误,因为这些是 arp 数据包,它们没有 IP 层。您能提出其他解决方案吗?
  • 哦,我的错。那将是pkt.arp.src.proto_ipv4
  • 不工作...同样的错误!
  • @pchaigno 您的解决方案与 scapy 完全兼容!感谢您的帮助。

标签: python pcap pyshark


【解决方案1】:

我找到了解决方案。这可以使用 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 as 访问 is_atTell 字段:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2013-11-26
    • 1970-01-01
    • 2011-07-22
    • 2011-09-30
    • 2012-02-20
    相关资源
    最近更新 更多