Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python、Scapy和Netfilterqueue只截获从客户端到服务器的HTTP数据包_Python_Http_Iptables_Scapy - Fatal编程技术网

Python、Scapy和Netfilterqueue只截获从客户端到服务器的HTTP数据包

Python、Scapy和Netfilterqueue只截获从客户端到服务器的HTTP数据包,python,http,iptables,scapy,Python,Http,Iptables,Scapy,我正试图编写一个python脚本,截获Linux机器上eth0接口的所有HTTP请求 我只能看到从客户端发送到服务器的HTTP数据包(例如192.168.1.201->151.101.1.69),但我从未看到从服务器发送到客户端的HTTP数据包(例如151.101.1.69->192.168.1.201) 这是完整的python脚本 运行时,它只传递以下条件: if http_packet[TCP].dport == 80: if http_packet[TCP].sport == 80:

我正试图编写一个python脚本,截获Linux机器上eth0接口的所有HTTP请求

我只能看到从客户端发送到服务器的HTTP数据包(例如192.168.1.201->151.101.1.69),但我从未看到从服务器发送到客户端的HTTP数据包(例如151.101.1.69->192.168.1.201)

这是完整的python脚本

运行时,它只传递以下条件:

if http_packet[TCP].dport == 80:
if http_packet[TCP].sport == 80:
并且它不会在以下条件下传递:

if http_packet[TCP].dport == 80:
if http_packet[TCP].sport == 80:
谢谢

# 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

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()

问题是由于在启动此脚本之前发出的“arpsopof”命令。
ARPSOPOF命令正在为要拦截的网络数据包创建筛选器。

Hi&欢迎使用Stackoverflow。请把你的问题集中在一个问题上:说“它不起作用,这是我的全部代码”不会有多大帮助。你的平台是什么?什么部分中断(Python?iptables?)您尝试过什么?。。。。。你可能想看看,快乐黑客!