如何从Nginx日志中挖掘系统潜在的慢速渗透和低频扫描行为?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1076个文字,预计阅读时间需要5分钟。
直接观察日志中那些不明显但反复出现的请求模式,比盲目大量攻击更有效。缓慢渗透和低频扫描,往往刻意压低频率、拉长时间、伪装成正常行为,常规监控易被忽视,但+Nginx+日志留下清晰轨迹——关键在于聚焦时间维度、请求路径特征和客户端行为的一致性。
盯住 request_time 和 upstream_response_time 的异常组合
慢速渗透(如 Slowloris、R.U.D.Y.)或低频探测(如逐个试探 admin/backup/.git/ 等敏感路径),常表现为:
– request_time 显著高于 upstream_response_time(例如 request_time=8.2s,upstream_response_time=0.012s):说明请求在 Nginx 层卡住,可能是客户端缓慢发包或故意拖延;
– upstream_response_time 高但 request_time 并不高(例如 upstream_response_time=4.5s,request_time=4.6s):上游服务被拖慢,可能因恶意构造的查询触发数据库深度遍历或正则回溯;
– 同一 IP 在数分钟内多次出现 request_time > 3s 的请求,但状态码均为 200 或 404,无明显错误日志。
可用命令快速筛查:
- awk '$NF ~ /request_time=[0-9]+\.[0-9]+/ {for(i=1;i 3) print $0}}' /var/log/nginx/access.log
- awk '{for(i=1;i 2) print $1, $4, $7, $9, $i}}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10
识别低频路径扫描的语义特征
攻击者为规避 WAF 和日志告警,常将扫描拆成单次/小时级请求,路径却暴露意图:
– 同一 IP 在 24 小时内访问过 /phpmyadmin/、/.env、/wp-config.php、/robots.txt、/backup.zip、/api/v1/users?id=1%20OR%201=1 等典型敏感路径或注入载荷;
– 请求中包含大量编码字符(如 %2e%2e%2f)、重复斜杠(//)、空格绕过(GET%20/admin HTTP/1.1);
– User-Agent 异常简短(如 “-”、“sqlmap”、“gobuster”)或与浏览器指纹严重不符(如声称 Chrome 却无 Accept 头)。
实操建议:
- 用 awk -F'"' '{print $2, $6}' access.log | grep -E '(\.env|phpmyadmin|\.git|backup\.|wp-config|robots\.txt)' | awk '{print $1}' | sort | uniq -c | sort -nr 汇总可疑路径访问源
- 对 Referer 为空、且请求路径含 SQL 关键字的请求做标记:awk '$4 ~ /\?/ && ($2 ~ /select|union|sleep|benchmark|order by|information_schema/ || $6 ~ /"-"$/) {print $0}' access.log
关联 IP 行为:从单次异常到长期画像
单次慢请求未必是攻击,但持续数天的“低频+高时延+多路径试探”就是强信号。需跳出单条日志,构建 IP 维度行为基线:
- 统计每个 IP 的 日均请求数、平均 request_time 中位数、404 路径多样性(不同 URL 数/总请求数)、含特殊编码路径占比
- 筛选出:日均请求 60%,且至少 3 次 request_time > 2s 的 IP —— 这类 IP 很可能在手工探测或使用轻量扫描器
- 命令示例:awk '{ip[$1]++; time[$1]+=$NF; cnt[$1]++; if($9==404) notfound[$1]++} END {for (i in ip) {if(notfound[i]/cnt[i]>0.6 && time[i]/cnt[i]>2) print i, cnt[i], notfound[i]/cnt[i]*100 "%", time[i]/cnt[i]}}' access.log | sort -k4 -nr
结合错误日志交叉验证
慢速攻击常伴随 Nginx 层超时或连接异常,这些不会出现在 access.log,但在 error.log 有记录:
- 搜索 upstream timed out、client timed out、no live upstreams、recv() failed 等关键词,提取对应 client IP
- 再回查 access.log 中该 IP 是否存在长时间 request_time、重复试探、或异常 User-Agent —— 若两者时间窗口重叠,基本可确认为慢速渗透尝试
- 特别注意 2026年5月起高频出现的 “client sent invalid request” 报错,部分新型模糊测试工具会发送畸形 HTTP/2 帧触发此错误,需检查是否集中于某几个 IP
本文共计1076个文字,预计阅读时间需要5分钟。
直接观察日志中那些不明显但反复出现的请求模式,比盲目大量攻击更有效。缓慢渗透和低频扫描,往往刻意压低频率、拉长时间、伪装成正常行为,常规监控易被忽视,但+Nginx+日志留下清晰轨迹——关键在于聚焦时间维度、请求路径特征和客户端行为的一致性。
盯住 request_time 和 upstream_response_time 的异常组合
慢速渗透(如 Slowloris、R.U.D.Y.)或低频探测(如逐个试探 admin/backup/.git/ 等敏感路径),常表现为:
– request_time 显著高于 upstream_response_time(例如 request_time=8.2s,upstream_response_time=0.012s):说明请求在 Nginx 层卡住,可能是客户端缓慢发包或故意拖延;
– upstream_response_time 高但 request_time 并不高(例如 upstream_response_time=4.5s,request_time=4.6s):上游服务被拖慢,可能因恶意构造的查询触发数据库深度遍历或正则回溯;
– 同一 IP 在数分钟内多次出现 request_time > 3s 的请求,但状态码均为 200 或 404,无明显错误日志。
可用命令快速筛查:
- awk '$NF ~ /request_time=[0-9]+\.[0-9]+/ {for(i=1;i 3) print $0}}' /var/log/nginx/access.log
- awk '{for(i=1;i 2) print $1, $4, $7, $9, $i}}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10
识别低频路径扫描的语义特征
攻击者为规避 WAF 和日志告警,常将扫描拆成单次/小时级请求,路径却暴露意图:
– 同一 IP 在 24 小时内访问过 /phpmyadmin/、/.env、/wp-config.php、/robots.txt、/backup.zip、/api/v1/users?id=1%20OR%201=1 等典型敏感路径或注入载荷;
– 请求中包含大量编码字符(如 %2e%2e%2f)、重复斜杠(//)、空格绕过(GET%20/admin HTTP/1.1);
– User-Agent 异常简短(如 “-”、“sqlmap”、“gobuster”)或与浏览器指纹严重不符(如声称 Chrome 却无 Accept 头)。
实操建议:
- 用 awk -F'"' '{print $2, $6}' access.log | grep -E '(\.env|phpmyadmin|\.git|backup\.|wp-config|robots\.txt)' | awk '{print $1}' | sort | uniq -c | sort -nr 汇总可疑路径访问源
- 对 Referer 为空、且请求路径含 SQL 关键字的请求做标记:awk '$4 ~ /\?/ && ($2 ~ /select|union|sleep|benchmark|order by|information_schema/ || $6 ~ /"-"$/) {print $0}' access.log
关联 IP 行为:从单次异常到长期画像
单次慢请求未必是攻击,但持续数天的“低频+高时延+多路径试探”就是强信号。需跳出单条日志,构建 IP 维度行为基线:
- 统计每个 IP 的 日均请求数、平均 request_time 中位数、404 路径多样性(不同 URL 数/总请求数)、含特殊编码路径占比
- 筛选出:日均请求 60%,且至少 3 次 request_time > 2s 的 IP —— 这类 IP 很可能在手工探测或使用轻量扫描器
- 命令示例:awk '{ip[$1]++; time[$1]+=$NF; cnt[$1]++; if($9==404) notfound[$1]++} END {for (i in ip) {if(notfound[i]/cnt[i]>0.6 && time[i]/cnt[i]>2) print i, cnt[i], notfound[i]/cnt[i]*100 "%", time[i]/cnt[i]}}' access.log | sort -k4 -nr
结合错误日志交叉验证
慢速攻击常伴随 Nginx 层超时或连接异常,这些不会出现在 access.log,但在 error.log 有记录:
- 搜索 upstream timed out、client timed out、no live upstreams、recv() failed 等关键词,提取对应 client IP
- 再回查 access.log 中该 IP 是否存在长时间 request_time、重复试探、或异常 User-Agent —— 若两者时间窗口重叠,基本可确认为慢速渗透尝试
- 特别注意 2026年5月起高频出现的 “client sent invalid request” 报错,部分新型模糊测试工具会发送畸形 HTTP/2 帧触发此错误,需检查是否集中于某几个 IP

