[Python] Getting Error 400 Bad Request when Injecting Code with Scapy

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to implement a code - injector using scapy and netfilterqueue. I am trying to modify the HTTP Requests by removing the "Accept-Encoding: " parameter so the HTML code won't be encrypted. However, when I do, and when I run the program, I get Error 400: Bad Request when I try to access HTTP websites. Below is the full implementation. Why is this happening?

    import netfilterqueue
    import scapy.all as scapy

    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) :
    sp = scapy.IP(packet.get_payload())
    if sp.haslayer(scapy.Raw) and sp.haslayer(scapy.TCP) :
    if sp[scapy.TCP].dport == 80 :
    load = str(sp[scapy.Raw].load)[1:]
    modifed_string = re.sub(r"Accept-Encoding:.*?\\r\\n", "", load)
    new_packet = set_load(sp, modified_string)
    packet.set_payload(bytes(new_packet))
    packet.accept()
    queue = netfilterqueue.NetfilterQueue()
    queue.bind(0, process_packet)
    queue.run()

    Continue reading...

Compartilhe esta Página