TCP SYN cookie的作用、原理、缺陷

SYN Flood 攻击

SYN cookie是用来抵御SYN 攻击的。SYN 攻击就是发很多的SYN给服务器,服务器收到SYN会为每个SYN创建一个TCB(Transmission Control Block),并将其放到半连接队列中。然而系统的半连接队列大小是有限制的(默认1024),如果半连接队列满了,服务器只能丢弃新来的请求了,从而正常的请求无法完成。

SYN Cookie概念

syn cookie究竟存在哪?它的实体就是服务器返回给客户端的ACK+SYN中的seq number。这个序列号本身也是一个信息,syn cookie就是把信息通过序列号作为载体,将一些信息编码到序列号里面了。因为客户端如果是正常的请求,返回的ack一定是seq+1,因此服务器就可以利用这个ack-1再重构出里面的编码信息。
那么 syn cookie究竟编码了哪些信息呢?

SYN cookies are initial sequence numbers that are carefully constructed according to the following rules:

  • let t be a slowly incrementing timestamp (typically time() logically right-shifted 6 positions, which gives a resolution of 64 seconds)
  • let m be the maximum segment size (MSS) value that the server would have stored in the SYN queue entry
  • let s be the result of a cryptographic hash function computed over the server IP address and port number, the client IP address and port number, and the value t. The returned value s must be a 24-bit value.

The initial TCP sequence number, i.e. the SYN cookie, is computed as follows:

Top 5 bits: t mod 32
Middle 3 bits: an encoded value representing m
Bottom 24 bits: s

上面是wiki里面的介绍,说的比较清楚了。
seq一共是32个bit,前5个bit编码的是时间戳,后面3bit是MSS大小,再后面24个bit是双方的ip地址以及端口。

SYN cookie的缺陷

  1. MSS大小只有8个取值(只有3个bit表示)
  2. 加密是比较耗cpu的
  3. 如果客户端的第三次ack丢失的话,由于服务器并没有存连接信息,因此不会重发ACK+SYN。从而导致客户端只能空等一段时间直到超时。

SYN cookie缺陷的克服

有个TCP Cookie Transaction (TCPCT),是一种新的标准,专门克服以上问题
参考:wiki

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值