什么是慢速连接攻击
缓慢的http拒绝服务攻击是一种专门针对于web的应用层拒绝服务攻击,攻击者操纵网络上的肉鸡,对目标web服务器进行海量http请求攻击,直到服务器带宽被打满,造成了拒绝服务。(瘫痪目标服务器)
慢速连接攻击类型
慢速连接攻击主要有如下几种:
1.slow headers攻击
攻击者向服务器发起http请求,而且不停地发送http头部。服务器为需要接收完所有http头部,才能处理请求。由于http头部不停地被攻击者发送,服务器永远也无法接收完,服务器的web容器很快就会被攻击者占满了tcp连接,而不再接收新的请求,最终拒绝服务。
2.slow body攻击
攻击者向目标服务器发送post请求,服务器以为要接收大量数据,一直保持连接状态,但攻击者却以10s-100s一个字节的速度去发送数据,类似的连接被不断增加后,服务器资源被大量消耗,最终达到极限拒绝服务。
3.slow read攻击
攻击者与服务器建立连接后,会发送完整的请求给服务器,一直保持连接状态,然后以极低的速度读取response,或者让服务器觉得客户端很忙,消耗服务器的连接和内存资源。
防护手段
真对http慢速攻击的特点,防护时可对每秒钟http并发连接数进行检查。
当每秒种http并发连接数超过设定值时,会触发http报文检查,检查出一下任意一种情况,都认定受到http慢速连接攻击。
1.连续多个httppost报文的总长度都很大,但是其http载荷长度都很小。
2.连续多个httpget/post报文的报文头都没有结束标识。
将该源ip判定为攻击源加入黑名单,同时断开此ip地址与http服务器的连接。
对web服务器的http头部传输的最大许可时间进行限制,修改成最大许可时间为20秒。
统计每个tcp连接的时长并计算单位时间内通过的报文数量即可做精确识别。一个tcp连接中,http报文太少和报文太多都是不正常的,过少可能是慢速连接攻击。
过多可能是使用http 1.1协议进行dehttp flood攻击,在一个tcp连接中发送多个http请求。
周期内统计报文数量。一个tcp连接,http请求的报文中,报文过多或者报文过少都是有问题的,如果一个周期内报文数量非常少,那么它就可能是慢速攻击;如果一个周期内报文数量非常多,那么它就可能是一个cc攻击。
限制http请求头的最大许可时间。超过最大许可时间,如果数据还没有传输完成,那么它就有可能是一个慢速攻击。
nginx
1、通过调整$request_method,配置服务器接受http包的操作限制;
2、在保证业务不受影响的前提下,调整client_max_body_size, client_body_buffer_size, client_header_buffer_size,large_client_header_buffersclient_body_timeout, client_header_timeout的值,必要时可以适当的增加;
3、对于会话或者相同的ip地址,可以使用httplimitreqmodule and httplimitzonemodule参数去限制请求量或者并发连接数;
4、根据cpu和负载的大小,来配置worker_processes 和 worker_connections的值,公式是:max_clients = worker_processes * worker_connections。
具体配置
user deployer;
user root;
worker_processes 16;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
limit_req_zone $binary_remote_addr zone=req_one:10m rate=10r/s;
limit_conn_zone $binary_remote_addr zone=limit_conn:10m;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_max_body_size 2m;
client_body_buffer_size 2m;
client_header_buffer_size 2k;
large_client_header_buffers 2 1k;
client_body_timeout 10s;
client_header_timeout 5s;
#gzip on;
server {
listen 10056;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
limit_conn limit_conn 10;
proxy_redirect off;
proxy_set_header host $host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_pass http://172.17.0.1:10050;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
以上就是nginx解决http慢攻击(slow http attack)的方法的详细内容,更多关于nginx解决http慢攻击的资料请关注代码网其它相关文章!
发表评论