networking - 用 scapy 回复数据包
问题描述
对于 POC,我需要创建一个 MITM 设置,在该设置中我将侦听接口上的 ICMP 流量,并且对于收到的所有 ping 命令,我将发送自己的回复。到目前为止,使用 python scapy,我已经能够拦截所有 ICMP 数据包。如何阻止实际的 ping 回复数据包并发送我自己的数据包作为回复?
我的代码看起来像这样
import scapy.all as scapy
import socket
from scapy.arch import get_if_hwaddr
from scapy.interfaces import get_if_list
from scapy.layers import http
from scapy.layers.inet import TCP, ICMP, IP
from scapy.layers.l2 import Ether
from uuid import getnode as get_mac
def sniffer(interface):
scapy.sniff(iface=interface, store=False, prn=process_packet)
def process_packet(packet):
if packet.haslayer(ICMP):
print("DUMP\n")
print(packet.show(dump=True))
print(packet[Ether].src)
print(Ether().src)
if packet[Ether].src == Ether().src:
print("OUTGOING PACKET")
else:
print("INCOMING PACKET")
interface = "Wi-Fi"
sniffer(interface)
解决方案
由于 ICMP 回复是由主机的 IP 堆栈发送的,因此您必须找到一个技巧来阻止它发送回复。如果您正在使用 linux 系统,例如,您可以:
- 使 IP 堆栈忽略回显请求:
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
- 配置防火墙,使得只能发送 scapy 发送的 ICMP 回复。例如,您可以将
XXX
您的 ICMP 回复的有效负载放在您的 scapy 脚本中,并让防火墙只接受此类 ICMP 回复数据包。
推荐阅读
- android - 合并回收站查看项目
- excel - 无法使用 Excel 中的“文本到列”和“单元格格式”选项将带有美元符号和逗号的美元金额格式化为简单数字
- javascript - 如何使用 css 显示网格使我的列号动态化?
- javascript - Chart JS - 页面刷新后记住隐藏标签状态
- java - Firebase:每次都必须验证用户,它运行应用程序
- flutter - Flutter 应用错误 发生异常。_TypeError(类型'String'不是'index'类型'int'的子类型)
- c++ - 为什么这个类模板参数被视为转发引用?
- java - 如何从 Java 消费者的主题中的消息中从模式注册表中检索 AVRO 模式
- python - 如何从 django 中的另一个模型更新模型的字段?
- html - 在我的导航栏上添加一个 PNG 标志,它从顶部和底部流动