Ray
Ray

Reputation: 83

Avoiding the RST packet when sending customized tcp packet

I am packing my own tcp packets and send it to another ubuntu machine. SYN and SYN-ACK can be successfully sent and received. However after receiving SYN-ACK, a RST packet is sent. The following is how I use the socket:

SYN:

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
#prepare customized ip header
#prepare customized tcp header
packet = ip_header + tcp_header + user_data
s.sendto(packet, (dest_ip , 0))

ACK for SYN-ACK:

#update the tcp header 
packet = ip_header + tcp_header + user_data
s.sendto(packet, (dest_ip , 0))

After the first SYN is sent and the SYN-ACK is received, the initiating machine will send a RST packet.enter image description here

I am guessing the client socket is closed but am not sure how to confirm and fix that. Thank you in advance!

Upvotes: 4

Views: 1306

Answers (1)

ardalan foroughi pour
ardalan foroughi pour

Reputation: 83

The problem is that the OS has a feature that when it gets a TCP packet to an unknown socket, it sends a RST back to the originator. This link explains it and how to solve it.

https://widu.tumblr.com/post/43624355124/suppressing-tcp-rst-on-raw-sockets

Upvotes: 2

Related Questions