¿Que es Mod Evasive?
Mod_Evasive es un modulo para Apache que permite prevenir ataques de denegación de servicios (DoS). Para ello, mantiene una tabla dinámica con las URIs accedidas por las distintas IPs de los clientes del Apache, y permite ejecutar algunas acciones cuando una misma IP solicita un mismo recurso (una misma URI o elementos de un mismo sitio) mas de n veces en m segundos. La acción predeterminada es, una vez superado el máximo de requests por segundo permitidos, bloquear durante una cantidad de segundos al cliente (la IP) devolviendo un error 403 (Forbidden) a la petición HTTP.

El sitio web oficial de mod_evasive es [Enlace externo eliminado para invitados].

NOTA: existe un bug no corregido en el código de mod_evasive, que provoca un error en el manejo de uno de los contadores y puede llevar a que se bloqueen algunas peticiones legítimas.

Para mayor información acerca del bug y su correción, véase [Enlace externo eliminado para invitados].

Bien, primeramente añadiremos el repositorio de Lazos, que es quien nos brinda Mod_Evasive ya Fixeado.

Para ello, se debe crear el archivo /etc/yum.repos.d/lazos.repo con el siguiente contenido:

Código: Seleccionar todo

[lazos-noarch]
name=Repositorio LAZOS para CentOS - noarch
baseurl=http://repo.lazos.cl/centos/$releasever/noarch
enabled=1
gpgcheck=0

[lazos-$basearch]
name=Repositorio LAZOS para CentOS - $basearch
baseurl=http://repo.lazos.cl/centos/$releasever/$basearch
enabled=1
gpgcheck=0
Una vez hecho esto, instalamos Mod_Evasive:

Código: Seleccionar todo

yum install mod_evasive
Tras esto, configuraremos Mod_Evasive, el archivo de configuracion está en /etc/httpd/conf.d/mod_evasive.conf, les muestro una configuración de ejemplo.

Código: Seleccionar todo

# mod_evasive configuration
LoadModule evasive20_module modules/mod_evasive20.so

<IfModule mod_evasive20.c>
    # The hash table size defines the number of top-level nodes for each
    # child's hash table.  Increasing this number will provide faster
    # performance by decreasing the number of iterations required to get to the
    # record, but consume more memory for table space.  You should increase
    # this if you have a busy web server.  The value you specify will
    # automatically be tiered up to the next prime number in the primes list
    # (see mod_evasive.c for a list of primes used).
    DOSHashTableSize    3097

    # This is the threshhold for the number of requests for the same page (or
    # URI) per page interval.  Once the threshhold for that interval has been
    # exceeded, the IP address of the client will be added to the blocking
    # list.
    DOSPageCount        200

    # This is the threshhold for the total number of requests for any object by
    # the same client on the same listener per site interval.  Once the
    # threshhold for that interval has been exceeded, the IP address of the
    # client will be added to the blocking list.
    DOSSiteCount        100

    # The interval for the page count threshhold; defaults to 1 second
    # intervals.
    DOSPageInterval     10

    # The interval for the site count threshhold; defaults to 1 second
    # intervals.
    DOSSiteInterval     10

    # The blocking period is the amount of time (in seconds) that a client will
    # be blocked for if they are added to the blocking list.  During this time,
    # all subsequent requests from the client will result in a 403 (Forbidden)
    # and the timer being reset (e.g. another 10 seconds).  Since the timer is
    # reset for every subsequent request, it is not necessary to have a long
    # blocking period; in the event of a DoS attack, this timer will keep
    # getting reset.
    DOSBlockingPeriod   1

    # If this value is set, an email will be sent to the address specified
    # whenever an IP address becomes blacklisted.  A locking mechanism using
    # /tmp prevents continuous emails from being sent.
    #
    # NOTE: Requires /bin/mail (provided by mailx)
    DOSEmailNotify      [email protected]

    # If this value is set, the system command specified will be executed
    # whenever an IP address becomes blacklisted.  This is designed to enable
    # system calls to ip filter or other tools.  A locking mechanism using /tmp
    # prevents continuous system calls.  Use %s to denote the IP address of the
    # blacklisted IP.
    #DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"

    # Choose an alternative temp directory By default "/tmp" will be used for
    # locking mechanism, which opens some security issues if your system is
    # open to shell users.
    #
    #   http://security.lss.hr/index.php?page=details&ID=LSS-2005-01-01
    #
    # In the event you have nonprivileged shell users, you'll want to create a
    # directory writable only to the user Apache is running as (usually root),
    # then set this in your httpd.conf.
    #DOSLogDir           "/var/lock/mod_evasive"

    # You can use whitelists to disable the module for certain ranges of
    # IPs. Wildcards can be used on up to the last 3 octets if necessary.  
    # Multiple DOSWhitelist commands may be used in the configuration.
    #DOSWhitelist   127.0.0.1
    #DOSWhitelist   192.168.0.*
</IfModule>
Cada una de las opciones de configuracion se encuentra bien explicada en el archivo. Las mas importantes son:

DOSPageCount <valor> - Indica el valor del umbral para el numero de peticiones de una misma pagina (o URI) dentro del intervalo definido en DOSPageInterval. Cuando el valor del parametro es excedido, la IP del cliente se añade a la lista de bloqueos.

DOSSiteCount <valor> - Cuenta cuantas peticiones de cualquier tipo puede hacer un cliente dentro del intervalo definido en DOSSiteInterval. Si se excede dicho valor, el cliente queda añadido a la lista de bloqueos.

DOSPageInterval <valor> - El intervalo, en segundos, para el umbral de peticion de paginas.

DOSSiteInterval <valor> - El intervalo, en segundos, para el umbral de peticion de objetos de cualquier tipo.

DOSBlockingPeriod <valor> - Establece el tiempo, en segundos, que un cliente queda bloqueado una vez que ha sido añadido a la lista de bloqueos. Todo cliente bloqueado recibira una respuesta del tipo 403 (Forbidden) a cualquier peticion que realice durante este periodo.

DOSEmailNotify <e-mail> - Un e-mail sera enviado a la direccion especificada cuando una direccion IP quede bloqueada.

Tras esto, reiniciamos Apache para que los cambios surtan efecto.

Código: Seleccionar todo

service httpd restart
Para comprobar si Mod_Evasive verdaderamente esta funcionando, escribimos:

Código: Seleccionar todo

httpd -M
Y buscamos evasive20_module en la lista, si aparece, ya tienes instalado Mod_Evasive correctamente.

Fuente: [Enlace externo eliminado para invitados]

//Regards.
Ikarus: Backdoor.VBS.SafeLoader
Agnitum: Trojan.VBS.Safebot.A
http://indeseables.github.io/
Responder

Volver a “Linux”