【问题标题】:Scapy function not returning DHCP requests from Amazon dash buttonScapy 函数未从 Amazon dash 按钮返回 DHCP 请求
【发布时间】:2017-03-27 05:04:55
【问题描述】:

我正在使用 scapy 嗅探功能来使用 Amazon Dash 按钮来触发功能。我使用的代码基本上完全来自 Github 上的一个解决方案,只是做了一些非常小的调整。

我使用了 Wire Shark,发现了破折号按钮的 DHCP 请求,并从这里提取了按钮的 MAC 地址,但该函数仍然没有返回任何内容。

代码如下:

import logging
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
from scapy.all import *

def dash_pressed():
  print 'Dash button pressed.'

def udp_filter(pkt):
  options = pkt[DHCP].options
  for option in options:
    if isinstance(option, tuple):
      if 'requested_addr' in option:
        mac_to_action[pkt.src]()
        break

mac_to_action = {'DASH_MAC_ADDRESS_HERE' : dash_pressed}
mac_id_list = list(mac_to_action.keys())

print 'Waiting for a button press...'
sniff(prn=udp_filter, store=0, filter='udp', lfilter=lambda d: d.src in mac_id_list)

(替换 mac_to_action 字典中的 MAC 地址字符串)

我没有收到任何错误,只是没有通过。当我打印嗅探功能时,它显示 0 个 udp 数据包。我已经两次和三次检查了我的 MAC 地址,这绝对是源地址(不是说无论如何我都可以将它与 ff:ff:ff:ff:ff:ff 混为一谈)。为什么按破折号按钮时它没有收到?

【问题讨论】:

    标签: python udp scapy dhcp


    【解决方案1】:

    此代码适用于我的亚马逊按钮

    def arp_handler(pkt):
        """ Handles sniffed ARP requests """
        for layer in [ARP]:
            if pkt.haslayer(layer):
                if pkt[layer].op == 1:  #who-has request
                    mac = pkt[layer].hwsrc
                    # your code to handle
    
    
    def main():
        sniff(prn=arp_handler, filter="arp", store=0)
    

    我不确定问题是否出在 ARP / DHCP 差异上。 可能是您在没有 root 权限的情况下运行代码,或者执行了其他阻止 scapy 正常工作的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-22
      • 2016-11-27
      • 1970-01-01
      • 2021-06-28
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      相关资源
      最近更新 更多