Click here to Skip to main content
14,336,379 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
[+] Request >>
Exception TypeError: "'module' object has no attribute '__getitem__'" in 'netfilterqueue.global_callback' ignored

Exception IndexError: IndexError('Layer [TCP] not found',) in 'netfilterqueue.global_callback' ignored

These two errors come while executing my python code given:

What I have tried:

#!/usr/bin/env python
import netfilterqueue
import scapy.all as scapy
import re

def set_load(packet, load):
scapy[scapy.Raw].load = load
del packet[scapy.IP].chksum
del packet[scapy.IP].len
del packet[scapy.TCP].chksum
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("[+] Request >>")
modified_load = re.sub("Accept-Encoding:.*?\\r\\n", "", scapy_packet[scapy.Raw].load)
new_packet = set_load(scapy_packet, modified_load)
packet.set_payload(str(new_packet))
elif scapy_packet[scapy.TCP].sport == 80:
print("[+] Response >>")
print(scapy_packet.show())

packet.accept()

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

queue.run()
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100