¿Qué es un ataque distribuido de denegación de servicio (DDoS)?.
Intentaré explicarlo de manera muy simple.
Los transportaré a un lugar donde tendrán que utilizar su imaginación:
Estás en una pizzería con tu amada.
-¡Mesero! Una de jamón y queso, grande. Dice tu amada.
-Enseguida, responde el mesero, perdón la tardanza, he quedado sólo.
A eso , entra una familia de... 6 o 8 personas, la mamá , el papá, la abuela, la tía , los tres hijos , el tío y el abuelo.
-¡Mozo! 6 de muzzarella , gritó el papá.
Juan, el pizzero, estaba con arduo trabajo. Todo iba tranquilo hasta que llegó un equipo de fútbol recién salido de un partido. Juan estaba colapsado. Lo único que se oía era "¡Mesero!". Juan no sabía para dónde ir , para dónde mirar y menos a quién contestar. Lo que faltaba, llega el equipo contrario de fútbol. Era el final de Juan, colapsó.
A eso tú y tu amada van y le piden una cerveza, él al no responder les está Denegando el servicio.
Juan: Servidor.
Tú y tu amada: Usuarios
Equipos de fútbol , familia y etc: Falsos usuarios (Bot's)
Más complejo (Wikipedia):
En seguridad informática, un ataque de denegación de servicio, también llamado ataque DoS (de las siglas en inglés Denial of Service), es un ataque a un sistema de computadoras o red que causa que un servicio o recurso sea inaccesible a los usuarios legítimos. Normalmente provoca la pérdida de la conectividad de la red por el consumo del ancho de banda de la red de la víctima o sobrecarga de los recursos computacionales del sistema de la víctima.
Se genera mediante la saturación de los puertos con flujo de información, haciendo que el servidor se sobrecargue y no pueda seguir prestando servicios, por eso se le denomina "denegación", pues hace que el servidor no dé abasto a la cantidad de solicitudes. Esta técnica es usada por los llamados crackers para dejar fuera de servicio a servidores objetivo.
Una ampliación del ataque DoS es el llamado ataque distribuido de denegación de servicio, también llamado ataque DDoS (de las siglas en inglés Distributed Denial of Service) el cual lleva a cabo generando un gran flujo de información desde varios puntos de conexión.
La forma más común de realizar un DDoS es a través de una botnet, siendo esta técnica el ciberataque más usual y eficaz por su sencillez tecnológica.
En ocasiones, esta herramienta ha sido utilizada como un buen método para comprobar la capacidad de tráfico que un ordenador puede soportar sin volverse inestable y afectar a los servicios que presta. Un administrador de redes puede así conocer la capacidad real de cada máquina.
Protegerse básicamente
Protegerse de estos ataques es facil, la mayoria de ellos se basa en mandar muchas peticiones a una base de datos, lo cual se puede evitar haciendo un script antiflood. Atacar una base de datos es facil, un server se cae facilmente mandando muchas peticiones sql, que si se mandaran http.
El otro tipo de ataques es por zombies, ahi se necesita implementar scripts de banneo automatico en el server
Otra forma de acabar o repeler estos ataques es:
1) Usando el comando netstat
[color=#000000] netstat -an | grep :80 | sort [/color]
[color=#000000]netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'[/color]
[color=#000000]netstat -n -p|grep SYN_REC | wc -l[/color]
[color=#000000]netstat -an | grep :80 | awk '{ print $5 }' | awk -F: '{ print $1 }' | sort | uniq -c | sort -n[/color]
Ejemplo de ataque SYN_RECV o SYN Flooding al Apache (puerto 80).
192.168.0.3 es la ip del servidor apache y 192.168.0.105 es la ip del "atacante".
[color=#000000] tcp 0 0 192.168.0.3:80 192.168.0.5:60808 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60761 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60876 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60946 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60763 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60955 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60765 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60961 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60923 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61336 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61011 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60911 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60758 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60828 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61114 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61074 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60826 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60959 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60900 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60940 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60920 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60825 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60945 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60913 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61009 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60755 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60904 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61583 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60910 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60915 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60827 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61458 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60908 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61007 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60927 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60951 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60942 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61113 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60909 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60822 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60894 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60952 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60928 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60936 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60906 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61466 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60919 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60914 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60926 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60939 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60931 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60831 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60823 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60954 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60916 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60963 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60947 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61006 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60933 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60950 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60895 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60917 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61480 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60935 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60960 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60767 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60918 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60821 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61077 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60905 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61517 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60893 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60953 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60903 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61439 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61337 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61545 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61299 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61010 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60930 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60744 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60929 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60754 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61008 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61116 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60811 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60807 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60938 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60764 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60873 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60817 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61550 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60748 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60956 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60753 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61115 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60741 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61075 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60948 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60829 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60943 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61338 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60762 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60824 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60830 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61535 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60898 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60815 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60962 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60957 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60944 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60921 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60759 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60897 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61518 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60958 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60922 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60937 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60875 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60766 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60751 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60768 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60743 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:61076 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60912 SYN_RECV
tcp 0 0 192.168.0.3:80 192.168.0.5:60816 SYN_RECV [/color]
Claro ejemplo de SYN Attack al Apache.
2) Mirando el server-status del Apache , no , no de tevez.
Si miramos el server-status del apache veremos conexiones en estado "Reading" ("R" Reading Request).
El problema es que cuando el número de conexiones "Reading" llena el "MaxClients" del Apache no acepta nuevas peticiones, por lo que los nuevos clientes, aunque sean legítimos, no serán aceptados.
Podemos aumentar el valor del "MaxClients" para que no se llene la cola de peticiones y acepte a todos los clientes, sean atacantes o no.
Otra buena medida es bajar el valor del "Timeout" del Apache para que las peticiones "Reading" sean "matadas" rápidamente, antes que pueda llenarse el MaxClients a su tope.
Para aumentar el MaxClients en el Apache 2 basta con añadir la directiva:
ServerLimit 350 antes de MaxClients y ya dejará.
<IfModule prefork.c>
[..]
ServerLimit 500
MaxClients 450
[..]
</IfModule>
3) Mirando los logs del mod_evasive
Jun 22 18:24:04 lan mod_evasive[3835]: Blacklisting address 82.228.169.50: possible attack.
Jun 22 18:24:45 lan mod_evasive[3600]: Blacklisting address 81.206.164.163: possible attack.
Jun 22 18:25:46 lan mod_evasive[3589]: Blacklisting address 155.232.250.19: possible attack.
Jun 22 18:27:23 lan mod_evasive[3671]: Blacklisting address 83.227.217.2: possible attack.
Jun 22 18:28:10 lan mod_evasive[3673]: Blacklisting address 68.187.171.89: possible attack.
Jun 22 18:29:57 lan mod_evasive[3605]: Blacklisting address 70.143.2.130: possible attack.
Jun 22 18:30:45 lan mod_evasive[3803]: Blacklisting address 69.157.93.88: possible attack.
Jun 22 18:31:45 lan mod_evasive[10397]: Blacklisting address 146.64.81.22: possible attack.
Jun 22 18:35:01 lan mod_evasive[3794]: Blacklisting address 66.38.192.134: possible attack.
Jun 22 18:35:15 lan mod_evasive[3553]: Blacklisting address 81.190.204.64: possible attack.
Jun 22 18:40:10 lan mod_evasive[16602]: Blacklisting address 64.231.39.129: possible attack.
Jun 22 18:48:04 lan mod_evasive[16479]: Blacklisting address 84.99.195.100: possible attack.
Jun 22 18:48:12 lan mod_evasive[16467]: Blacklisting address 201.0.10.142: possible attack.
Jun 22 18:52:57 lan mod_evasive[16573]: Blacklisting address 219.95.39.242: possible attack.
Jun 22 18:53:07 lan mod_evasive[16534]: Blacklisting address 86.129.3.91: possible attack.
Jun 22 18:53:26 lan mod_evasive[16527]: Blacklisting address 62.254.0.32: possible attack.
Jun 22 18:54:41 lan mod_evasive[30473]: Blacklisting address 24.196.199.191: possible attack.
Jun 22 18:55:17 lan mod_evasive[30520]: Blacklisting address 142.161.157.227: possible attack.
Jun 22 18:55:24 lan mod_evasive[30461]: Blacklisting address 65.92.145.133: possible attack.
Jun 22 18:55:33 lan mod_evasive[30509]: Blacklisting address 88.111.227.200: possible attack.
Jun 22 18:56:13 lan mod_evasive[30473]: Blacklisting address 69.199.94.227: possible attack.
Jun 22 18:57:45 lan mod_evasive[30517]: Blacklisting address 86.125.135.212: possible attack.
Jun 22 18:57:54 lan mod_evasive[30479]: Blacklisting address 84.192.141.65: possible attack.
Jun 22 18:58:46 lan mod_evasive[30527]: Blacklisting address 83.140.97.106: possible attack.
Jun 22 18:59:31 lan mod_evasive[30469]: Blacklisting address 82.173.216.196: possible attack.
Jun 22 19:00:33 lan mod_evasive[30517]: Blacklisting address 80.176.157.245: possible attack.
Jun 22 19:00:38 lan mod_evasive[30470]: Blacklisting address 86.133.102.51: possible attack.
Jun 22 19:01:35 lan mod_evasive[30870]: Blacklisting address 24.42.134.253: possible attack.
Jun 22 19:01:48 lan mod_evasive[30509]: Blacklisting address 62.254.0.34: possible attack.
Jun 22 19:02:57 lan mod_evasive[31009]: Blacklisting address 81.227.219.125: possible attack.
Jun 22 19:03:29 lan mod_evasive[31056]: Blacklisting address 172.209.173.153: possible attack.
Jun 22 19:05:07 lan mod_evasive[31385]: Blacklisting address 84.6.12.110: possible attack.
Jun 22 19:06:52 lan mod_evasive[31008]: Blacklisting address 85.227.144.249: possible attack.
Jun 22 19:06:56 lan mod_evasive[31263]: Blacklisting address 213.222.156.222: possible attack.
Jun 22 19:07:13 lan mod_evasive[31393]: Blacklisting address 62.163.143.166: possible attack.
Jun 22 19:07:37 lan mod_evasive[31021]: Blacklisting address 62.135.101.73: possible attack.
Jun 22 19:08:03 lan mod_evasive[31251]: Blacklisting address 82.201.249.69: possible attack.
Jun 22 19:08:17 lan mod_evasive[31200]: Blacklisting address 81.62.65.53: possible attack.
Jun 22 19:11:04 lan mod_evasive[31263]: Blacklisting address 82.39.148.204: possible attack.
Jun 22 19:12:37 lan mod_evasive[31241]: Blacklisting address 213.222.154.13: possible attack.
Jun 22 19:13:54 lan mod_evasive[31027]: Blacklisting address 81.51.79.4: possible attack.
Jun 22 19:24:04 lan mod_evasive[31041]: Blacklisting address 84.221.118.156: possible attack.
Jun 22 19:48:47 lan mod_evasive[3400]: Blacklisting address 62.135.101.192: possible attack.
Jun 22 19:53:04 lan mod_evasive[31031]: Blacklisting address 62.30.33.13: possible attack.
Jun 22 19:54:32 lan mod_evasive[31016]: Blacklisting address 72.14.194.18: possible attack.
Jun 22 19:56:10 lan mod_evasive[31067]: Blacklisting address 198.96.34.58: possible attack.
Jun 22 20:03:24 lan mod_evasive[5144]: Blacklisting address 172.213.33.242: possible attack.
Jun 22 20:08:31 lan mod_evasive[5137]: Blacklisting address 83.241.11.16: possible attack.
Jun 22 20:21:59 lan mod_evasive[6645]: Blacklisting address 201.23.193.20: possible attack.
Jun 22 20:32:28 lan mod_evasive[7801]: Blacklisting address 212.38.134.172: possible attack.
Jun 22 20:45:46 lan mod_evasive[7836]: Blacklisting address 81.247.11.48: possible attack.
Jun 22 20:48:03 lan mod_evasive[7796]: Blacklisting address 70.245.98.186: possible attack.
Jun 22 20:49:38 lan mod_evasive[7832]: Blacklisting address 61.8.138.203: possible attack.
Jun 22 20:51:21 lan mod_evasive[7801]: Blacklisting address 201.132.197.161: possible attack.
Jun 22 20:57:18 lan mod_evasive[10426]: Blacklisting address 82.201.249.67: possible attack.
Jun 22 20:57:51 lan mod_evasive[7822]: Blacklisting address 81.77.26.162: possible attack.
Jun 22 21:00:25 lan mod_evasive[7817]: Blacklisting address 200.39.202.243: possible attack.
Jun 22 21:12:04 lan mod_evasive[7794]: Blacklisting address 84.27.139.25: possible attack.
Jun 22 21:22:27 lan mod_evasive[7816]: Blacklisting address 217.208.98.254: possible attack.
Si es un DDoS muy distribuido enseguida notaremos que muchas ip's diferente DoSean el Apache.
4) Mirando los logs del syslog (del kernel)
May 17 13:39:01 lan kernel: possible SYN flooding on port 80. Sending cookies.
May 17 13:39:02 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:35 lan kernel: NET: 4 messages suppressed.
May 17 13:39:35 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:38 lan kernel: NET: 1 messages suppressed.
May 17 13:39:38 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:43 lan kernel: NET: 6 messages suppressed.
May 17 13:39:43 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:48 lan kernel: NET: 4 messages suppressed.
May 17 13:39:48 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:52 lan kernel: NET: 9 messages suppressed.
May 17 13:39:52 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:39:57 lan kernel: NET: 15 messages suppressed.
May 17 13:39:57 lan kernel: ip_conntrack: table full, dropping packet.
May 17 13:40:01 lan kernel: possible SYN flooding on port 80. Sending cookies.
Líneas a mirar:
Citar
possible SYN flooding on port 80. Sending cookies.
"Sending Cookies" si lo tenemos activado en el /etc/sysctl.conf
# Enable TCP SYN Cookie Protection
[color=#000000] net.ipv4.tcp_syncookies = 1 [/color]
A veces es mejor deshabilitarlo:
[color=#000000]net.ipv4.tcp_syncookies = 0[/color]
Espero haberles sido de utilidad, puntúen, ya que este ejemplo lo hice yo tras leer en wikipedia y variadas páginas