Proteger recursos web

    Es muy común ver accesos a contextos de administración, variables,… con la única finalidad de poder ejecutar y acceder de forma remota.
    En la mayoría, todos son ilícitos y vamos a identificar y bloquear:

    45.56.108.128 - - [19/Apr/2024:12:51:37 +0200] "GET /systembc/password.php HTTP/1.0" 403 - 766"-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/5                       37.36" 183 662
    83.147.93.226 - - [19/Apr/2024:13:08:15 +0200] "GET / HTTP/1.1" 403 - 890"-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" 186 643
    198.44.128.10 - - [19/Apr/2024:13:10:06 +0200] "HEAD /.env HTTP/1.1" 403 - 665"-" "Go-http-client/1.1" 78 304

    Para controlar dicha situación, se instaló Fail2Ban por lo que vamos a añadir un filtro y una jaula:

    cat > /etc/fail2ban/filter.d/webexploits.conf <<EOF
    [Definition]
    failregex = ^ -.*(GET|POST|HEAD).*(/\.env)
                ^ -.*(GET|POST|HEAD).*(/\.git)
                ^ -.*(GET|POST|HEAD).*(/\.well-known/probing\.txt)
                ^ -.*(GET|POST|HEAD).*(/systembc/password\.php)
                ^ -.*(GET|POST|HEAD).*(/phpMyAdmin/)
                ^ -.*(GET|POST|HEAD).*(/boaform/admin/)
                ^ -.*(GET|POST|HEAD).*(/cgi-bin/luci/)
                ^ -.*(GET|POST|HEAD).*(/vendor/phpunit/)
                ^ -.*(GET|POST|HEAD).*(/phpadmin/index\.php)
    ignoreregex =
    EOF

    cat > /etc/fail2ban/jail.d/wordpress.conf <<EOF
    [wordpress]
    enabled = true
    filter = wordpress
    port   = http,https
    banaction = iptables-multiport[name="WORDPRESS", port="http,https", protocol=tcp]
    maxretry = 2
    bantime  = 15m
    logpath  = %(apache_access_log)s
    EOF

    Finalmente, recargaremos la configuración:

    Leave a Reply

    Your email address will not be published. Required fields are marked *