Skip to main content
  1. Posts/

Using ModSecurity to Block Web Crawlers

·1 min·
modsec modsec apache

Web crawler (perayap) digunakan untuk mengindeks semua konten yang tersedia di internet termasuk website yang Anda miliki dan disimpan pada database search engine.

Namun beberapa perayan web melakukan request (GET) dalam jumlah yang tidak wajar pada satu waktu sehingga memberikan efek seperti DOS ke server dan menjadikan performa website menjadi menurun.

Berikut merupakan cara untuk memblokir bad bots menggunakan modsecurity.

Buat folder custom_rules

mkdir -p /etc/httpd/modsecurity.d/custom_rules

Selanjutnya buat rule modsec seperti contoh berikut.

nano /etc/httpd/modsecurity.d/custom_rules/badbots.conf
SecRule REQUEST_HEADERS:User-Agent "@rx (?:AhrefsBot)" "msg:'AhrefsBot Spiderbot blocked',phase:1,log,id:7777771,t:none,block,status:403"
SecRule REQUEST_HEADERS:User-Agent "@rx (?:MJ12bot)" "msg:'MJ12bot Spiderbot blocked',phase:1,log,id:7777772,t:none,block,status:403"
SecRule REQUEST_HEADERS:User-Agent "@rx (?:Yandex)" "msg:'Yandex Spiderbot blocked',phase:1,log,id:7777773,t:none,block,status:403"
SecRule REQUEST_HEADERS:User-Agent "@rx (?:SeznamBot)" "msg:'SeznamBot Spiderbot blocked',phase:1,log,id:7777774,t:none,block,status:403"

Atau Anda bisa membuatnya seperti berikut untuk memblokir beberapa badbots dengan 1 rule

# cat badbots.conf
SecRule REQUEST_HEADERS:User-Agent "@pmFromFile badbots.list" "msg:'badbots blocked',phase:1,log,id:7777771,t:none,block,status:403"

# cat badbots.list
AhrefsBot
MJ12bot
Yandex
SeznamBot

Edit konfigurasi mod_security.conf

<IfModule mod_security2.c>
Include modsecurity.d/custom_rules/*.conf
</IfModule>

Restart service apache.

systemctl restart httpd

Pastikan file rule yang dibuat sudah di load oleh server web.

# httpd -t -D DUMP_INCLUDES | grep custom
      (56) /etc/httpd/modsecurity.d/custom_rules/badbots.conf

Test rule dengan curl

curl -s -o /dev/null -w "%{http_code}" -A 'Mozilla/5.0 (compatible; SeznamBot/2.1; +http://www.google.com/bot.html)' http://example.com
$ curl -I -A 'Mozilla/5.0 (compatible; SeznamBot/2.1; +http://www.google.com/bot.html)' http://example.com
HTTP/1.1 403 Forbidden
Date: Fri, 20 Oct 2023 08:07:53 GMT
Server: Apache
Content-Type: text/html; charset=iso-8859-1

Related

Cara Menginstal ModSecurity di Apache
·2 mins
apache apache modsec
Enable Google PageSpeed Module
·2 mins
linux linux apache nginx
Enable Brotli Compression
·2 mins
linux apache nginx linux
Restoring Real Visitor IPs Cloudflare
·2 mins
cloudflare cpanel apache
Integrasi Apache dengan Passenger
·1 min
passenger python passenger apache
Menggunakan Apache Sebagai Proxy dan Load Balancer
·1 min
apache apache ubuntu