Regole ModSecurity: appunti

Regole ModSecurity: appunti

ModSecurity è un web application firewall molto popolare che ormai viene incluso anche con tutti i principali pannelli di controllo hosting.

In aggiunta alla regole di sicurezza già incluse, è possibile scrivere regole personalizzate per bloccare vari tipi di attacchi, o particolari richieste che includono header invalidi, referrer indesiderati, ecc.

Nota: l'operatore @pm è molto più efficiente delle espressioni regolari.

Ecco alcuni esempi.

Bloccare il referer spam

SecRule REQUEST_HEADERS:Referer "@pm bottraffic4free.xyz bottraffic4free.club bottraffic.host getbottraffic4free.club trafficbot4free.host automatedtraffic4free.pw automatedtraffic4free.host websitebottraffic.host websitebottraffic.pw getbottraffic4free.xyz websitebottraffic.xyz websitebottraffic.club" \
"deny,log,auditlog,msg:'Bad Referer Blocked',id:'000000001'"

Per testare il corretto funzionamento della regola:

curl --referer https://websitebottraffic.host https://example.dev

Bloccare host indesiderati

SecRule REMOTE_HOST "@pm colocrossing fastwebserver torservers tor-exit exit-node basefarm healthcarecorporated poneytelecom psychz chociz contina solidseodedicated nedgree ioflood quadranet eqservers goloansusa siteslinks clickbridgemultimedia vpsnow 163data hostgator star-server iplannetworks thepiratebay secureserver hosteurope codero dreamhost weyantenterprises myserverhosts inmotionhosting" "deny,log,auditlog,msg:'Malicious Hostname Blocked',id:'000000002'"

Bloccare user agent indesiderati

SecRule REQUEST_HEADERS:User-Agent "@pm Icarus6j JCE chroot-apach0day Python-urllib winhttp.winhttprequest.5 EasouSpider semalt HTTrack trendictionbot tools.ua.random woopingbot Sogou FreeWebMonitoring seokicks &as_qdr=all voltron Daumoa magpie-crawler crazywebcrawler CRAZYWEBCRAWLER pornogig BLEXBot Synthesio Gigabot ASDF python-requests JDatabaseDriverMysqli JDatabaseDriverMysql O: AhrefsBot DigExt DTS Agent DarcyRipper GrapeshotCrawler SemrushBot proximic IAS GetIntent Gluten GrapeshotCrawler DomainCrawler" \
"deny,log,auditlog,msg:'Bad User Agent Blocked',id:'000000003'"

Per testare il corretto funzionamento della regola:

curl -H "User-Agent:Gigabot" https://example.dev

Risorsa

Guida di riferimento.

Ti sei mai detto "vorrei tanto parlare con un supporto tecnico più umano"?

INIZIA ORA