How to stop bruteforce attacks

Discussion in 'Security' started by invisible, Aug 3, 2008.

  1. #1
    First, you'll need APF to be installed, I'm not going to go in details on how to setup the firewall, but you'll simply need it install so that BFD (brute force detector) can block the IP from trying to "brute force".

    Installing APF
    cd ~
    wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz
    tar -xvzf apf-current.tar.gz
    rm -f apf-current.tar.gz
    cd apf-*
    sudo sh install.sh

    Installing BFD
    cd ~
    wget
    http://www.rfxnetworks.com/downloads/bfd-current.tar.gz
    tar -xvzf bfd-current.tar.gz
    rm -f bfd-current.tar.gz
    cd bfd-*
    sudo sh install.sh

    Configuring BFD
    Use your favorite text editor (I prefer nano) to edit the configuration file,
    /usr/local/bfd/conf.bfd

    Find
    ALERT_USR="0"
    and replace it with
    ALERT_USR="1"

    Find
    EMAIL_USR="root"
    and replace it with
    ALERT_USR="your.email@webserver.com"

    Save your modifications and exit your editor, start BFD using the line
    /usr/local/sbin/bfd -s

    Now, whenever BFD will detect a bruteforce, it will email you at the email set above & BFD will run the command
    /etc/apf/apf -d the.attackers.ip

    The emails you will usually recieve look like this:
    Jul 29 08:22:40 yourhostname sshd[21642]: Invalid user manfred from the.attackers.ip
    Jul 29 08:22:40 yourhostname sshd[21643]: Invalid user michi from the.attackers.ip
    Jul 29 08:22:42 yourhostname sshd[21642]: Failed password for invalid user manfred from the.attackers.ip port 48215 ssh2
    Jul 29 08:22:42 yourhostname sshd[21643]: Failed password for invalid user michi from the.attackers.ip port 48223 ssh2
    Jul 29 08:22:44 yourhostname sshd[21646]: Invalid user michi from the.attackers.ip
    Jul 29 08:22:47 yourhostname sshd[21646]: Failed password for invalid user michi from the.attackers.ip port 48322 ssh2
    Jul 29 08:22:47 yourhostname sshd[21647]: Failed password for postgres from the.attackers.ip port 48329 ssh2
    Oh, and one thing I have done after I recieved the attack, I immeditaly changed the default SSH port. Use your favorite text editor (nano again!) to edit /etc/ssh/sshd_config

    Find
    #Port 22
    And uncomment the line (Remove the #) and replace the 22 by the port you want SSH to use (Max. port number is
    49151 so make sure you don't put anything past that. Afterwards, restart SSH. Usually on CentOS it is service sshd restart and in other operating systems, it is /etc/rc.d/init.d/sshd restart

    After getting attacked, I did a WHOIS on the IP (Run whois the.attackers.ip). You'll usually see one of the emails something like abuse@somedomain.com.

    Make sure to send them an email including the logs from the email, your server IP and the attackers IP.
     
    invisible, Aug 3, 2008 IP
  2. nimhost

    nimhost Active Member

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    i think cpanel has their own BF detection
     
    nimhost, Aug 15, 2008 IP
  3. blowingideas

    blowingideas Peon

    Messages:
    642
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    why not install denyhost? it’s a python script that analyzes the log messages to determine what hosts are trying to hack into the system. if ever a repeated attacks will be notice, the /etc/hosts.deny file will be then updated.
     
    blowingideas, Aug 15, 2008 IP
  4. MrEsper

    MrEsper Banned

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah your right. Its under 'Server Configuration' in WHM from what i can remember.
     
    MrEsper, Aug 15, 2008 IP
  5. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mdvaldosta, Aug 15, 2008 IP
  6. nimhost

    nimhost Active Member

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #6
    combining cpHulk with CSF and mod_security was the best :D
     
    nimhost, Aug 15, 2008 IP
  7. popowich

    popowich Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #7
    There are scripts available to monitor your ssh logs and put deny rules in your firewall to block IP's that generate too many ssh login failure attempts. Here are some examples. It would be best to only open up ssh (and other ports) to the networks that need them or you will be accessing them from. Also, if the attacks are out of control and not regular noise passing over you I'd consider submitting an abuse report to the ISP of the offending IP address.

    -Raymond
     
    popowich, Aug 15, 2008 IP
  8. nimhost

    nimhost Active Member

    Messages:
    235
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #8
    that was for freebsd :)
     
    nimhost, Aug 15, 2008 IP
  9. hostindya

    hostindya Banned

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    are useing any control panel
     
    hostindya, Aug 16, 2008 IP