Blog | G5 Cyber Security

Block Vulnerability Scanners with .htaccess

TL;DR

Protect your shared hosting account from automated vulnerability scanners by blocking their user agents in your .htaccess file. This guide shows you how.

Blocking Vulnerability Scanners with .htaccess

  1. Understand the Risk: Automated scanners try to find weaknesses on websites. While not all are malicious, they can overload your server and potentially identify real vulnerabilities that attackers could exploit.
  2. Locate Your .htaccess File: This file is usually in your website’s root directory (e.g., public_html or www). If you can’t find it, create a new text file and name it .htaccess. Make sure your FTP client shows hidden files (usually an option in the settings).
  3. Edit Your .htaccess File: Open the .htaccess file with a plain text editor (like Notepad on Windows or TextEdit on Mac – avoid Word processors!). Add the following code to block common scanner user agents.
RewriteEngine On
# Block specific scanners
RewriteCond %{HTTP_USER_AGENT} (Nikto|DirBuster|OWASP ZAP|sqlmap|Burp Suite|Acunetix|Nessus|OpenVAS) [NC]
RewriteRule .* - [F,L]

Explanation:

  1. Add More Scanners: You can add more scanner user agents to the list within the parentheses, separated by pipes (|). Research common scanners to keep your blocklist up-to-date. For example:
    RewriteCond %{HTTP_USER_AGENT} (Nikto|DirBuster|OWASP ZAP|sqlmap|Burp Suite|Acunetix|Nessus|OpenVAS|HTTrack Website Copier) [NC]
  2. Save the File: Save your changes to the .htaccess file.
  3. Test Your Block: Use a tool like WhatIsMyUserAgent to simulate one of the blocked user agents and confirm you get a ‘403 Forbidden’ error when trying to access your website.
  4. Monitor Your Logs: Regularly check your server logs for any suspicious activity, even after implementing these blocks. Shared hosting providers usually offer log access through their control panel (cPanel, Plesk, etc.).

Important Considerations

Exit mobile version