feat(infraestrutura): adiciona plugin infraestrutura (agents, skills, knowledge e metadados do projeto)
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
---
|
||||
name: security-check
|
||||
description: Auditoria de seguranca de infraestrutura — certificados SSL, portas abertas, actualizacoes pendentes, backups recentes, CSF/firewall e email security. Score por servidor.
|
||||
context: fork
|
||||
layer: wiki
|
||||
---
|
||||
|
||||
# /security-check v1.0 (infraestrutura)
|
||||
|
||||
Auditoria de seguranca dos servidores Descomplicar. Verifica SSL, portas, actualizacoes, backups, firewall e email security.
|
||||
|
||||
> **Auditoria de dependencias de codigo:** usar `/dep-audit` (plugin dev-tools).
|
||||
|
||||
**Referencia:** PROC-Security-Audit-API-Keys.md | PROC-Backup-Sistema.md | Memory: `infra.md`, `cwp-ssl-autorenew-fix.md`
|
||||
|
||||
---
|
||||
|
||||
## Servidores Alvo
|
||||
|
||||
| Alias | Host | IP | SO | Firewall | Gestor SSL |
|
||||
|-------|------|----|----|----------|------------|
|
||||
| server | server.descomplicar.pt | 176.9.3.158 | CentOS (CWP) | CSF v15 | acme.sh |
|
||||
| easy | qibspu.easypanel.host | 178.63.18.51 | Ubuntu 24.04 | — | EasyPanel/Traefik |
|
||||
| gateway | gateway.descomplicar.pt | — | — | — | nginx/acme |
|
||||
|
||||
---
|
||||
|
||||
## Modos de Execucao
|
||||
|
||||
| Comando | Descricao |
|
||||
|---------|-----------|
|
||||
| `/security-check` | Auditoria completa (todos os servidores, todos os checks) |
|
||||
| `/security-check server` | Apenas servidor CWP |
|
||||
| `/security-check easy` | Apenas EasyPanel |
|
||||
| `/security-check ssl` | Apenas certificados SSL (todos os servidores) |
|
||||
| `/security-check quick` | Resumo rapido: SSL a expirar + backups + firewall |
|
||||
|
||||
---
|
||||
|
||||
## Protocolo de Execucao
|
||||
|
||||
### Check 1: Certificados SSL (server)
|
||||
|
||||
```bash
|
||||
# Executar via mcp__ssh-unified__ssh_execute(server="server")
|
||||
|
||||
# Listar todos os certs e datas de expiracao
|
||||
for dir in /root/.acme.sh/cwp_certs/*_ecc; do
|
||||
domain=$(basename "$dir" | sed 's/_ecc$//')
|
||||
cert="$dir/${domain}.cer"
|
||||
if [ -f "$cert" ]; then
|
||||
expiry=$(openssl x509 -enddate -noout -in "$cert" 2>/dev/null | cut -d= -f2)
|
||||
days=$(( ($(date -d "$expiry" +%s) - $(date +%s)) / 86400 ))
|
||||
if [ "$days" -lt 15 ]; then
|
||||
echo "CRITICAL $domain expires in ${days}d ($expiry)"
|
||||
elif [ "$days" -lt 30 ]; then
|
||||
echo "WARN $domain expires in ${days}d ($expiry)"
|
||||
else
|
||||
echo "OK $domain expires in ${days}d"
|
||||
fi
|
||||
fi
|
||||
done | sort
|
||||
```
|
||||
|
||||
**Thresholds:**
|
||||
- **OK:** >30 dias para expirar
|
||||
- **WARN:** 15-30 dias
|
||||
- **CRITICAL:** <15 dias
|
||||
|
||||
### Check 2: Portas Abertas (server)
|
||||
|
||||
```bash
|
||||
# Portas a escutar no servidor CWP
|
||||
ss -tlnp | awk 'NR>1 {print $4}' | sed 's/.*://' | sort -n | uniq
|
||||
|
||||
# Portas esperadas (CWP padrao):
|
||||
# 22(SSH) 25(SMTP) 80(HTTP) 110(POP3) 143(IMAP) 443(HTTPS)
|
||||
# 465(SMTPS) 587(Submission) 993(IMAPS) 995(POP3S)
|
||||
# 2031(CWP) 2087(CWP Admin) 3306(MySQL)
|
||||
# 8443(CWP SSL) 9443(SSH alternativo)
|
||||
EXPECTED="22 25 80 110 143 443 465 587 993 995 2031 2087 3306 8443 9443"
|
||||
|
||||
# Comparar: portas abertas que NAO estao na lista esperada
|
||||
ss -tlnp | awk 'NR>1 {print $4}' | sed 's/.*://' | sort -n | uniq | while read port; do
|
||||
if ! echo "$EXPECTED" | grep -qw "$port"; then
|
||||
proc=$(ss -tlnp | grep ":${port} " | sed 's/.*users:(("//' | cut -d'"' -f1)
|
||||
echo "UNEXPECTED :${port} ($proc)"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
### Check 3: Actualizacoes Pendentes
|
||||
|
||||
```bash
|
||||
# CWP Server (CentOS/dnf)
|
||||
# mcp__ssh-unified__ssh_execute(server="server")
|
||||
dnf check-update --quiet 2>/dev/null | grep -v "^$" | wc -l
|
||||
# Se >0: listar security updates
|
||||
dnf updateinfo list security 2>/dev/null | tail -10
|
||||
|
||||
# EasyPanel (Ubuntu/apt)
|
||||
# mcp__ssh-unified__ssh_execute(server="easy")
|
||||
apt list --upgradable 2>/dev/null | grep -c upgradable
|
||||
# Se >0: listar security updates
|
||||
apt list --upgradable 2>/dev/null | grep -i secur
|
||||
```
|
||||
|
||||
**Thresholds:**
|
||||
- **OK:** 0 security updates pendentes
|
||||
- **WARN:** 1-5 security updates
|
||||
- **CRITICAL:** >5 security updates OU kernel update pendente
|
||||
|
||||
### Check 4: Backups Recentes (server)
|
||||
|
||||
```bash
|
||||
# mcp__ssh-unified__ssh_execute(server="server")
|
||||
|
||||
echo "=== MySQL Daily ==="
|
||||
ls -lt /home/backup/mysql/daily/ 2>/dev/null | head -3
|
||||
latest_mysql=$(find /home/backup/mysql/daily/ -name "*.sql.gz" -mtime -2 2>/dev/null | wc -l)
|
||||
echo "BDs com backup <48h: $latest_mysql"
|
||||
|
||||
echo "=== Monthly ==="
|
||||
ls -lt /home/backup/monthly/ 2>/dev/null | head -5
|
||||
|
||||
echo "=== Rsync Easy->Server ==="
|
||||
# Verificar ultimo rsync (Easy replica para Server as 06:00)
|
||||
ls -lt /gordito/backup-easy/ 2>/dev/null | head -3 || echo "path nao existe"
|
||||
|
||||
echo "=== Idade ultimo backup ==="
|
||||
newest=$(find /home/backup/ -type f -name "*.gz" -printf '%T@\n' 2>/dev/null | sort -rn | head -1)
|
||||
if [ -n "$newest" ]; then
|
||||
age_hours=$(echo "scale=1; ($(date +%s) - $newest) / 3600" | bc)
|
||||
echo "Backup mais recente: ${age_hours}h atras"
|
||||
fi
|
||||
```
|
||||
|
||||
**Thresholds:**
|
||||
- **OK:** backup MySQL <48h, monthly <35 dias
|
||||
- **WARN:** backup MySQL 48-72h, monthly 35-60 dias
|
||||
- **CRITICAL:** backup MySQL >72h, monthly >60 dias
|
||||
|
||||
### Check 5: Firewall CSF (server)
|
||||
|
||||
```bash
|
||||
# mcp__ssh-unified__ssh_execute(server="server")
|
||||
|
||||
echo "=== CSF Status ==="
|
||||
csf -v
|
||||
csf -l | head -5
|
||||
|
||||
echo "=== IPs Bloqueados ==="
|
||||
wc -l /etc/csf/csf.deny
|
||||
echo "Ultimos 5 bloqueios:"
|
||||
tail -5 /etc/csf/csf.deny
|
||||
|
||||
echo "=== LFD Status ==="
|
||||
systemctl is-active lfd
|
||||
|
||||
echo "=== Ataques Recentes (24h) ==="
|
||||
grep "$(date
|
||||
Reference in New Issue
Block a user