为了检查我们的应用服务器中的漏洞,我们运行了 Qualys 扫描。从报告中我们发现我们的应用服务器容易受到慢速 HTTP Post 攻击。为了缓解这种攻击,我们根据 Qualys 报告(https://blog.quallys.com/securitylabs/2011/11/02/how-to-protect-against-slow-http- )在应用服务器前配置了 nginx。攻击)。根据 Qualys 的说法,如果服务器保持连接打开超过 120 秒,他们认为该服务器容易受到慢速 HTTP Post 攻击。尽管 nginx 默认超时是 60 秒,但它在我们的应用服务器中保持连接超过 2 分钟。我们还检查了 nginx 连接状态,它使连接保持在写状态超过 2 分钟。
请帮助我们配置 nginx 以防止慢速 HTTP Post 攻击。
当前的 nginx 配置
user nginx;
worker_processes auto;
worker_rlimit_nofile 102400;
events {
worker_connections 100000;
}
access_log off;
autoindex off;
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=2r/s;
limit_conn_zone $binary_remote_addr zone=limitzone:10m;
limit_conn_status 403;
limit_req_status 403;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 20 15;
client_body_timeout 5s;
client_header_timeout 5s;
send_timeout 2;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
client_body_buffer_size 100K;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream backend {
server 127.0.0.1:8080 max_conns=150;
}
server {
listen 443 ssl http2 default_server;
\# listen [::]:443 ssl http2 default_server;
server_name *******;
underscores_in_headers on;
if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 444;
}
*** ssl configuration ***
.....
location / {
limit_conn limitzone 20;
limit_req zone=req_limit_per_ip burst=5 nodelay;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=strict";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://backend;
}
}