用scapy和netfilterqueue修改
Modify with scapy and netfilterqueue
我是 运行 Debian Python 2.7,scapy/netfilterqueue。
我在我的 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)。
我是 运行 Debian Python 2.7,scapy/netfilterqueue。
我在我的 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)。