Created
August 12, 2023 16:09
-
-
Save scysys/b5eff3cb1703cde07c7cac847266b7d9 to your computer and use it in GitHub Desktop.
Packet Payload Modification for Network Traffic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from netfilterqueue import NetfilterQueue | |
import scapy.all as scapy | |
# Configuration variables | |
original_keyword = b"search" | |
modified_keyword = b"replace" | |
def modify_packet(packet): | |
scapy_packet = scapy.IP(packet.get_payload()) | |
if scapy_packet.haslayer(scapy.Raw): | |
packet_payload = scapy_packet[scapy.Raw].load | |
new_payload = packet_payload.replace(original_keyword, modified_keyword) | |
scapy_packet[scapy.Raw].load = new_payload | |
packet.set_payload(bytes(scapy_packet)) | |
print("Original payload:", packet_payload) | |
print("Modified payload:", new_payload) | |
packet.accept() | |
nfqueue = NetfilterQueue() | |
nfqueue.bind(0, modify_packet) | |
try: | |
nfqueue.run() | |
except KeyboardInterrupt: | |
print("Flushing iptables rules...") | |
nfqueue.unbind() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iptables -I INPUT -p tcp --dport 80 -j NFQUEUE --queue-num 0