Want to subscribe to topics you're interested in?
Become a Member

Nginx Nginx down when DDoS

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Oxide, Apr 18, 2016.

  1. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    Can you please share (if you want) the content of your:

    Code:
    /etc/fail2ban/jail.local
    Thanks !!!

     
  2. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    Its this:

    Code:
    [pingback]
    enabled = true
    port = http,https
    filter = pingback
    logpath = /var/log/nginx/access.log
    backend  = polling
    journalmatch =
    maxretry = 1
    findtime = 1
    bantime = 86400
    action = iptables-allports
     
  3. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    So i just edit the :

    Code:
    /etc/fail2ban/jail.local
    and add inside:

    Code:
    [Definition]
    
    failregex = ^<HOST> -.*WordPress.*/
     
    
    Jail:
    
    [pingback]
    enabled = true
    port = http,https
    filter = pingback
    logpath = /var/log/nginx/access.log
    backend  = polling
    journalmatch =
    maxretry = 1
    findtime = 1
    bantime = 86400
    action = iptables-allports
    restart fail2ban and try it?
     
  4. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    Nop.

    Inside filter.d folder you create a file with the name pingback.conf
    Inside that file you paste:
    Code:
    [Definition]
    
    failregex = ^<HOST> -.*WordPress.*/
    Then in file jail.local you add:
    Code:
    [pingback]
    enabled = true
    port = http,https
    filter = pingback
    logpath = /var/log/nginx/access.log
    backend  = polling
    journalmatch =
    maxretry = 1
    findtime = 1
    bantime = 86400
    action = iptables-allports
    Restart fail2ban.

    Then run: fail2ban-client status
    It should return the new jail.
     
  5. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    Do you use any other rules there as:

    Code:
    [sshd]
    enabled = true
    or any other in general that will help to block system attacks or in general some booter attacks?
     
  6. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    6:22 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    not needed for sshd as CSF Firewall's LFD (Login Failure Daemon) takes care of that CSF Firewall - CentminMod.com LEMP Nginx web stack for CentOS

    Code (Text):
    tail -3 /var/log/lfd.log
    Sep  6 08:28:05 hostname lfd[28424]: (sshd) Failed SSH login from 91.200.12.122 (UA/Ukraine/dedic805.hidehost.net): 5 in the last 3600 secs - *Blocked in csf* [LF_SSHD]
    
    Sep  6 12:55:47 hostname lfd[17684]: (sshd) Failed SSH login from 185.110.132.89 (RU/Russian Federation/-): 5 in the last 3600 secs - *Blocked in csf* [LF_SSHD]
    
    Sep  6 13:06:27 hostname lfd[20234]: 185.56.82.22 (NL/Netherlands/-), 5 distributed sshd attacks on account [root] in the last 3600 secs - *Blocked in csf* [LF_DISTATTACK]
    
     
  7. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    Ok great :)

    Waiting for Revenge for any other rules that he has already try and will help :)
     
  8. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    I don't use CSF, so i use the rule to ban ips that failed to login.

    I also use a rule for those people that press F5 continually in our site, leading the load to rise. It will ban the IP for 15 minutes anyone that remembers to do that.
    I can do this, while excluding some folders. This is something CSF cannot do.
     
  9. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    6:22 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    nice so basically a failregex of GETs and ignoregex on specific folders :cool:
     
  10. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    I was asking for other rules for fail2ban that will help with booters and not for csf :)
     
  11. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    Exactly, i need that for IPS 4.1. To exclude the folder from where js and css are loaded. I believe Xenforo must be something similar.
     
    Last edited: Sep 7, 2016
  12. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    For booters i only use that one. Every booter that i've seen, the only strong attack they have for Layer 7 is the xml-rpc. This rule protects against that with the help of nginx returning a 444 to them.

    The other type of attacks are Layer 4, and no software on your server can do something against that. Only a dedicated anti-ddos. If you are with OVH, they are really good against Layer 4 attacks.
     
  13. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    So you use also an Nginx rule for that?

    Code:
    if ($http_user_agent ~* "PHP|curl|Wget|HTTrack|Nmap|Verifying|PingBack|Pingdom|Joomla|Wordpress") { return 444; } 
    I think that can be done also with the block file of Centminmod:

    Code:
        if ($http_user_agent ~ "Wordpress") {
            set $block_user_agents 1;
        }
    Do i have to enable it when i am under attack or is it automated?
     
  14. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    Centminmod already have that protection included.
    Yep, OVH anti-ddos is automated. Many booters even have a dedicated method against OVH, and most of the times it does not work anyway. You can see from there how much OVH is good and they need to create special methods against it.
     
  15. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    Just notice that you use:

    Code:
    logpath = /var/log/nginx/access.log
    Is that ok or i must use:

    Code:
    /home/nginx/domains/mydomain.com/log/access.log
    confused :(
     
  16. Revenge

    Revenge Active Member

    469
    93
    28
    Feb 21, 2016
    Portugal
    Ratings:
    +354
    Local Time:
    9:22 AM
    1.9.x
    10.1.x
    You need to change that path to the correct one on your server ;)
     
  17. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    I was thinking to enable email alerts for this but if fail2ban ban 5.000 ip's i will get 5.000 emails?

    How do you handle this?
     
  18. cloud9

    cloud9 Active Member

    437
    118
    43
    Oct 6, 2015
    England
    Ratings:
    +221
    Local Time:
    9:22 AM
    1.25.3
    10.6.x
    @pamamolf Are you going to be using fail2ban with csf?
     
  19. pamamolf

    pamamolf Well-Known Member

    4,125
    429
    83
    May 31, 2014
    Ratings:
    +841
    Local Time:
    11:22 AM
    Nginx-1.29.x
    MariaDB 10.6.x
    yes..
     
  20. cloud9

    cloud9 Active Member

    437
    118
    43
    Oct 6, 2015
    England
    Ratings:
    +221
    Local Time:
    9:22 AM
    1.25.3
    10.6.x
    Ok, thanks, with IPS 4.x as well ?

    If its all working well for you and you have finished tinkering let us know your final configs (if different fro above)