Modify with scapy and netfilterqueue

随声附和 提交于 2019-12-08 04:54:52

问题


I'm running Debian with Python 2.7, and scapy/netfilterqueue.

I've added the following in my iptables:

iptables -A OUTPUT -p tcp --dport 5678 -j NFQUEUE --queue-num 1

And this is my code for getting HTTP packages and changing URL and 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

Running the code does retrieve the correct packages, and it seems the .dst and .dport is changed, but I'm getting the following error:

Exception socket.gaierror: gaierror(-2, 'Name or service not known') in 'netfilterqueue.global_callback' ignored

I'm kinda stuck...


回答1:


Just change pkt.dst = 'https://my-secure-domain.com' to pkt[IP].dst = 'my-secure-domain.com' (that's the IP destination, not a URL).



来源:https://stackoverflow.com/questions/46645142/modify-with-scapy-and-netfilterqueue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!