LoginSignup
3
2

More than 5 years have passed since last update.

su失敗してくるグローバルIPアドレスをランキング表示

Posted at

環境

  • CentOS7

「最後の正しいログインの後に 33 回の失敗ログインの試行があります」とメッセージが表示されたのでlastbで確認してみたところ、数万件以上のグローバルIPアドレスからsu試行が確認されたので、慌ててIP制限しました。

IPアドレスでランキング

lastbの結果だと空白区切りだったのでカンマ区切りに変換して出力。

# lastb | tr -s ' ' ',' > lastb_log.txt

# ls -ltr
total 7176
-rw-r--r-- 1 root root 7344672 Sep 21 17:23 lastb_log.txt

3カラム目をソートしてカウントしたものから上位10個を出力。

# cat lastb_log.txt |cut -f 3 -d ',' | sort |uniq -c|sort -nr|head -10

  44541 xxx.xxx.xxx.xxx
  12015 xxx.xxx.xxx.xxx
   8664 xxx.xxx.xxx.xxx
   7074 xxx.xxx.xxx.xxx
   6319 xxx.xxx.xxx.xxx
   6192 xxx.xxx.xxx.xxx
   5049 xxx.xxx.xxx.xxx
   4722 xxx.xxx.xxx.xxx
   1792 xxx.xxx.xxx.xxx
   1792 xxx.xxx.xxx.xxx

ちょっと多すぎたので今日の分だけでランキング。

# grep 'Sep,21' lastb_log.txt | cut -f 3 -d ',' | sort |uniq -c|sort -nr|head -10

676 xxx.xxx.xxx.xxx
141 xxx.xxx.xxx.xxx
 52 xxx.xxx.xxx.xxx
 22 xxx.xxx.xxx.xxx
 12 xxx.xxx.xxx.xxx
 11 xxx.xxx.xxx.xxx
  8 xxx.xxx.xxx.xxx
  3 localhost
  2 xxx.xxx.xxx.xxx

これらをhosts.denyに追記っと。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2