LoginSignup
4
4

More than 5 years have passed since last update.

不正アクセスにイライラする編

Last updated at Posted at 2018-01-02

サーバを運用していると、不正アクセスに頻繁に遭遇します。

# last -f /var/log/btmp

こんな感じで、ログインに失敗したアクセスの一覧を見ることができます。件数を限定するために、 | head を付けると良いかもしれません。

# last -f /var/log/btmp | head
masayuki ssh:notty    114.200.199.45   Tue Jan  2 13:52    gone - no logout
masayuki ssh:notty    114.200.199.45   Tue Jan  2 13:52 - 13:52  (00:00)
centos   ssh:notty    c-67-168-83-230. Tue Jan  2 13:23 - 13:52  (00:28)
centos   ssh:notty    c-67-168-83-230. Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)
root     ssh:notty    14.116.171.251   Tue Jan  2 13:23 - 13:23  (00:00)

リアルタイムにアタックをかけられている最中だと、なんとなくイライラします。

IPアドレスベースで見るためには、-i オプションを使います。

# last -i -f /var/log/btmp | awk '{print $3}' | sort | uniq -c | sort -rn | head

こんな感じにすると、過去の一覧をランキング形式で見ることができます。

# last -f /var/log/btmp | awk '{print $3}' | sort | uniq -c | sort -rn | head
 215737 58.242.83.34
 163529 58.242.83.17
 134798 58.242.83.18
 130636 58.242.83.38
 111747 58.242.83.27
 100762 58.242.83.36
  98506 58.242.83.24
  88019 42.7.26.15
  86996 182.100.67.120
  86298 113.195.145.80

左がログイン試行回数、右がアクセス元のIPアドレスです。
58.242.83.17~38が物凄いですね。悪の巣窟なんでしょうか。

どこのIPセグメントかは whois で見ることができます。(一部略)

# whois 58.242.83.17

% Information related to '58.242.81.0 - 58.242.86.255'

% Abuse contact for '58.242.81.0 - 58.242.86.255' is 'hqs-ipabuse@chinaunicom.cn'

inetnum:        58.242.81.0 - 58.242.86.255
netname:        HUAIBEIBASIP
country:        CN

ちなみに、不正アクセス元は9割近くが中国からです。続いてロシア。

iptablesを使っている場合は、特定のセグメントからのアクセスを遮断(パケットをドロップ)できます。

# vi /etc/sysconfig/iptables
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
(略)
-A INPUT -s 58.242.83.0/24 -j DROP
(略)
COMMIT
# systemctl restart iptables

で再読込。

# iptables -nL

で確認ができます。

まぁ、sshのリッスンポートを22から他に移す のが、お手軽ですけどね。

4
4
1

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
4
4