romangrinev/hestia-security
GitHub: romangrinev/hestia-security
一套专为 HestiaCP 服务器定制的安全基线加固、自动化巡检与防篡改回滚脚本工具集。
Stars: 0 | Forks: 0
# hestia-security
适用于 **HestiaCP** 服务器(Ubuntu/Debian,nginx + PHP-FPM)的安全加固、监控和事件响应脚本。
## 快速安装
```
git clone https://github.com/romangrinev/hestia-security.git /root/server-security
cd /root/server-security
cp security-audit.env.example /etc/security-audit.env
nano /etc/security-audit.env # заполните API-ключ и email
bash install.sh
```
## 脚本
| 脚本 | 运行频率 | 描述 |
|--------|--------|----------|
| `01-security-audit.sh` | 每天 3:00 | 全面审计:shell、cron、登录、进程、被修改的文件。将报告发送至邮箱 |
| `02-git-cleanup.sh` | 手动 | 回滚所有 git 仓库(`git checkout -- . && git clean -fd`) |
| `03-hardening.sh` | 手动(一次性) | PHP 加固,SSH,fail2ban,文件权限,inotifywait 监控 |
| `04-git-auto-restore.sh` | 每 6 小时 | 自动回滚被修改的 git 仓库并发送邮件通知 |
## 配置说明
```
# /etc/security-audit.env
RESEND_API_KEY="re_xxxxxxxx" # Resend.com API key
RESEND_FROM="security@yourdomain.com" # верифицированный домен в Resend
RESEND_TO="admin@youremail.com" # куда слать отчёты
```
脚本会通过 HestiaCP (`v-list-users`) 自动检测用户。
如需手动指定列表,请在相应脚本开头取消注释 `USERS=` 行。
## 手动运行
```
# Audit (立即运行)
sudo bash /root/server-security/01-security-audit.sh 2>&1 | tee /tmp/audit.txt
# Hardening (在新服务器上首次运行)
sudo bash /root/server-security/03-hardening.sh 2>&1 | tee /tmp/hardening.txt
# 通过 git 清理 (事件发生后)
sudo bash /root/server-security/02-git-cleanup.sh 2>&1 | tee /tmp/cleanup.txt
```
## 环境要求
- Ubuntu 20.04+ / Debian 11+
- HestiaCP
- `curl`、`git`、`inotify-tools`、`fail2ban`
- Resend.com 账户(每月 3000 封邮件免费)
## 防火墙 (iptables)
首次运行 `03-hardening.sh` 后,建议将 SSH 限制为仅您的 IP 可访问:
```
# 仅允许来自您的 IP 的 SSH
sudo iptables -R INPUT 10 -p tcp -s ВАШ_IP --dport 22 -j ACCEPT
# 保存规则 (重启后依然生效)
sudo netfilter-persistent save
```
将您的 IP 添加到 fail2ban 白名单(不会被阻止):
```
# 在 /etc/fail2ban/jail.local 的 [DEFAULT] 部分中:
ignoreip = 127.0.0.1/8 ВАШ_IP
sudo systemctl restart fail2ban
```
脚本 `01-security-audit.sh` 会自动检查 iptables 并在以下情况发出警告:
- SSH 对 `0.0.0.0/0`(整个互联网)开放
- `INPUT` 策略不是 `DROP`
- MySQL 可从外部访问
- fail2ban 未处于活跃状态
## Cron(可通过 `install.sh` 配置)
```
0 3 * * * root bash /root/server-security/01-security-audit.sh >> /var/log/security-audit.log 2>&1
0 */6 * * * root bash /root/server-security/04-git-auto-restore.sh >> /var/log/git-auto-restore.log 2>&1
```
标签:Awesome, Debian, Fail2ban, GitHub Advanced Security, Git备份恢复, HestiaCP, Inotifywait, Linux服务器, Nginx, PHP-FPM, Shell脚本, SSH安全, x64dbg, 动态API解析, 安全加固, 应用安全, 控制面板安全, 系统管理, 自动化运维