VPS & SSH hardening
Só leitura — não altera nada no alvo. Só em alvo seu ou autorizado por escrito.
O vetor
Vetor: bots varrem a internet 24/7 tentando SSH por senha em portas padrão (22). Um VPS recém-criado sofre brute-force em minutos. O que testamos: portas expostas, política de SSH, fail2ban, firewall.
Os passos
Passo 1 (🟢, de fora do VPS) — que portas o mundo vê:
# Substitua SEU_IP. internetDB da Shodan é grátis e não invasivo:
curl -s "https://internetdb.shodan.io/SEU_IP" | python -m json.tool
# Só deveriam aparecer 80 e 443 (e, no máximo, a porta SSH custom).
Passo 2 (🟢, no VPS) — auditar SSH e firewall:
sudo sshd -T | grep -Ei "permitrootlogin|passwordauthentication|port|maxauthtries"
sudo ufw status verbose
O que esperar
- VULNERÁVEL:
port 22,passwordauthentication yes,permitrootlogin yes, UFW inativo, banco (5432/3306/6379) exposto. - SEGURO: porta não-padrão,
passwordauthentication no(só chave), root sem senha, UFWdeny incomingexceto 80/443/SSH.
Como corrigir
Correção (P0): sshd_config → Port 2222, PasswordAuthentication no, PermitRootLogin prohibit-password, MaxAuthTries 3; ufw default deny incoming + allow só 80/443/2222; instalar fail2ban (jail sshd) e unattended-upgrades. (Detalhes: DOCUMENTACAO §4.3.)
Limpeza: nenhuma (só leitura/config).