我正在用Python 2.7和scapy / netfilterqueue运行Debian。
我在iptables中添加了以下内容:
iptables -A OUTPUT -p tcp --dport 5678 -j NFQUEUE --queue-num 1
这是我的代码,用于获取HTTP包以及更改URL和PORT:
#! /usr/bin/env python2.7
from scapy.all import *
from netfilterqueue import NetfilterQueue
def modify(packet):
pkt = IP(packet.get_payload())
if pkt.haslayer(TCP) and pkt.getlayer(TCP).dport == 5678:
pkt.dst = 'https://my-secure-domain.com'
pkt.dport = 443
del pkt[IP].chksum
del pkt[TCP].chksum
packet.set_payload(str(pkt))
packet.accept()
nfqueue = NetfilterQueue()
nfqueue.bind(1, modify)
try:
print "[*] waiting for data"
nfqueue.run()
except KeyboardInterrupt:
pass
运行代码确实会检索正确的程序包,并且
.dst
和.dport
似乎已更改,但是出现以下错误:Exception socket.gaierror: gaierror(-2, 'Name or service not known') in 'netfilterqueue.global_callback' ignored
我有点卡住...
最佳答案
只需将pkt.dst = 'https://my-secure-domain.com'
更改为pkt[IP].dst = 'my-secure-domain.com'
(这是IP目的地,而不是URL)。
关于python - 用scapy和netfilterqueue进行修改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46645142/