VPS hardening de Linux

  • Autor Autor DaniFox
  • Fecha de inicio Fecha de inicio
D

DaniFox

Beta
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
¿Qué estrategias de hardening utilizan para sus VPS en Linux?

¿Qué programas recomiendan instalar? ¿alcanza con un IDS?

Si puedieran mostrar qué configuración de iptables tienen, también estaría agradecido.

Saludos.
 
En Ubuntu normalmente uso Fail2Ban

Insertar CODE, HTML o PHP:
[B]About Fail2Ban[/B]

[COLOR=#000000][FONT=proxima-nova]Servers do not exist in isolation, and those virtual private servers with only the most basic SSH configuration can be vulnerable to brute force attacks. fail2ban provides a way to automatically protect virtual servers from malicious behavior. The program works by scanning through log files and reacting to offending actions such as repeated failed login attempts.[/FONT][/COLOR]

[B]Step One—Install Fail2Ban[/B]

[COLOR=#000000][FONT=proxima-nova]Use apt-get to install Fail2Ban[/FONT][/COLOR]
sudo apt-get install fail2ban
[B]Step Two—Copy the Configuration File[/B]

[COLOR=#000000][FONT=proxima-nova]The default fail2ban configuration file is location at /etc/fail2ban/jail.conf. The configuration work should not be done in that file, however, and we should instead make a local copy of it.[/FONT][/COLOR]
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local[COLOR=#000000][FONT=proxima-nova]After the file is copied, you can make all of your changes within the new jail.local file. Many of possible services that may need protection are in the file already. Each is located in its own section, configured and turned off.[/FONT][/COLOR]

[B]Step Three—Configure the Defaults in Jail.Local[/B]

[COLOR=#000000][FONT=proxima-nova]Open up the the new fail2ban configuration file:[/FONT][/COLOR]
sudo nano /etc/fail2ban/jail.local[COLOR=#000000][FONT=proxima-nova]The first section of defaults covers the basic rules that fail2ban will follow. If you want to set up more nuanced protection on your virtual server, you can customize the details in each section.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]You can see the default section below.[/FONT][/COLOR]
[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1/8
bantime  = 600
maxretry = 3

# "backend" specifies the backend used to get files modification. Available
# options are "gamin", "polling" and "auto".
# yoh: For some reason Debian shipped python-gamin didn't work as expected
#      This issue left ToDo, so polling is default backend for now
backend = auto

#
# Destination email address used solely for the interpolations in
# jail.{conf,local} configuration files.
destemail = root@localhost[COLOR=#000000][FONT=proxima-nova]Write your personal IP address into the ignoreip line. You can separate each address with a space. IgnoreIP allows you white list certain IP addresses and make sure that they are not locked out. Including your address will guarantee that you do not accidentally ban yourself from your own server.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]The next step is to decide on a bantime, the number of seconds that a host would be blocked from the VPS if they are found to be in violation of any of the rules. This is especially useful in the case of bots, that once banned, will simply move on to the next target. The default is set for 10 minutes—you may raise this to an hour (or higher) if you like.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]Maxretry is the amount of incorrect login attempts that a host may have before they get banned for the length of the ban time.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]You can leave the backend as auto.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]Destemail is the email that alerts get sent to. If you have a mail server set up on your droplet, Fail2Ban can email you when it bans an IP address.[/FONT][/COLOR]
[B]Additional Details—Actions[/B]

[COLOR=#000000][FONT=proxima-nova]The Actions section is located below the defaults. The beginning looks like this:[/FONT][/COLOR]
#
# ACTIONS
#

# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
banaction = iptables-multiport

# email action. Since 0.8.1 upstream fail2ban uses sendmail
# MTA for the mailing. Change mta configuration parameter to mail
# if you want to revert to conventional 'mail'.
mta = sendmail

# Default protocol
protocol = tcp
[...][COLOR=#000000][FONT=proxima-nova]Banaction describes the steps that fail2ban will take to ban a matching IP address. This is a shorter version of the file extension where the config if is located. The default ban action, "iptables-multiport", can be found at /etc/fail2ban/action.d/iptables-multiport.conf[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]MTA refers to email program that fail2ban will use to send emails to call attention to a malicious IP.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]You can change the protocol from TCP to UDP in this line as well, depending on which one you want fail2ban to monitor.[/FONT][/COLOR]

[B]Step Four (Optional)—Configure the ssh-iptables Section in Jail.Local[/B]

[COLOR=#000000][FONT=proxima-nova]The SSH details section is just a little further down in the config, and it is already set up and turned on. Although you should not be required to make to make any changes within this section, you can find the details about each line below.[/FONT][/COLOR]
[ssh]

enabled  = true
port     = ssh
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 6[COLOR=#000000][FONT=proxima-nova]Enabled simply refers to the fact that SSH protection is on. You can turn it off with the word "false".[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]The port designates the port that fail2ban monitors. If you have set up your virtual private server on a non-standard port, change the port to match the one you are using:[/FONT][/COLOR]
 eg. port=30000[COLOR=#000000][FONT=proxima-nova]The filter, set by default to sshd, refers to the config file containing the rules that fail2ban uses to find matches. sshd refers to the /etc/fail2ban/filter.d/sshd.conf.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]log path refers to the log location that fail2ban will track.[/FONT][/COLOR]
[COLOR=#000000][FONT=proxima-nova]The max retry line within the SSH section has the same definition as the default option. However, if you have enabled multiple services and want to have specific values for each one, you can set the new max retry amount for SSH here.[/FONT][/COLOR]

[B]Step Five—Restart Fail2Ban[/B]

[COLOR=#000000][FONT=proxima-nova]After making any changes to the fail2ban config, always be sure to restart Fail2Ban:[/FONT][/COLOR]
sudo service fail2ban restart[COLOR=#000000][FONT=proxima-nova]You can see the rules that fail2ban puts in effect within the IP table:[/FONT][/COLOR]
sudo iptables -L
 
Un IDS evidentemente debe ir acompañado siempre de las medidas que podríamos llamar "básicas" a la hora de asegurar un sistema GNU/Linux, como:

  • Cambio de puertos por defecto en los servicios abiertos.
  • Firewall con todo capado excepto los puertos por los que escuchan nuestros servicios.
  • Contraseñas robustas.
  • No permitir el login remoto para el usuario root.
  • Fail2ban o cualquier otra herramienta para evitar los ataques de fuerza bruta.
  • Actualización periódica del servidor.
  • Revisión de logs (logwatch o similares, o manualmente).

Saludos!
 
Última edición:
para iptables mejor usa ufw... pero ten cuidado por que puedes bloquearte ssh
 
Gracias a todos por las respuestas, igualmente el tema es complejo para debatir en este foro
 
en este foro hay buenos sysadmin de seguridad, que te podrían ayudar con el hardening a muy bajo costo
 
Todo depende para que necesites el servidor y que servicios tengas corriendo y necesites tener corriendo.

Entre menos servicios mejor.

Lo otro es que se puede aplicar una seguridad básica y estandar a todos los servidores y luego asegurarlos cada uno por aparte según necesidades.
 
Atrás
Arriba