Search Knowledge Base
Table of Contents
< Go Back To Home
Print

Stop BAD BOTS in cPanel / WHM Using ModSecurity Custom Rule Set (Easiest Way)

This is only applicable if you have a Linux based VPS or dedicated server with cPanel / WHM as Control Panel.

Know how you can create a custom rule in ModSecurity in your cPanel / WHM and stop bad bots and crawlers globally to improve overall stability and performance of your VPS or dedicated server.


How to Block?

  1. Login to WHM:
    1. Login to WHM by visiting your-domain.com/whm or https://your-domain.com:2087 (Change your-domain.com with your actual domain name of server IP address).
  2. Navigate and Open ‘ModSecurity Tools’ under ‘Security Center’ category.
  3. Click on ‘Rule List’ button available on the right side of the screen.
  4. Click on ‘Add Rule’ button available on the right side of the screen. You will reach a page which says ‘Add a new custom ModSecurity™ rule’.
  5. Paste the below code in the ‘box’ which says ‘Rule Text’
    SecRule REQUEST_HEADERS:User-Agent "@rx (?:BotNameHere|BotNameHere|BotNameHere)" "msg:'Spiderbot blocked',phase:1,log,id:7777771,t:none,block,status:403"
  6. Make sure that you paste the code starting from ‘SecRule’ ending 403″.
  7. Tick on ‘Enable Rule’ and ‘Deploy and Restart Apache’. (It will deploy the rule and restart Apache).
  8. Click on ‘Save’ button and you’re done.

Checking Results

  1. Login to WHM:
    1. Login to WHM by visiting your-domain.com/whm or https://your-domain.com:2087 (Change your-domain.com with your actual domain name of server IP address).
  2. Navigate and Open ‘ModSecurity Tools’ under ‘Security Center’ category.
  3. You will see ‘Hits List’ showing recent history.
  4. Simply search for ‘7777771’ and press enter to search all blocks related to the rule ID which we have created above.
  5. If it shows the list with status code as 404 then, you’ve successfully managed to stop the bad bots from accessing your server and saved plenty of server resources.

Congratulations! You’re server will start blocking the bots and show them 404 page stopping them to access your website or application.


Important Note:

  • Make sure to replace ‘BotNameHere’ with the BOT / user-agent you want to block.
  • You can add as many Bots in the above code. There is no restriction on the numbers.