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: http://www.thice.nl/creating-ack-get-packets-with-scapy/ ).

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: http://lkml.indiana.edu/hypermail/linux/net/0404.2/0021.html, 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.

Asked By: user1177093



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.

Answered By: Mike Pennington

I don’t have a non-iptables answer, but one can fix the reset issue. Instead of trying to filter the outgoing reset in the filter table, filter all of the incoming packets from the target in the raw table instead. This prevents the return packets from the target from even being processed by the kernel, though scapy still sees them. I used the following syntax:

iptables -t raw -A PREROUTING -p tcp --dport <source port I use for scapy traffic> -j DROP

This solution does force me to use the same source port for my traffic; feel free to use your own iptables-fu to identify your target’s return packets.

Answered By: Jeremy Dover

The blog article cited in other answers is not entirely correct. It’s not only that you aren’t completing the three way handshake, it’s that the kernel’s IP stack has no idea that there’s a connection happening. When it receives the SYN-ACK, it sends a RST-ACK because it’s unexpected. Receiving first or last really doesn’t enter into it. The stack receiving the SYN-ACK is the issue.

Using IPTables to drop outbound RST packets is a common and valid approach, but sometimes you need to send a RST from Scapy. A more involved but very workable approach is to go lower, generating and responding to ARP with a MAC that is different from the host’s. This allows you to have the ability to send and receive anything without any interference from the host.

Clearly this is more effort. Personally, I only take this approach (as opposed to the RST dropping approach) when I actually need to send a RST myself.

Answered By: David Hoelzer
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.