当前位置:网站首页>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
边栏推荐
- NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO
- 【LeetCode】148. 排序链表
- Mathematical analysis_ Notes_ Chapter 3: limits
- 讲座记录《捷联惯导解算的历史及发展》
- How to draw an industry investment map
- AI quantitative transaction (I) -- Introduction to quantitative transaction
- 1. first knowledge of chromatic harmonica
- Communication problems in parent and child components of uniapp
- Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
- 515. 在每个树行中找最大值 / 剑指 Offer II 095. 最长公共子序列
猜你喜欢

NFT insider 63: the sandbox reached a cooperation with Time magazine, and YGG established Spain's subdao

DAP data scheduling function improvement description

How much do you know about the use value of WMS warehouse management system

Nodejs connects to MySQL through heidisql, and ER appears_ BAD_ DB_ ERROR: Unknown database 'my_ db_ books'

什么是存储引擎以及MySQL常见的三种数据库存储引擎

【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。

The 5th series of NFT works of missing parts was launched on the sandbox market platform

讲座记录《惯性导航的新应用——惯性测量》

NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO

Flutter FittedBox组件
随机推荐
SQL, CTE, flg case problems
小心被偷脸!天天用的人脸识别风险原来这么多?
@Requestbody solution get parameter is null
What is the difference between learning code, rolling code and fixed code? The number of repeated codes, coding capacity and the principle of rolling code
Nodejs connects to MySQL through heidisql, and ER appears_ BAD_ DB_ ERROR: Unknown database 'my_ db_ books'
讲座记录《多种空间大地测量技术的数据处理方法和应用》
Color NFT series representing diversity launched on the sandbox market platform
Flutter FittedBox组件
acmStreamOpen返回值问题
1. Phase II of the project - user registration and login
[kubernetes series] installation and use of Helm
Is opencv open source?
Standing wave ratio calculation method
无法安装redis接口
AI quantitative transaction (II) -- tushare financial data framework
地方/園區產業規劃之 “ 如何進行產業定比特 ”
代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
JS arrow function
Summary of various problems encountered by cocos2d-x
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding