2010年11月5日 星期五

SIP Attack



最近遇到Asterisk架設的SIP Server服務fail
看了一下執行的log,有一堆IP在try帳號


google了一下,發現解法
http://www.51asterisk.com/read.php?tid=1354


解釋一下上述的方法
1.使用iptables來阻擋特定的IP
 iptables -I asterisk -s $ip -j DROP
 連結直接擋掉整個IP


 也可以只擋掉5060服務
 iptables -I asterisk -p udp --dport 5060 -s $ip -j DROP



2.IP藉由分析asterisk log檔來得到
 連結使用perl撰寫,來得到特定行為的IP(用特定字串來搜尋)。
 比對和目前iptables chain中的IP是否重複
 沒有重複的話,才加到iptables chain中。


 由於該script檔有ip累計次數功能
 修改成 try帳號次數超過#次,才加入iptables chain檔中
 if (exists $currblocked{ $ip }) {
            print "$ip already blocked\n";
} else {
            if($count > #){
                $action = `/sbin/iptables -I asterisk -s $ip -j DROP`;
                print "$ip blocked. $count attempts.\n"; 
            }else {
                print "$ip: try $count times. less than # attempts.\n";
            }              
        }

沒有留言:

張貼留言