SSH ¤Ø¤ÎÁíÅö¤¿¤ê¹¶·â(brute force attack)¤ÈËɱÒ
Posted by yoosee on Debian at 2005-11-08 23:42 JST1 SSH¤ËÂФ¹¤ë¥Ö¥ë¡¼¥È¥Õ¥©¡¼¥¹¹¶·â¤Ø¤ÎÂкö
sshd ¤Ø¤Î¥Ñ¥¹¥ï¡¼¥ÉÁíÅö¤¿¤ê¹¶·â¤Ïº£Ç¯¤ÎÁ°È¾¤¯¤é¤¤¤«¤éÈó¾ï¤ËÁý¤¨¤Æ¤¤¤Æ¡¢¡Ö¼ÂºÝ¤Ë guest ¤ä test ¤Ê¤É¤Î¥¢¥«¥¦¥ó¥È̾¤ò¾è¤Ã¼è¤é¤ì¤¿¡×¤È¸À¤¦¥±¡¼¥¹¤â¼Â¤Ï¤½¤³¤½¤³¤ÎÉÑÅÙ¤Çʹ¤¤¤Æ¤¤¤ë¡£»Å»ö¤Ç¤Ï´û¤ËËɸ楹¥¯¥ê¥×¥È¤ò»Å¹þ¤ó¤Ç¤¤¤ë¥µ¡¼¥Ð¤â¤¢¤ë¤¬¡¢ÌµËÉÈ÷¤Ê¥µ¡¼¥Ð¤Ë¼ÂºÝ¤Ë¤É¤ì¤¯¤é¤¤¤Î¹¶·â¤¬Íè¤Æ¤¤¤ë¤Î¤«¡¢¥í¥°¤ò¸«¤Æ¤ß¤¿¡£2 ¸ºß¤·¤Ê¤¤¥æ¡¼¥¶¤Ø¤Î¹¶·â
sshd ¤Ø¤Î¥¢¥¯¥»¥¹¤¬¼ºÇÔ¤¹¤ë¤È¡¢¾¯¤Ê¤¯¤È¤â FreeBSD ¤ä Debian ¤Ç¤Ï /var/log/auth.log ¤Ë¥á¥Ã¥»¡¼¥¸¤¬»Ä¤ë¡£¾å¤¬Â¸ºß¤·¤Ê¤¤¥æ¡¼¥¶¡¢²¼¤¬Â¸ºß¤¹¤ë¥æ¡¼¥¶¤Ø¤ÎÁíÅö¤¿¤ê¹¶·â¥í¥°¤ÎÎ㤳¤ì¤ò ruby ¤Î¥ï¥ó¥é¥¤¥Ê¡¼¤Ç̾Á°¤ÎÉôʬ¤À¤±ÀÚ¤ê½Ð¤·¤Æ¤ß¤ë¡£°Ê²¼¤Ç»È¤Ã¤¿¤Î¤ÏË¿½ê¥µ¡¼¥Ð¤Î 11·îʬ¤Î¥í¥°¡£Nov 8 11:29:47 example sshd[81317]: Failed password for invalid user jiseitai from 211.93.0.248 port 59039 ssh2
Nov 8 11:29:47 example sshd[81317]: Failed password for root from 211.93.0.248 port 59039 ssh2
# grep -c invalid /var/log/auth.log 18125 # ruby -e ' names = Array.new File.open("/var/log/auth.log").each do |line| if /invalid user (\w+) from/ =~ line then names.push $1 end end puts names.uniq.join(", ")' > list # wc list 1 8367 687528,367¼ïÎà¤Î¥¢¥«¥¦¥ó¥È̾¤Ç¡¢Ìó18,000²ó¤â¥¢¥¿¥Ã¥¯¤·¤Æ¤¤Æ¤¤¤ë¤è¤¦¤À¡£
3 ¹¶·â¸µ IP ¥¢¥É¥ì¥¹
¾åµ¤Î ruby ¥ï¥ó¥é¥¤¥Ê¡¼¤ò¾¯¤·ÊѤ¨¤Æ ip ¥¢¥É¥ì¥¹¤òÃê½Ð¤·¤Æ¤ß¤ë¡£# ruby -e ' ips = Hash.new(0) File.open("/var/log/auth.log").each do |line| if /Failed password for .+ from ([0-9\.]+) port/ =~ line then ips[$1] += 1 end end ips.sort{|a,b| b[1]<=>a[1]}.each do |ip, count| puts "#{count} - #{ip}" end'¤È¤¤¤¦´¶¤¸¤Ç¡£Àè¤Î¹¶·â¤Ï¸«¤Æ¤ß¤ë¤È 50 IP Addresses ¤«¤éÍè¤Æ¤ë¤è¤¦¤À¡£100·ï±Û¤¨¤¬ 17·ï¤Ç¡¢¤¦¤Á 1,000·ï±Û¤¨¤¬°Ê²¼¤Î 4·ï
whois ¤ÇÄ´¤Ù¤Æ¤ß¤ë¤È¡¢´Ú¹ñ¡¢Ãæ¹ñ¡¢Êƹñ¤È¤¤¤¦¸«»ö¤Ëŵ·¿Åª¤Ê¹¶·â¸µ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¡£5,272 - 219.240.75.45 (HANANET-HIGHBAN-MANTECH, Hananet Korean - hanaro.com)
3,387 - 211.93.0.248 (UNICOM, China United Telecommunication Corp. - cnuninet.com)
3,134 - 64.251.25.85 (INFOLINK-BLK-100, Infolink Information Services Inc. - infolink.com)
2,609 - 8.3.7.89 (LVLT, Level 3 Commucations, Inc. - level3.com)
4 ÁíÅö¤¿¤ê¹¶·â¤òËɸ椹¤ë¥¹¥¯¥ê¥×¥È¤ä»ÅÁȤß
¤³¤¦¤·¤¿¹¶·â¤òËɱҤ¹¤ë¤Ë¤Ï¡¢Î㤨¤Ð sshd ¤ÎÂÔ¤Á¼õ¤± port ¤òɸ½à¤Î 22/tcp ¤«¤éÊѹ¹¤·¤¿¤ê¡¢knockd ¤ò»È¤Ã¤Æ port ¤òÊĤ¸¤¿¤ê¡¢¤Þ¤¿¤Ï ssh ¤Î¥Ñ¥¹¥ï¡¼¥É¤Ë¤è¤ëǧ¾Ú¤òÀڤäƤ·¤Þ¤¦ÊýË¡¤¬¤¢¤ë¡£¤·¤«¤·¤É¤ì¤â¥æ¡¼¥¶¤ËÄÌÃΤʤêÍøÍÑ·ÁÂÖ¤ÎÊѹ¹¤ò¶¯¤¤¤ë¤¿¤á¡¢ÂçÀª¤Ç»È¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¿¾¯Æ³Æþ¤·¿É¤¤¡£¤È¸À¤¦¤³¤È¤Ç¥µ¡¼¥Ð¦¤Ç¹¶·â¥¢¥¯¥»¥¹¤Î¤ß¤òµñÈݤ¹¤ë»ÅÁȤߤ¬¤¢¤ë¤ÈÊØÍø¤Ê¤³¤È¤â¿¤¤¡£¸¶Íý¤È¤·¤Æ¤Ï´ðËÜŪ¤Ë¾åµ¤Î¤è¤¦¤Ê¥í¥°¤«¤é ¹¶·â¸µ¤Î IP ¥¢¥É¥ì¥¹¤òÈ´¤½Ð¤·¤Æ deny ¤¹¤ë¤â¤Î¤È¡¢¥Õ¥í¡¼À©¸æŪ¤Ëû»þ´Ö¤ËÊ£¿ô²ó¿ô¤Î ssh ¥¢¥¯¥»¥¹¤¬¤¢¤Ã¤¿¾ì¹ç¤Ë deny ¤¹¤ëÊýË¡¤¬¤¢¤ë¡£
- maxlogins.pl
- FreeBSD ÍѤȤʤäƤ¤¤ë¤¬ hosts.allow ¤ËÄɲ乤ë·Á¤Ê¤Î¤Ç Linux ¤¢¤¿¤ê¤Ç¤â»È¤¨¤½¤¦¡£¥í¥°¤ËÊ£¿ô²ó¤Î ssh login failure ¤¬¤¢¤ë¤È IP ¥¢¥É¥ì¥¹¤ò deny ¤ËÄɲ乤ë
- sshdfilter
- ¤³¤ì¤â¸¶Íý¤Ï»÷¤¿¤è¤¦¤Ê¤â¤Î¤Ç¡¢libwrap ¤ÎÂå¤ï¤ê¤Ë iptables ¤ò»È¤¦¤Î¤¬°Û¤Ê¤ëÅÀ¡£ÅöÁ³ *BSD ¤Ç¤Ï»È¤¨¤Ê¤¤¤±¤É¡¢ipf ¤Ë½ñ¤´¹¤¨¤ì¤Ð¤¤¤¤µ¤¤â¤¹¤ë¡£
- Blocking repeated failed login attempts via SSH
- ¤³¤ì¤â»÷¤¿¤è¤¦¤Ê¤â¤Î¡£
- ipt_recent
- ¤³¤ì¤Ï Linux iptables ¤Î ipt_recent ¥â¥¸¥å¡¼¥ë¤ò»È¤Ã¤Æ°ìÄê»þ´ÖÆâ¤ÎƱ°ì IP ¥¢¥É¥ì¥¹¤«¤é¤Î·«¤êÊÖ¤·¥¢¥¯¥»¥¹¤òµñÈݤ¹¤ë»ÅÁȤߡ£
5 SSH brute force ¹¶·â¤«¤é¥µ¡¼¥Ð¤ò¼é¤ë - ¤Þ¤È¤á
ºÇ½é¤Ëµó¤²¤¿½Õ»³¤µ¤ó¤Î¤â¤Î¤È·ë¶É¤¿¤¤¤·¤ÆÊѤï¤é¤Ê¤¤¤ï¤±¤À¤¬°ì±þ½ñ¤¤¤È¤¯¡£- ÆÃÄêIP¥¢¥É¥ì¥¹¤Î¤ß¤«¤é¤Î¥¢¥¯¥»¥¹¤òµö²Ä¤·¡¢Â¾¤ÏÁ´µñÈݤ¹¤ë
- sshd ¤Î listen port ¤ò 22/tcp ¤«¤é¾¤ÎǤ°Õ¤Î port ¤ËÊѹ¹¤¹¤ë
- sshd.conf ¤Î Port 22 ¤ò 22 °Ê³°¤ÎǤ°Õ¤Î¿ô»ú¤ËÊѹ¹
- ¤â¤·¤¯¤Ïport 22 ¤Ë knockd ¤ò»È¤¦
- ¥Ñ¥¹¥ï¡¼¥É¤Ë¤è¤ëǧ¾Ú¤ò¶Ø»ß¤¹¤ë (PasswordAuthentication no, ChallengeResponseAuthentication no)
- ÁíÅö¤¿¤ê¹¶·â¤ÎËɸ楹¥¯¥ê¥×¥È¤òƳÆþ¤¹¤ë
- ¥í¥°¤«¤é¹¶·â¤ò¸¡ÃΤ·¡¢libwrap ¤ä iptables, ipf Åù¤ÇµñÈÝ
- iptables ¤Îµ¡Ç½¤ò»È¤Ã¤ÆƱ¤¸IP¶õ¤ÎϢ³¥¢¥¯¥»¥¹¤ò¼«Æ°µñÈÝ
http://sourceforge.jp/pro ... /2/winf2005.pdf