LoginSignup
9
8

More than 5 years have passed since last update.

ufwで簡単firewall(ブルートフォース対策)

Posted at

某VPSでDebian8を動かしているがiptablesの設定が面倒くさい(勉強不足)ので
Ubuntuに標準で入っているufw(Uncomplicated FireWall)をDebianに入れた。

ちなみに、以前はiptables-persistentを使い普通に記述していた。

以前の設定はこんな感じ

# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Allows SSH connections
# The --dport number is the same as in /etc/ssh/sshd_config
-A INPUT -p tcp -m state --state NEW --dport 10022 -j ACCEPT

この程度ならば直接記述した方が早い。
でも、DoS回避のために試行回数制限(hashlimit)を使おうとすると面倒。

# 1分間に3回アクセスor全体で6回アクセスしてきたipアドレスからの接続を60000ms(1m)拒否
$ iptables -A INPUT -p tcp -m state --syn --state NEW --dport 1022 
-m hashlimit --hashlimit-name limit_sshd --hashlimit 3/m --hashlimit-burst 6 
--hashlimit-mode srcip --hashlimit-htable-expire 60000 -j ACCEPT

「この程度理解できなければサーバ管理なんてできない」と思われる方もいますが、できれば面倒は避けたい。



なのでufwを使う。

#30秒間に6回アクセスしてきた IP の接続を一定時間拒否する。
$sudo ufw limit 10022
$sudo ufw status
To                         Action      From
--                         ------      ----
10022                      LIMIT       Anywhere
10022                      LIMIT       Anywhere (v6)

はい、簡単にできました。(IPv6も自動的にやってくれてる。)

これで「IPV6はとりあえず全部拒否しとけ」とかやらずに済みます。



※何か間違いがあったら指摘お願いします。(特にiptablesのルール)






ufw limit の回数制限が"30秒間に6回アクセス"の根拠(一定時間は不明)

[http://manpages.ubuntu.com/manpages/raring/man8/ufw.8.html:title]

ufw will deny connections if an IP address has attempted to initiate 6 or more connections in the last 30seconds.



参考:iptablesの設定例

[http://www.atmarkit.co.jp/ait/articles/1007/14/news102_2.html:title]

[http://qiita.com/homihomu/items/778770a1c1b3b2371fe0:title]

9
8
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
9
8