【发布时间】:2016-07-30 05:11:28
【问题描述】:
我想使用 netfilterqueue(0.6 - 最新)和 scapy 用我的值更改“主机”标头。这是我的 iptables 规则:
iptables -A OUTPUT -p tcp --dport 80 -j NFQUEUE --queue-num 0
我有我的代码:
from netfilterqueue import *
from scapy.all import *
def change(pkt):
scapy_pkt = IP(pkt.get_payload())
if scapy_pkt.haslayer(TCP) and scapy_pkt.getlayer(TCP).dport == 80 and scapy_pkt.haslayer(Raw):
http_content = scapy_pkt.getlayer(Raw).load
list_of_headers = http_content.split("\r\n")
new_headers = []
for i in list_of_headers:
if "Host" in i:
new_headers.append("Host: google.pl")
else:
new_headers.append(i)
pkt.set_payload("\r\n".join(new_headers))
pkt.accept()
nfqueue = NetfilterQueue()
nfqueue.bind(0, change)
try:
nfqueue.run()
except KeyboardInterrupt:
print
但它不起作用..我不知道为什么.. 我在更改之前和之后打印标题,唯一的更改是“主机”标题。 Soo..为什么它不起作用?有人有什么想法吗? :)
我使用 CURL 进行测试,使用wireshark 进行调试。请求未发送。我在wireshark中找不到。
编辑: 我试图解决这个问题,我将代码更改为:
from netfilterqueue import *
from scapy.all import *
def change(pkt):
scapy_pkt = IP(pkt.get_payload())
print dir(pkt);
if scapy_pkt.haslayer(TCP) and scapy_pkt.getlayer(TCP).dport == 80 and scapy_pkt.haslayer(Raw):
#http_content = scapy_pkt.getlayer(Raw).load
#list_of_headers = http_content.split("\r\n")
#new_headers = []
#for i in list_of_headers:
# if "Host" in i:
# new_headers.append("Host: google.pl")
# else:
# new_headers.append(i)
scapy_pkt.dst = 'google.pl'
del scapy_pkt[IP].chksum
del scapy_pkt[TCP].chksum
pkt.set_payload(str(scapy_pkt))
pkt.accept()
nfqueue = NetfilterQueue()
nfqueue.bind(0, change)
try:
nfqueue.run()
except KeyboardInterrupt:
print
但它仍然无法正常工作。在 Wireshark 中,我使用 HTTP 进行过滤。但是当我通过 TCP 和 destport == 80 进行过滤时,我可以看到包,但目标是从传递给 CURL 的参数到 IP,而不是我在上面的代码中注入数据包的 IP。
感谢您的提前:)
【问题讨论】: