Proteger servidor con Linux Kernel /etc/sysctl.conf.
En este articulo vamos a mejorar la seguridad y el rendimiento de un sistema basado en Linux.
Configurando el archivo del kernel /etc/sysctl.conf, evitaremos algunos tipos de ataques específicos.
El archivo Linux kernel sysctl.conf nos permitirá realizar los cambios en el kernel Linux. Podremos modificar diversas configuraciones tanto de la red, como del sistema sistema, por ejemplo:
- Limitar la configuración de red en IPv4.
- Limitar la configuración de red en IPv6.
- Activar la protección execshield.
- Prevención contra ‘syn flood attack‘.
- Activar la verificación de la IP de origen.
- Evitar un ataque de suplantación de identidad contra la IP del servidor.
- Registrar los paquetes sospechosos, que pueden ser falsificados, paquetes con enrutamiento de origen y redireccionamiento.
Como puedes ver…. es una temática prácticamente obligatoria de ejecutar, así que vamos a ello.
Proteger el sistema con el Kernel /etc/sysctl.conf
Con el comando sysctl podremos modificar los parámetros del kernel en tiempo de ejecución. Podemos cargar las configuraciones con:
1 | sysctl -a |
1 | sysctl -A |
1 | sysctl mib |
1 | sysctl net.ipv4.conf.all.rp_filter |
1 | sysctl -a --pattern 'net.ipv4.conf.(eth|wlan)0.arp' |
En este punto ya podemos editar el archivo “/etc/sysctl.conf”.
1 | nano /etc/sysctl.conf |
OJO!!! si tienes un kernel personalizado es posible que el archivo sea…
/etc/sysctl.d/99-custom.conf
Comprueba tu caso, copia y pega lo siguiente (el ejemplo de archivo que te propongo es el recomendado para servidores dedicados).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # The following is suitable for dedicated web server, mail, ftp server etc. # --------------------------------------- # BOOLEAN Values: # a) 0 (zero) - disabled / no / false # b) Non zero - enabled / yes / true # -------------------------------------- # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename # Useful for debugging multi-threaded applications kernel.core_uses_pid = 1 # Controls the use of TCP syncookies # Turn on SYN-flood protections net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_synack_retries = 5 ########## IPv4 networking start ############## # Send redirects, if router, but this is just server # So no routing allowed net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 # Accept packets with SRR option? No net.ipv4.conf.all.accept_source_route = 0 # Accept Redirects? No, this is not router net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 # Log packets with impossible addresses to kernel log? yes net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.default.accept_source_route = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 # Ignore all ICMP ECHO and TIMESTAMP requests sent to it via broadcast/multicast net.ipv4.icmp_echo_ignore_broadcasts = 1 # Prevent against the common 'syn flood attack' net.ipv4.tcp_syncookies = 1 # Enable source validation by reversed path, as specified in RFC1812 net.ipv4.conf.all.rp_filter = 1 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 ########## IPv6 networking start ############## # Number of Router Solicitations to send until assuming no routers are present. # This is host and not router net.ipv6.conf.default.router_solicitations = 0 # Accept Router Preference in RA? net.ipv6.conf.default.accept_ra_rtr_pref = 0 # Learn Prefix Information in Router Advertisement net.ipv6.conf.default.accept_ra_pinfo = 0 # Setting controls whether the system will accept Hop Limit settings from a router advertisement net.ipv6.conf.default.accept_ra_defrtr = 0 #router advertisements can cause the system to assign a global unicast address to an interface net.ipv6.conf.default.autoconf = 0 #how many neighbor solicitations to send out per address? net.ipv6.conf.default.dad_transmits = 0 # How many global unicast IPv6 addresses can be assigned to each interface? net.ipv6.conf.default.max_addresses = 1 ########## IPv6 networking ends ############## #Enable ExecShield protection #Set value to 1 or 2 (recommended) #kernel.exec-shield = 2 #kernel.randomize_va_space=2 # TCP and memory optimization # increase TCP max buffer size setable using setsockopt() #net.ipv4.tcp_rmem = 4096 87380 8388608 #net.ipv4.tcp_wmem = 4096 87380 8388608 # increase Linux auto tuning TCP buffer limits #net.core.rmem_max = 8388608 #net.core.wmem_max = 8388608 #net.core.netdev_max_backlog = 5000 #net.ipv4.tcp_window_scaling = 1 # increase system file descriptor limit fs.file-max = 65535 #Allow for more PIDs kernel.pid_max = 65536 #Increase system IP port limits net.ipv4.ip_local_port_range = 2000 65000 # RFC 1337 fix net.ipv4.tcp_rfc1337=1 |
Para que reinicie a los 10 segundos de entrar en un temido “kernel panic“.
1 | kernel.panic=10 |
Para aleatorizar las direcciones “mmap” y la VDSO.
1 | kernel.randomize_va_space=2 |
Ignorar errores malignos ICMP.
1 | net.ipv4.icmp_ignore_bogus_error_responses=1 |
Protegerte contra la creación o seguimiento de los enlaces.
1 2 | fs.protected_hardlinks=1 fs.protected_symlinks=1 |
Llegado a este punto ya puedes guardar el archivo y reiniciar el servidor.
En próximos artículos aumentaremos aun más si cabe, la seguridad de nuestro servidor.