当前位置:网站首页>A detailed summary of TCP connection triple handshake
A detailed summary of TCP connection triple handshake
2022-06-25 04:27:00 【Life is sweet and good luck is good】
Three handshakes :
Client state at start :CLOSED Server status at start :LISTEN | The first handshake | The second handshake | The third handshake |
From A to B | client → The server | The server → client | client → The server |
state | client : CLOSED → SYN_SENT | The server : LISTEN→ SYN_RCVD | client : SYN_SENT → ESTABLISHED Server received ACK After the message : SYN_RCVD → ESTABLISHED |
Message name | SYN Connection request message | SYN-ACK Connection confirmation message | ACK message |
What (TCP Sign a ) | SYN = 1, ACK = 0 Initial serial number (ISN):seq = x | SYN = 1,ACK = 1 Confirmation no. = Client initial serial number (ISN)+ 1: ack = x + 1 seq = y | ACK = 1 Confirmation no. = Server initial serial number (ISN)+ 1:ack = y + 1 seq = x + 1( Client initial seq = x, Send a SYN A sequence number is consumed after the message , So this is the second message segment , The serial number is x + 1) |
Consumption serial number ? | Consume 1 A serial number | Don't consume | If you carry data , Consumption . If you do not carry data, you will not consume . |
What does it mean |
| It indicates that the server has received the from the client SYN | Indicates that the client has received the server's SYN.
|
Whether the message can carry data ? | You can't | You can't | can |
Semi and full connection queues |
| The server receives the client's SYN-ACK After the connection confirmation message , The server is in SYN_RCVD state , The two sides have not yet fully established a connection , The server puts the connection requests in this state in the semi connection queue . If SYN The semi connection queue is full , Can only drop connections ? It's not like that . Turn on syncookies The function can be used without using SYN In case of queue, the connection is successfully established .syncookies That's what it does : The server calculates a value based on the current state , Put it on your own side SYN+ACK Send out in a message , When the client returns ACK When the message , Take out the value to verify , If the legitimate , Think the connection is successful . | The server receives a message from the client ACK After the confirmation , Complete three handshakes ,TCP Connection is established . The established connection is put in the full connection queue . When the full connection queue is full, packet loss may occur . |
What if the handshake fails ? | The client sends SYN Opened three handshakes , After that, the status of the client connection is SYN_SENT, Then wait for the server to reply ACK message . Under normal circumstances , The server will return in a few milliseconds ACK, But if the client does not receive it for a long time ACK What will happen ? The client will resend SYN, The number of retries is determined by tcp_syn_retries Parameter control , The default is 6 Time . | When the third handshake fails , The server does not retransmit ACK message , It's a direct delivery RST Message segment , Get into CLOSED state . The purpose of this is to prevent SYN Flooding attack . | |

Why do I need three handshakes ?( What is the purpose of the three handshakes ? Can you use two handshakes to achieve the same goal ?)
| The first handshake | The second handshake | The third handshake |
The purpose of the three handshakes : | 1. Confirm whether the receiving capacity and sending capacity of both parties are normal 2. Specify initialization serial number , Prepare for reliable transmission in the future . | ||
Operations performed | Client sends packets , The server receives a packet | Server , The client received the package | Client sends packets , The server receives a packet |
who , What's the conclusion ? | Server knows , The sending capacity of the client and the receiving capacity of the server are normal . | The client knows , Receiving and sending of the client ok Receiving and sending of the server ok | Server knows , The receiving capacity and sending capacity of the client ok, The receiving and sending capacity of the server ok
|
Therefore, three handshakes are required to confirm whether the receiving and sending capabilities of both parties are normal . | |||
Can I carry data during the three handshakes ?
Only the third handshake can carry data .
Why do things turn out like this? ?
If the first handshake can carry data , It will make the server more vulnerable to attack .
If the first handshake can carry data , If someone maliciously attacks the server , In the first handshake SYN Connection request message Put a lot of data in . Because the attacker does not care whether the sending and receiving capabilities of the server are normal , When the client madly repeats sending SYN Connection request message , It will make the server spend a lot of time and space to receive these messages .
The third handshake , The client is already in ESTABLISHED state . For the client , He has established a connection , And we already know the server's reception 、 The ability to send is normal , So there's nothing wrong with being able to carry data .
What is? SYN( Sync serial number :Synchronize Sequence Numbers) attack ?
SYN The attack is that the client forges a large number of nonexistent in a short time IP Address , And send it to the server continuously SYN Connection request message , Server reply confirmation package , And wait for the client to confirm . Because the source address does not exist , Therefore, the server must constantly resend SYN-ACK Connection confirmation message Until the timeout . These fake SYN The package will take up... For a long time Semi connected queues , Cause normal SYN The connection request message is discarded because the queue is full , Therefore, the network is congested and even the system is paralyzed .
How to detect SYN attack ? Or say SYN What is the performance of the attack ?
When you see a large number of semi connected states on the server , And the source IP The address is random , Basically, it can be concluded that this is a SYN attack .
Common defense SYN What are the methods of attack ?
(1) Shorten the timeout time (SYN Timeout)
(2) Increase the maximum number of half connections
(3) Filtering Gateway protection
(4)SYN cookies technology
Refer to the post :https://yuanrengu.com/2020/77eef79f.html
边栏推荐
- Retrofit source code analysis
- 讲座记录《多种空间大地测量技术的数据处理方法和应用》
- Retrofit 源码分析
- La gamme NFT Color, qui représente la diversité, est en ligne sur la plate - forme du marché Sandbox
- 2020.3.3 notes async/await and promise and Then processes and threads
- @RequestBody解决获取参数为null
- Simple integration of client go gin 11 delete
- Hello CTP (I) - basic knowledge of futures
- Laravel document sorting 1. Installation and Preliminary Configuration
- Can Navicat directly operate the Android database SQLite
猜你喜欢

数字时代的“文艺复兴”?起底数字藏品,让人欢喜让人愁

【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
![Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding](/img/ad/69fce7cf064479a0ddd477fb935de2.png)
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding

How to draw an industry investment map

Failed to install redis interface

Hello CTP (II) -- Introduction to CTP

《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台

讲座记录《捷联惯导解算的历史及发展》

Text keyword extraction: ansj

Watch out for the stolen face! So many risks of face recognition used every day?
随机推荐
BSC smart contract dividend mainstream currency | including marketing wallet | deflation | reflow | dividend free token | available for direct deployment
Numpy NP tips: squeeze and other processing of numpy arrays
Simple integration of client go gin 11 delete
EasyRecovery15非常好用的电脑数据恢复软件
How much do you know about the use value of WMS warehouse management system
升级cmake
5 key indicators of SEO: ranking + traffic + session + length of stay + bounce rate
CMD operation MySQL in Windows
【Kubernetes系列】Helm的安装使用
i. Max development board learning record
地方/園區產業規劃之 “ 如何進行產業定比特 ”
讲座记录《多种空间大地测量技术的数据处理方法和应用》
如何筛选出和产品相关的词,精准排除掉无效词
Retrofit 源码分析
UCLA | 用于黑盒优化的生成式预训练
Coinlist queuing tutorial to improve the winning rate
PHP extracts and analyzes table contents, and collects bidding information
Color NFT series representing diversity launched on the sandbox market platform
Comparison of towe/ JIRA / tapd / Zen collaboration platforms
"Renaissance" in the digital age? The bottom digital collection makes people happy and sad