使用Scapy实施简单的NAT

发布于 2025-02-10 05:40:00 字数 1286 浏览 3 评论 0原文

因此拓扑是这样的:H1(192.168.1.2)--- S1 ---(192.168.1.1) M试图在H3中使用SCAPY实现一个简单的NAT脚本。

from scapy.all import *
def handlePacket(pkt):
        if pkt.sniffed_on == "h3-eth0":
                if IP in pkt and ICMP in pkt:
                        if pkt[IP].src=="192.168.1.2" and pkt[IP].dst == "20.0.0.2":
                                pkt[IP].src="20.0.0.3"
                                pkt[Ether].dst= None
                                sendp(pkt,iface="h3-eth1")
         elif pkt.sniffed_on == "h3-eth1":
                if IP in pkt and ICMP in pkt:
                        if pkt[IP].src=="20.0.0.2" and pkt[IP].dst=="20.0.0.3":
                                pkt[IP].dst="192.168.1.2"
                                pkt[Ether].dst= None
                                sendp(pkt,iface="h3-eth0")
if __name__ == "__main__":
        sniff(filter="icmp",iface=["h3-eth0","h3-eth1"],prn=handlePacket)

在这里,H2接收ICMP数据包,但不给出答复

框架7:98字节(784位),98个字节捕获(784位)接口H2-ETH0,ID 0 以太网II,SRC:52:A8:79:2D:6F:CF(52:A8:79:2D:6F:6F:CF),DST:36:34:00:00:71:F8:51(36:34:00: 71:F8:51) Internet协议版本4,SRC:20.0.0.3,DST:20.0.0.2

我在这里做错了什么?

So the topology is like this: H1(192.168.1.2)---S1---(192.168.1.1)H3(20.0.0.1)---S2---H2(20.0.0.2)... and I'm trying to implement a simple NAT script using scapy in H3.

from scapy.all import *
def handlePacket(pkt):
        if pkt.sniffed_on == "h3-eth0":
                if IP in pkt and ICMP in pkt:
                        if pkt[IP].src=="192.168.1.2" and pkt[IP].dst == "20.0.0.2":
                                pkt[IP].src="20.0.0.3"
                                pkt[Ether].dst= None
                                sendp(pkt,iface="h3-eth1")
         elif pkt.sniffed_on == "h3-eth1":
                if IP in pkt and ICMP in pkt:
                        if pkt[IP].src=="20.0.0.2" and pkt[IP].dst=="20.0.0.3":
                                pkt[IP].dst="192.168.1.2"
                                pkt[Ether].dst= None
                                sendp(pkt,iface="h3-eth0")
if __name__ == "__main__":
        sniff(filter="icmp",iface=["h3-eth0","h3-eth1"],prn=handlePacket)

Here, H2 receives the ICMP packet but doesn't give reply

Frame 7: 98 bytes on wire (784 bits), 98 bytes captured (784 bits) on interface h2-eth0, id 0
Ethernet II, Src: 52:a8:79:2d:6f:cf (52:a8:79:2d:6f:cf), Dst: 36:34:00:71:f8:51 (36:34:00:71:f8:51)
Internet Protocol Version 4, Src: 20.0.0.3, Dst: 20.0.0.2

What am i doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文