调整scapy以识别特定的问题

2024-06-28 19:11:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试修改下面的脚本,以便在检测到与特定格式匹配的探测器时能够在终端中发出警报。我要匹配的格式是“KD-??????????????”有人能帮我吗?你知道吗

#!/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

Tags: toinfo脚本终端if格式sudo警报
1条回答
网友
1楼 · 发布于 2024-06-28 19:11:38

你知道吗 首先,如果需要唯一的值,不要使用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

相关问题 更多 >