★ wanayoo — archive 1999 https://github.com/kti/python-netfilterqueue/issues/29Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not set payload correctly with length changed #29

Open
rhoninzhang opened this issue Mar 21, 2017 · 4 comments
Open

can not set payload correctly with length changed #29

rhoninzhang opened this issue Mar 21, 2017 · 4 comments

Comments

@rhoninzhang
Copy link

@rhoninzhang rhoninzhang commented Mar 21, 2017

after changing the TCP payload, and the length is different, the program is abnormal:

iptables rule in test server:

iptables -A OUTPUT -p TCP -d [test client ip] -j NFQUEUE --queue-num 1

if the length is shorter after changed:
client can receive the modified payload, but the client send a RST connection to server while closing socket

if the length is longer:
client can receive the modified payload, but the server repeatedly to send the packet for several times, and the length looks like not changed via get_payload_len()

if the length is same, just replace content, all behave correctly

could you please help me? thanks, below is the test code:

from netfilterqueue import NetfilterQueue
from scapy.layers.inet import IP,TCP
from scapy.packet import Packet,Raw

def print_and_accept(pkt):
    msg = IP(pkt.get_payload())
    try:
        if msg.haslayer(TCP) and msg.haslayer(Raw):
            print msg[IP].show()
            print pkt.get_payload_len()
            _Data = 'for the hook test'
            msg[TCP].remove_payload()
            msg[TCP].add_payload(_Data)
            #msg[Raw].load = _Data
            #print msg[IP].show()
            msg[IP].len = len(msg)
            del msg[IP].chksum
            del msg[TCP].chksum
            msg = msg.__class__(str(msg))
            pkt.set_payload(str(msg))
            #new_msg = IP(pkt.get_payload())
            #print new_msg[TCP].payload
            #print new_msg[IP].show()
            print msg[IP].show()
            print pkt.get_payload_len()
            pkt.accept()
        else:
            pkt.accept()
    except Exception, err:
        print err
        pkt.accept()

nfqueue = NetfilterQueue()
nfqueue.bind(1, print_and_accept)
try:
    nfqueue.run()
except KeyboardInterrupt:
    print('')
@fripSide
Copy link

@fripSide fripSide commented Apr 12, 2017

We can manually modify the length of packet,
pkt[IP].len = len(pkt)

@svolpe
Copy link

@svolpe svolpe commented Feb 9, 2018

I tried the above example using netcat senting Hello. I see the debug information showing its overwriting 'hello' with 'for the hook test' but the netcat at the other end still recieves 'hello'. why is it not modifying the packet?

@Atiyeh-mohammadkhani
Copy link

@Atiyeh-mohammadkhani Atiyeh-mohammadkhani commented Jun 24, 2018

Hello
what is code doing? >>>msg = msg.class(str(msg))

@Atiyeh-mohammadkhani
Copy link

@Atiyeh-mohammadkhani Atiyeh-mohammadkhani commented Mar 9, 2019

Does this strategy work whit UDP packet? actually I test this for change udp packet size but for size above 1500 It send IP packet whit no source/destination IP address too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.