配置 Scapy 侦听特定数据包,一旦收到数据包,就发送特定数据包 [英] configure Scapy to listen for a specific packet and once the packet is received, send a specific packet

查看:65
本文介绍了配置 Scapy 侦听特定数据包,一旦收到数据包,就发送特定数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 Scapy 配置为侦听网络流量并在收到具有特定参数的数据包后发送精心制作的数据包?我的意思是,例如 Scapy 侦听 eth0 上的网络流量,如果收到来自源 IP 10.10.44.3 的 ICMP回显请求"数据包,Scapy 将使用 8.8.8.8 作为 IP 地址 192.168.2.1 的 TCP SYN 数据包发送到端口 34 到 IP 地址 192.168.2.1来源.Scapy 可以进行这种设置吗?

解决方案

是.

使用 sniff() 函数,您可以为 stop_filter 选项提供一个参数.

<预><代码>>>>打印嗅探.__doc__嗅探数据包sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] +L2ListenSocket args) ->数据包列表...剪辑...stop_filter:python 函数应用于每个数据包以确定如果我们必须在此数据包之后停止捕获例如:stop_filter = lambda x: x.haslayer(TCP)

如果函数返回 1,嗅探将停止,您可以继续执行您希望的任何逻辑.

Is it possible to configure Scapy to listen for network traffic and send a crafted packet once a packet with certain parameters is received? I mean for example Scapy listens network traffic on eth0 and in case an ICMP "echo request" packet from source IP 10.10.44.3 is received, Scapy sends an TCP SYN packet to port 34 to IP address 192.168.2.1 using 8.8.8.8 as a source. Is such setup possible with Scapy?

解决方案

Yes.

Using the sniff() function, you can provide a parameter to the stop_filter option.

>>> print sniff.__doc__
Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + 
      L2ListenSocket args) -> list of packets

...clipped...

stop_filter: python function applied to each packet to determine
             if we have to stop the capture after this packet
             ex: stop_filter = lambda x: x.haslayer(TCP)

If the function returns 1, sniff will stop, and you can continue with whatever logic you wish.

这篇关于配置 Scapy 侦听特定数据包,一旦收到数据包,就发送特定数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆