user1177093 user1177093 - 2 years ago 302
Python Question

Unwanted RST TCP packet with Scapy

In order to understand how TCP works, I tried to forge my own TCP SYN/SYN-ACK/ACK (based on the tutorial: ).

The problem is that whenever my computer recieve the SYN-ACK from the server, it generates a RST packet that stops the connection process.

I tried on a OS X Lion and on a Ubuntu 10.10 Maverick Meerkat, both reset the connection. I found this:, I don't know if it is the reason.

Does anyone could tell me what could be the reason? And how to avoid this problem?

Thank you.

Answer Source

The article you cited makes this pretty clear...

Since you are not completing the full TCP handshake your operating system might try to take control and can start sending RST (reset) packets, to avoid this we can use iptables:

iptables -A OUTPUT -p tcp --tcp-flags RST RST -s -j DROP

Essentially, the problem is that scapy runs in user space, and the linux kernel will receive the SYN-ACK first. The kernel will send a RST because it won't have a socket open on the port number in question, before you have a chance to do anything with scapy.

The solution (as the blog mentions) is to firewall your kernel from sending a RST packet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download