1

I have some code for code injector on python. When i del cksum and len of TCP and IP layers, scapy doesnt recalculate them. Where am i idiot?

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
    packet = packet.__class__(bytes(packet))
    return packet

def process_packet(packet):
    scapy_packet = scapy.IP(packet.get_payload())
    if scapy_packet.haslayer(scapy.Raw):
        if scapy_packet[scapy.TCP].dport == 80:
            print("HTTP Request")
            modified_load = re.sub(r"Accept-Encoding:.*?\\r\\n", r"", str(scapy_packet[scapy.Raw].load))
            new_packet = set_load(scapy_packet, modified_load)
            packet.set_payload(bytes(new_packet))
            print(scapy_packet.show())
        elif scapy_packet[scapy.TCP].sport == 80:
            print("HTTP Response")
            print(scapy_packet.show())
    packet.accept()


queue = netfilterqueue.NetfilterQueue()
queue.bind(0, process_packet)
queue.run()

enter image description here Interpeter python3.9

Ilya
  • 11
  • 1
  • Possible duplicate of [How to recalculate IP checksum with scapy?](https://stackoverflow.com/q/6112913/6843158) – Kate Sep 24 '22 at 19:09

0 Answers0