1

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!

Ray
  • 53
  • 7
  • This problem is already discussed in various other questions, like [How to set linux kernel not to send RST\_ACK, so that I can give SYN\_ACK within raw socket](https://stackoverflow.com/questions/8047728/how-to-set-linux-kernel-not-to-send-rst-ack-so-that-i-can-give-syn-ack-within-r), [Using socket AF_PACKET / SOCK_RAW but tell kernel to not send RST](https://stackoverflow.com/questions/48891727/using-socket-af-packet-sock-raw-but-tell-kernel-to-not-send-rst) and others. – Steffen Ullrich Nov 22 '19 at 06:55

1 Answers1

1

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