WordPress wp-login.php ve xmlrc.php ataklarını Modsecurity üzerinden IP adresini bir süre banlayarak engelleyebiliriz.
WHM panel üzerinden işlemin nasıl yapıyacağını, Modsecurity Kuralının(rule) nasıl ekleneceği ve yazmamız gereken kuralı aşağıda anlatmaya çalışacağım.
ModSecurity kuralları ile bağlantıları sınırlamak.
WHM panelde, “ModSecurity™ Tools” linkine tıklanır. arama kutusuna “mod” yazarsanız daha kolay erişirsiniz.
İlgili sayfada işlem kayıtlarını görebiliriz. Sayfanın üst sağ köşesinde “Rule List” tıklanır ve “Add Rule” ve “Edit Rule” seçenekleri bulunur. Yeni eklemek için “Add Rule”, düzenlemek için”Edit Rule” seçeneği kullanılır. Bir tane oluşturacağız.
Add Rule dedikten sonra çıkan metin kutusuna aşağıdaki kodları ekledikten sonra,
“Deploy and Restart Apache” ktusu işaretlenir ve kaydedilir(Save)…
# wp-login.php SecAction phase:1,nolog,pass,initcol:IP=%{REMOTE_ADDR},id:1000000 <LocationMatch "/wp-login\.php"> SecRule ip:FLAG_B "@gt 0" "phase:2,deny,status:403,log,msg:'WAF Rules : WordPress, 6 auth failures in 90 seconds - blocked for 5 minutes',id:1000001" SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.count_a=0,id:1000002" SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,id:1000003" SecRule REQUEST_METHOD "^POST$" "chain,setvar:ip.count_a=+1,deprecatevar:ip.count_a=6/90" SecRule ip:COUNT_A "@gt 5" "setvar:ip.flag_b=1,expirevar:ip.flag_b=300,setvar:ip.count_a=0" </LocationMatch> SecAction phase:1,nolog,pass,initcol:IP=%{REMOTE_ADDR},id:2000000 <LocationMatch "/wp-login\.php"> SecRule ip:FLAG_B "@gt 0" "phase:2,deny,status:403,log,msg:'WAF Rules : WordPress, 6 auth failures in 90 seconds - blocked for 5 minutes',id:2000002" SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.count_a=0,id:2000003" SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,id:2000004" SecRule REQUEST_METHOD "^GET$" "chain,setvar:ip.count_a=+1,deprecatevar:ip.count_a=6/90" SecRule ip:COUNT_A "@gt 5" "setvar:ip.flag_b=1,expirevar:ip.flag_b=300,setvar:ip.count_a=0" </LocationMatch> # xmlrpc.php SecAction phase:1,nolog,pass,initcol:IP=%{REMOTE_ADDR},id:3000000 <LocationMatch "/xmlrpc\.php"> SecRule ip:FLAG_B "@gt 0" "phase:2,deny,status:403,log,msg:'WAF Rules : WordPress, 6 auth failures in 90 seconds - blocked for 5 minutes',id:3000001" SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.count_a=0,id:3000002" SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,id:3000003" SecRule REQUEST_METHOD "^POST$" "chain,setvar:ip.count_a=+1,deprecatevar:ip.count_a=6/90" SecRule ip:COUNT_A "@gt 5" "setvar:ip.flag_b=1,expirevar:ip.flag_b=300,setvar:ip.count_a=0" </LocationMatch> SecAction phase:1,nolog,pass,initcol:IP=%{REMOTE_ADDR},id:400000 <LocationMatch "/xmlrpc\.php"> SecRule ip:FLAG_B "@gt 0" "phase:2,deny,status:403,log,msg:'WAF Rules : WordPress, 6 auth failures in 90 seconds - blocked for 5 minutes',id:400001" SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.count_a=0,id:400002" SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,id:400003" SecRule REQUEST_METHOD "^GET$" "chain,setvar:ip.count_a=+1,deprecatevar:ip.count_a=6/90" SecRule ip:COUNT_A "@gt 5" "setvar:ip.flag_b=1,expirevar:ip.flag_b=300,setvar:ip.count_a=0" </LocationMatch>
Yukarıdaki kural, wp-login.php, “GET” VE “POST” içindir. 5 Kez ard-arda kullanılırsa, ilgili IP adresi 6. denemesinde, 5 dakikalığına engellenmektedir. Süreyi değiştirmek için
expirevar:ip.flag_b=300
ilgili değeri saniye cinsinden girebilirsiniz.
Hits listesinde emgellenen IP adresini görebiliriz (alttaki resim )