ÀÌ·±ÂÊÀº Áªº´À̶ó
ÇöÀç ¸®´ª½º ¸ÞÀϼ¹ö¸¦ ¿î¿µÁßÀε¥ ±²ÀåÈ÷ ¸¹Àº SMTP Á¢±Ù ½Ãµµ°¡ ÀÖ½À´Ï´Ù.
ÀÏ´Ü Æ¯ÀÌ Á¢±Ù ½Ãµµ´Â
´ÙÀ½°ú °°Àº ¸í·É¾î·Î ¸®½ºÆ® ÃßÃâÀº Çß½À´Ï´Ù.
grep "LOGIN" /var/log/maillog | awk '{print $7 $8}' | sort | grep SASL | uniq -c | sort -r > /tmp/spamlist
ÀÌ·¸°Ô Çϸé
9226 unknown[XXX.XXX.XXX.XXX]:SASL
913 unknown[XXX.XXX.XXX.XXX]:SASL
7 unknown[XXX.XXX.XXX.XXX]:SASL
772 unknown[XXX.XXX.XXX.XXX]:SASL
69 unknown[XXX.XXX.XXX.XXX]:SASL
6846 unknown[XXX.XXX.XXX.XXX]:SASL
6719 unknown[XXX.XXX.XXX.XXX]:SASL
5 unknown[XXX.XXX.XXX.XXX]:SASL
5729 unknown[XXX.XXX.XXX.XXX]:SASL
50 unknown[XXX.XXX.XXX.XXX]:SASL
4 unknown[XXX.XXX.XXX.XXX]:SASL
4777 ipXXX.ip-xxx-xxx-xxx.net[XXX.XXX.XXX.XXX]:SASL
ÀÌ·¸°Ô ÃßÃâÀº µË´Ï´Ù.
±×·³ ¿©±â¼ ÀÏ´Ü ÃÖ¼Ò 20¹ø ÃÊ°ú ½Ãµµ¿¡ ÇÑÇÑ ½ÃµµÀÇ ¾ÆÀÌÇǸ¸ ÃßÃâÇß½À´Ï´Ù.
while read A B
do
if [ ${A} -gt 20 ]
then
echo ${B} |awk -F[ '{print $2}' |awk -F] '{print $1}' >> /tmp/blacklist
fi
done < /tmp/spamlist
±×·³ /tmp/blacklist ¾È¿¡´Â À§¿¡ ÃßÃâµÈ ¸®½ºÆ®Áß 20ȸ ÃÊ°úÇÏ´Â ½ÃµµÀÇ ¾ÆÀÌÇǸ¸ Àû¾îÁý´Ï´Ù.
±×·³ /tmp/blacklistÀÇ ÆÄÀÏÀ» Àоîµé¿©¼ firewall ¸í·É¾î (Centos 7)·Î
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='IP' reject"
¸¸ ½ÇÇàÇÏ°í ¹æȺ®À» Àç½ÃÀÛ ÇÏ¸é µË´Ï´Ù.
±×·¡¼ ÃÖÁ¾ ½ºÅ©¸³Æ®´Â
-------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
grep "LOGIN" /var/log/maillog | awk '{print $7 $8}' | sort | grep SASL | uniq -c | sort -r > /tmp/spamlist
while read A B
do
if [ ${A} -gt 20 ]
then
echo ${B} |awk -F[ '{print $2}' |awk -F] '{print $1}' >> /tmp/blacklist
fi
done < /tmp/spamlist
while read C
do
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='${C}' reject"
done < /tmp/blacklist
firewall-cmd --reload
-------------------------------------------------------------------------------------------------------------------------
À§¿Í °°ÀÌ ÇÏ¸é ½ÇÇàÀº Àߵ˴ϴÙ.
Á¦°¡ ÇÏ°í½ÍÀº°Ç spamlist ÆÄÀÏÀ̳ª blacklist ÆÄÀÏ µîÀÇ »ý¼ºÀ» ÃÖ¼ÒÈ ÇÏ°í
while do µîÀÇ Áߺ¹ »ç¿ëÀ» ÃÖ¼ÒÇÑ ÁÙÀÌ°íÀÚ ÇÕ´Ï´Ù.
Á¶¾ð ºÎŹµå¸³´Ï´Ù.
|
´Ù¸¥ ÀÌÀ¯·Î Fail2ban¿¡¼ ÀÌ ºÎºÐ¸¸ µû·Î »©³»¼ ±¸ÇöÇÏ·Á°í ÇÏ´ÂÁßÀÔ´Ï´Ù.