惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
C
Cisco Blogs
The Hacker News
The Hacker News
T
Threatpost
S
Schneier on Security
K
Kaspersky official blog
Spread Privacy
Spread Privacy
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
NISL@THU
NISL@THU
量子位
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
V
V2EX
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
L
LangChain Blog
W
WeLiveSecurity
Cloudbric
Cloudbric

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法 券商费率调整记 迷你主机组装记 Labwc更换定制皮肤 树莓派跑分流代理 实用自动代理配置示例 九年老鼠标复活记 Openvpn示例 Mac下如何旋转webp图片 如何隐藏Vscode中Markdown PDF插件的头部内容 解决Linux下网络配置无法变更保存的问题 labwc环境启用wlogout Ubuntu下新官方微信尝鲜 简单检测用户是否开启广告屏蔽 Atuin ZFS下卡顿问题解决 Wine安装64位微信 Fish 和 Atuin使用记 Fastapi简单实现临时下载链接 Fastapi微信公众号开发简要 Hugo根据语种展示不同内容 如何修复Waybar微信图标错误 信封加密简要 Linux环境下维护公众号记录 快速隐藏和呼出终端 Wayland环境自动切换壁纸 SuperTuxKart 试玩 简单抓取雪球股票快讯 为什么你的kill命令不能列出信号表 Wine安装微信保姆教程 Hysteria科学上网简要 Ubuntu 23.10 钉钉无法启动解决方法 网站导航栏防止插入Adsense自动广告 Linux环境按键检测 Hugo文末添加最后修改时间 Wayland环境ksnip无法复制问题解决 我眼中的股票市场 Caddy简单图片防盗链 greetd和regreet使用教程 Wayland环境下截图加后期修改 Wayland 环境下gif录屏 Firefox的一些有趣功能 Ubuntu 切换系统语言 Firefox 标题栏高度调整 网站添加回到顶部功能 Hugo自定义字体 Labwc 便捷配置 Wofi使用教程 窗口管理器labwc使用记 文件共享软件Dufs推荐 Hugo静态站点接入Adsense广告 Fcitx5配置详解 Ubuntu安装chrome的方法总结 一种Xterm.js的全屏方案 Google网址收录api Python示例 手机听离线音乐 Snipe it资产导入 应用启动器yofi使用配置 Snipe it资产管理系统安装使用 Ubuntu开机启动加速 Vue3 vite TypeScript跨域等相关设置 Ubuntu手动升级Libreoffice Ubuntu设置alacritty为默认终端 简体文章批量转换为繁体 使用Inkscape调整svg图片大小 实用命令 使用mitmproxy给手机app抓包 Python中rstrip方法细解 Github同主机多仓库部署deploy key问题处理 Linux安装最新版本Python KeePassXC使用教程 Ubuntu 22.10连接蓝牙耳机报错br-connection-profile-unavailable解决方法 Caddy日志配置轮转和格式化
个人网站安全防护
2026-01-30 · via mephisto.cc

前阵子提到给网站接入日志监控后,发现每天都有人恶意扫描,扫描后一大堆 404 的访问记录,浪费带宽不说,还影响我排错,网络世界很险恶,总有刁民想害朕。

以前我只是简单部署了个 fail2ban 防止 ssh 爆破,无奈又加上日志分析。

类似这样,每天能抓到 10 多个恶意 ip。

1root@tokyo:~# cat /etc/fail2ban/filter.d/caddy-json-scan.conf
2[Definition]
3# 匹配 status=404 且 uri 以 .php、.cgi、.pl 等结尾的请求
4# 提取 remote_addr 中的 IP(自动忽略端口)
5failregex = ^.*"remote_ip":"<HOST>".*"uri":"[^"]*\.(?i:php|cgi|pl|asp)[^"]*".*"status":404.*
6ignoreregex =

这样写正则表达式,碰到那些扫描压缩包的又不行了。比如很多攻击会扫描.zip/.tar/.gz 等,HEAD 请求,再写一次匹配规则很繁琐。

而且 fail2ban 内存占用较多,测试命中结果慢,只能寻找替代方案。

搜了下 CrowdSec 能担当起这个责任,它是一个开源的、基于社区协作的网络安全工具,用于检测和阻止恶意行为(如暴力破解、扫描、Web 攻击等)。其通过分析日志文件实时识别可疑 IP 地址,并可与全球用户共享威胁情报(在用户同意的前提下),从而形成一个“集体免疫”式的防御网络。解析 Caddy 日志、SSH/FTP 暴力破解防御等也不在话下,感觉很适合个人使用。

1. CrowdSec

安装使用很简单:

1curl -s https://install.crowdsec.net | sudo bash
2sudo apt update
3sudo apt list --upgradable
4sudo apt install crowdsec -y
5sudo apt install crowdsec-firewall-bouncer-nftables -y

其中的 crowdsec-firewall-bouncer-nftables 是 CrowdSec 官方提供的一个 bouncer(拦截器),用于将 CrowdSec 检测到的恶意 IP 地址自动添加到 Linux 的 nftables 防火墙规则中,从而实现网络层的实时封禁。

安装的过程中,CrowdSec 会自动识别你系统有哪些服务(比如 Postgres、sshd、Nginx 等),自动加载对应的防护模块,相比 fail2ban 手编正则还是方便不少。

也就是说,恶意 ip 被检测到后,访问请求包就被系统丢弃了,根本不会到达 Caddy 服务,恶意扫描记录会大幅减少。bouncer 也可以在应用层级来做,比如 Caddy 就有对应的拦截器:https://github.com/hslatman/caddy-crowdsec-bouncer, 意思就是在 webserver 层级进行拦截,相比系统拦截,能进行更多定制化操作。

我比较痛恨这些恶意扫描的,直接就系统级丢弃了。每个月主机厂商都会准时给我账单,开站不赚钱好心为人民服务还被攻击,换谁都不乐意。

看下面的输出,感受下这个世界的邪恶:

 1root@tokyo:~#  cscli decisions list
 2╭────────┬──────────┬────────────────────┬───────────────────────────────────┬────────┬─────────┬─────────────────────────────────────────────┬────────┬────────────┬──────────╮
 3│   ID   │  Source  │     Scope:Value    │               Reason              │ Action │ Country │                      AS                     │ Events │ expiration │ Alert ID │
 4├────────┼──────────┼────────────────────┼───────────────────────────────────┼────────┼─────────┼─────────────────────────────────────────────┼────────┼────────────┼──────────┤
 5300360 │ crowdsec │ Ip:101.47.161.84   │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 28     │ 3h53m54s   │ 549 6300359 │ crowdsec │ Ip:101.47.162.19   │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 27     │ 3h53m22s   │ 548 7300358 │ crowdsec │ Ip:221.14.65.92    │ crowdsecurity/http-probing        │ ban    │ CN      │ 4837 CHINA UNICOM China169 Backbone         │ 12     │ 3h49m40s   │ 546 8300357 │ crowdsec │ Ip:122.192.133.100 │ crowdsecurity/http-bad-user-agent │ ban    │ CN      │ 4837 CHINA UNICOM China169 Backbone         │ 2      │ 3h45m54s   │ 545 9300356 │ crowdsec │ Ip:198.98.57.141   │ crowdsecurity/ssh-slow-bf         │ ban    │ US      │ 53667 PONYNET                               │ 14     │ 3h35m44s   │ 54310285355 │ crowdsec │ Ip:45.78.194.178   │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 31     │ 3h3m16s    │ 53811285354 │ crowdsec │ Ip:92.118.39.76    │ crowdsecurity/ssh-slow-bf         │ ban    │ US      │ 47890 Unmanaged Ltd                         │ 19     │ 3h2m50s    │ 53712285353 │ crowdsec │ Ip:45.78.219.42    │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 24     │ 2h53m55s   │ 53513285352 │ crowdsec │ Ip:45.78.229.72    │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 16     │ 2h45m33s   │ 53414285351 │ crowdsec │ Ip:173.249.50.59   │ crowdsecurity/ssh-slow-bf         │ ban    │ FR      │ 51167 Contabo GmbH                          │ 15     │ 2h43m43s   │ 53315285350 │ crowdsec │ Ip:159.89.143.86   │ crowdsecurity/ssh-slow-bf         │ ban    │ US      │ 14061 DIGITALOCEAN-ASN                      │ 15     │ 2h43m12s   │ 53216285349 │ crowdsec │ Ip:23.236.169.182  │ crowdsecurity/ssh-slow-bf         │ ban    │ US      │ 55286 SERVER-MANIA                          │ 13     │ 2h40m12s   │ 53117285348 │ crowdsec │ Ip:103.175.206.22  │ crowdsecurity/ssh-slow-bf         │ ban    │ ID      │ 147124 PT Hostingan Awan Indonesia          │ 13     │ 2h40m0s    │ 53018285347 │ crowdsec │ Ip:163.61.198.41   │ crowdsecurity/http-probing        │ ban    │ SG      │ 9664 SOUTHEAST ASIA TELECOMSG PTE. LTD.     │ 13     │ 2h37m41s   │ 52919285346 │ crowdsec │ Ip:45.78.193.199   │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 27     │ 2h34m44s   │ 52820285345 │ crowdsec │ Ip:101.47.163.243  │ crowdsecurity/ssh-slow-bf         │ ban    │ SG      │ 150436 Byteplus Pte. Ltd.                   │ 21     │ 2h30m40s   │ 52721285344 │ crowdsec │ Ip:162.240.109.153 │ crowdsecurity/ssh-slow-bf         │ ban    │ US      │ 46606 UNIFIEDLAYER-AS-1                     │ 14     │ 2h22m55s   │ 52422285343 │ crowdsec │ Ip:181.167.144.229 │ crowdsecurity/ssh-slow-bf         │ ban    │ AR      │ 7303 Telecom Argentina S.A.                 │ 18     │ 2h22m28s   │ 52323285342 │ crowdsec │ Ip:95.90.13.168    │ crowdsecurity/ssh-slow-bf         │ ban    │ DE      │ 3209 Vodafone GmbH                          │ 12     │ 2h21m59s   │ 52224285341 │ crowdsec │ Ip:211.106.133.202 │ crowdsecurity/ssh-slow-bf         │ ban    │ KR      │ 4766 Korea Telecom                          │ 14     │ 2h21m32s   │ 52125285340 │ crowdsec │ Ip:69.63.203.162   │ crowdsecurity/http-probing        │ ban    │ US      │ 3257 GTT Communications Inc.                │ 11     │ 2h9m41s    │ 51926285339 │ crowdsec │ Ip:49.86.41.49     │ crowdsecurity/http-bad-user-agent │ ban    │ CN      │ 146966 China Telecom                        │ 2      │ 1h54m39s   │ 51827285338 │ crowdsec │ Ip:43.134.66.41    │ crowdsecurity/http-probing        │ ban    │ SG      │ 132203 Tencent Building, Kejizhongyi Avenue │ 11     │ 1h29m46s   │ 51528270337 │ crowdsec │ Ip:20.78.169.245   │ crowdsecurity/http-wordpress-scan │ ban    │ JP      │ 8075 MICROSOFT-CORP-MSN-AS-BLOCK            │ 4      │ 56m13s     │ 51329270334 │ crowdsec │ Ip:152.42.225.101  │ crowdsecurity/http-probing        │ ban    │ SG      │ 14061 DIGITALOCEAN-ASN                      │ 11     │ 21m40s     │ 50830╰────────┴──────────┴────────────────────┴───────────────────────────────────┴────────┴─────────┴─────────────────────────────────────────────┴────────┴────────────┴──────────╯

CrowdSec 有很丰富的小功能点,不一一列举。整体来说,适合个人网站使用,值得推荐。

2. Caddy 集成 Coraza WAF 和 rate_limit

大一点的公司,服务的最外层都有一层 WAF; rate_limit 可以流防 CC 攻击、防接口刷取、暴力破解等,咱也得安排上。

1CGO_ENABLED=1 \
2xcaddy build \
3  --with github.com/dunglas/caddy-cbrotli \
4	--with github.com/mholt/caddy-ratelimit \
5	--with github.com/corazawaf/coraza-caddy/v2

我是在电脑上编译好上述非标准模块后,直接上传到服务器,服务器配置太低,编不动且影响用户。caddy-cbrotli 是添加 br 支持,后面 2 个才是 ratelimit 和 WAF。

结果核对:

 1➜  ~ ./caddy list-modules | tail -n 10
 2
 3  Standard modules: 127
 4
 5http.encoders.br
 6http.handlers.rate_limit
 7http.handlers.waf
 8
 9  Non-standard modules: 3
10
11  Unknown modules: 0

WAF 配置片段示例:

 1# --- 1. Coraza WAF 核心防护 ---
 2# 针对静态站,我们主要拦截异常扫描和恶意 User-Agent
 3coraza_waf {
 4    directives `
 5        SecRuleEngine On
 6        SecRequestBodyAccess On
 7        SecDebugLogLevel 0
 8
 9        # 阻止常见的恶意扫描器
10        SecRule REQUEST_HEADERS:User-Agent "(sqlmap|grabber|cgiscan|nessus|nikto|dirbuster|pangolin)" \
11            "id:101,phase:1,deny,status:403,msg:'Malicious Scanner Detected'"
12
13        # 阻止尝试访问敏感文件路径
14        SecRule REQUEST_URI "\.(git|env|config|php|asp|aspx|jsp|cgi|exe)$" \
15            "id:102,phase:1,deny,status:404,msg:'Path Traversal Attempt'"
16    `
17}

测试核验正常,如下所示:

1➜  ~ curl -A "sqlmap" https://mephisto.cc
2Error: 403 Forbidden⏎
3➜  ~ curl -I  https://mephisto.cc/.env
4HTTP/2 404
5alt-svc: h3=":443"; ma=2592000

限流示例:

 1:80
 2
 3rate_limit {
 4	distributed
 5	zone static_example {
 6		match {
 7			method GET
 8		}
 9		key    static
10		events 100
11		window 1m
12	}
13	zone dynamic_example {
14		key    {remote_host}
15		events 2
16		window 5s
17	}
18	log_key
19}
20
21respond "I'm behind the rate limiter!"

限流的功能,我很早就加上去了,是真怕人刷接口。

还有些 RSS 软件,不光访问 RSS 源文件,还要高频抓取全文,违背常理,通过 UA 识别也一并处理掉了。

3. 总结

这样一套组合拳下来,对于个人服务器来说,基本能防住一些常规攻击,也没有什么额外成本,小站良心低调经营,为人民服务。无利可图,应该还不是专业团伙攻击目标。