简体   繁体   中英

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. 在此处输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM