【问题标题】:Replying to packets with scapy用 scapy 回复数据包
【发布时间】:2021-10-08 18:30:56
【问题描述】:

对于 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)

【问题讨论】:

    标签: networking scapy man-in-the-middle


    【解决方案1】:

    由于 ICMP 回复是由主机的 IP 堆栈发送的,因此您必须找到一个技巧来阻止它发送回复。如果您正在使用 linux 系统,例如,您可以:

    • 使 IP 堆栈忽略回显请求:
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
    
    • 配置防火墙,只发送scapy发送的ICMP回复。例如,您可以在 scapy 脚本中将 XXX 作为 ICMP 回复的有效负载,让防火墙只接受此类 ICMP 回复数据包。

    【讨论】:

    • 我们可以只忽略特定单一接口的回显请求吗?
    猜你喜欢
    • 1970-01-01
    • 2019-07-26
    • 2021-03-19
    • 1970-01-01
    • 2022-07-08
    • 2014-08-18
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多