星期五, 三月 14, 2008

Shell Script: 來最多次的 IP, 抓前 10 名

一隻簡單的 Bash Script, 找出暴力攻擊 Server 的 IP, 然後不得已的情況, 就是把他擋掉....

Shell Script: tail -1000 /var/log/apache2/www-access.log | awk '{print $1}' | sort | uniq -c | sort -n | tail

取最後進來的 1000 筆 access log 來看, 觀察一下有沒有太誇張的 IP (特別是看有沒有是特別來亂的, ex: 開始亂塞些惡意的值)

列出大致如下:

  • 次數 和 IP
  • 10 xxx.xxx.xxx.x
  • 100 xxx.xx.xx.x
  • 300 xx.xx.x.x
  • ... 等 10 筆
再去 grep 最大量的那些 IP, 看看是不是來亂的, 如果是來亂的, 擋掉這個IP, 或視情況擋掉那個網段(Linux):
  • 擋掉 100.100.1.1 的 IP: iptables -I INPUT -s 100.100.1.1 -j DROP
  • 擋掉 100.100.0.0 整個網段: iptables -A INPUT -s 100.100.0.0/24 -j DROP
  • 解除: iptables -D INPUT -s 100.100.1.1 -j DROP
相關標籤

this is comment icon [回覆]

習慣 pf 的說 :P

Comment by 日落 (03/14/2008 19:18)

this is comment icon 回 日落 [回覆]

pf 是指 http://www.openbsd.org/faq/pf/ 這個嗎? (bsd only?)

Comment by Tsung (03/14/2008 19:42)

this is comment icon [回覆]

fail2ban這個套件不錯喔

Comment by cvictor (03/17/2008 04:01)

this is comment icon 回 cvictor [回覆]

嗯嗯, 真的是很不錯的套件, 感謝推薦~ :)

Comment by Tsung (03/17/2008 09:08)

this is comment icon 想起 Adrian Reber封锁部分中国大陆IP [回覆]

Andran Reber的Blog: http://lisas.de/blog/adrian/2008/Mar/12/
Comment by Antony (03/20/2008 23:41)

this is comment icon 回 Antony [回覆]

哈, 這真是太暴力了, 我是盡量能不封就不要封, 除非亂到太誇張... Orz...

Comment by Tsung (03/22/2008 23:30)
Add this page to del.icio.us Add this page to Yahoo Taiwan's bookmark Add this page to MyShare

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~