El 04/09/2015 a las 14:49, Hugo Florentino escribió:
Hola colegas,

Por estos días estoy montando un servidor web con Nginx (en Debian
Jessie) y al revisar las trazas me han llamado la atención unas entradas:

En /var/log/nginx/access.log:
115.230.127.237 - - [04/Sep/2015:14:13:16 -0400] "GET
http://zc.qq.com/cgi-bin/common/attr?id=260714&r=0.0623891042912144
HTTP/1.1" 404 200 "-" "Mozilla/5.0 (comp
atible; MSIE 9.0; Windows NT 6.1; Trident/5.0; 360SE)"

En /var/log/nginx/error.log:
2015/09/04 14:13:16 [error] 59274#59274: *16 open()
"/var/www/html/cgi-bin/common/attr" failed (2: No such file or
directory), client: 115.230.127.237, server: _,
  request: "GET
http://zc.qq.com/cgi-bin/common/attr?id=260714&r=0.0623891042912144
HTTP/1.1", host: "zc.qq.com"

Tengo pensado trastear las reglas de naxsi y además hacer unas reglitas
para fail2ban, pero alguien sabe si existen medidas adicionales que
puedan tomarse en la propia configuración de Nginx para minimizar el
riesgo de tales intentos de explotar posibles vulnerabilidades?

He instalado Nginx (variante nginx-naxsi del repositorio dotdeb) y he
aqui el contenido del archivo /etc/nginx/sites-available/default:

server {
   listen 80 default_server;
   server_name _;

   root /var/www/html;

   index index.html;

   location / {
     try_files $uri $uri/ =444;
   }

   location ~* \.(ico|gif|png|jp(e|e?g)|css|js|eot)$ {
     valid_referers none blocked server_names elequipo.eldominio.tld
eldominio.tld;
     if ($invalid_referer) {
       return 403;
     }
   }

   location ~ \.php$ {
     fastcgi_read_timeout 20s;
     fastcgi_intercept_errors off;
     include fastcgi_params;
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     set $SavedPathInfo $fastcgi_path_info;
     fastcgi_param PATH_INFO $SavedPathInfo;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     try_files $fastcgi_script_name =444;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_index index.php;
   }
}




______________________________________________________________________
Lista de correos del Grupo de Usuarios de Tecnologías Libres de Cuba.
Gutl-l@jovenclub.cu
https://listas.jovenclub.cu/cgi-bin/mailman/listinfo/gutl-l
tengo algo como esto puesto en un archivo que incluyo en la sección server, de mis servidores nginx uso la versión 1.8.0 del repo oficial de la propia nginx.org.
######################################################################
        ## Block some common exploits
        ######################################################################
        set $common_exploit 0;
        if ($query_string ~ "proc/self/environ") {
                set $common_exploit 1;
        }
        if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
                set $common_exploit 1;
        }
        if ($query_string ~ "base64_(en|de)code\(.*\)") {
                set $common_exploit 1;
        }
        if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
                set $common_exploit 1;
        }
        if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
                set $common_exploit 1;
        }
        if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
                set $common_exploit 1;
        }
        if ($common_exploit = 1) {
                return 403;
        }

        ######################################################################
        ## File injection protection
        ######################################################################
        set $file_injection 0;
        if ($query_string ~ "[a-zA-Z0-9_]=http://";) {
                set $file_injection 1;
        }
        if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
                set $file_injection 1;
        }
        if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
                set $file_injection 1;
        }
        if ($file_injection = 1) {
                return 403;
        }
        
        ######################################################################
        ## SQL injection first line of defence (NOT comprehensive!)
        ######################################################################
        set $sql_injection 0;
        if ($query_string ~ "concat.*\(") {
                set $sql_injection 1;
        }
        if ($query_string ~ "union.*select.*\(") {
                set $sql_injection 1;
        }
        if ($query_string ~ "union.*all.*select.*") {
                set $sql_injection 1;
        }
        if ($sql_injection = 1) {
                return 403;
        }

        ######################################################################
        ## Basic anti-spam
        ######################################################################
        set $looks_like_spam 0;
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
                set $looks_like_spam 1;
        }
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
                set $looks_like_spam 1;
        }
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
                set $looks_like_spam 1;
        }
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
                set $looks_like_spam 1;
        }
        if ($looks_like_spam = 1) {
                return 403;
        }
######################################################################
        ## User agent blocking
        ##
        ## Disables access to your site by user agent. Useful to block some
        ## bandwidth hoggers.
        ######################################################################
        set $bad_ua 0;  
        # This also disables Akeeba Remote Control 2.5 and earlier
        if ($http_user_agent ~ "Indy Library") {
                set $bad_ua 1;
        }
        # Disabling Wget will also block the most common method to run CRON 
jobs        
        if ($http_user_agent ~ "Wget") {
                set $bad_ua 1;
        }       
# Common bandwidth hoggers and hacking tools. Each rule is three lines, beginning with "if"
        if ($http_user_agent ~ "libwww-perl") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "Download Demon") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "GetRight") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "GetWeb!") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "Go!Zilla") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "Go-Ahead-Got-It") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "GrabNet") {
                set $bad_ua 1;
        }
        if ($http_user_agent ~ "TurnitinBot") {
                set $bad_ua 1;
        }
        # If you enable any of the above don't remove this. It's what blocks
        # the bad user agents!
        if ($bad_ua = 1) {
                return 403;
        }


--
Ing. Arian Molina Aguilera
Administrador de Redes y Servicios Telemáticos
Nodo Central ARTex S.A. La Habana. Cuba.
Telfs: +53(7)2047874, +53(7)204-2710 ext 123
jabber: ar...@artex.sa
Linux Usuario Registrado #392892




______________________________________________________________________
Lista de correos del Grupo de Usuarios de Tecnologías Libres de Cuba.
Gutl-l@jovenclub.cu
https://listas.jovenclub.cu/cgi-bin/mailman/listinfo/gutl-l

Reply via email to