freebsd:pf
差異處
這裏顯示兩個版本的差異處。
| 下次修改 | 前次修改 | ||
| freebsd:pf [2007/08/07 22:10] – 建立 wenpei | freebsd:pf [2010/04/06 12:14] (目前版本) – wenpei | ||
|---|---|---|---|
| 行 22: | 行 22: | ||
| # 允許列表中的 IP 登入 ssh | # 允許列表中的 IP 登入 ssh | ||
| pass in on $ext_if proto tcp from < | pass in on $ext_if proto tcp from < | ||
| + | |||
| + | # 允許所有 IP 連接網頁伺服器 | ||
| + | pass in on $ext_if proto tcp from any to any port = 80 | ||
| + | pass in on $ext_if proto tcp from any to any port = 443 | ||
| </ | </ | ||
| 行 30: | 行 34: | ||
| # / | # / | ||
| + | |||
| + | ====== SSH Brute Force Blocker with PF on FreeBSD ====== | ||
| + | http:// | ||
| + | |||
| + | / | ||
| + | table < | ||
| + | block quick from < | ||
| + | |||
| + | 程式碼 | ||
| + | < | ||
| + | # | ||
| + | |||
| + | use strict; | ||
| + | |||
| + | my @assholes = (); | ||
| + | |||
| + | open (IN, "/ | ||
| + | while (< | ||
| + | if ($_ =~ /Invalid user.*from ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ | ||
| + | push(@assholes, | ||
| + | } | ||
| + | if ($_ =~ /Did not receive identification string from ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ | ||
| + | push(@assholes, | ||
| + | } | ||
| + | } | ||
| + | close (IN); | ||
| + | |||
| + | @assholes = sort {lc($a) cmp lc($b)} @assholes; | ||
| + | |||
| + | my @allowedIPs = (); | ||
| + | open (IN, "/ | ||
| + | while (< | ||
| + | if ($_ =~ / | ||
| + | push(@allowedIPs, | ||
| + | } | ||
| + | } | ||
| + | close (IN); | ||
| + | |||
| + | chop(@allowedIPs); | ||
| + | |||
| + | my $tmp = ""; | ||
| + | foreach my $asshole (@assholes) { | ||
| + | if ($asshole eq $tmp) { | ||
| + | $asshole = ""; | ||
| + | } else { | ||
| + | if ($asshole =~ / | ||
| + | $asshole = ""; | ||
| + | } | ||
| + | if ($asshole =~ / | ||
| + | $asshole = ""; | ||
| + | } | ||
| + | foreach my $allowedIP (@allowedIPs) { | ||
| + | if ($asshole =~ / | ||
| + | $asshole = ""; | ||
| + | } | ||
| + | } | ||
| + | $tmp = $asshole; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | @assholes = sort {lc($b) cmp lc($a)} @assholes; | ||
| + | |||
| + | my $popCount = 0; | ||
| + | foreach my $asshole (reverse @assholes) { | ||
| + | if ($asshole eq "" | ||
| + | $popCount++; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | for (my $i = 0; $i < $popCount; $i++) { | ||
| + | pop (@assholes); | ||
| + | } | ||
| + | |||
| + | my $list = ""; | ||
| + | foreach my $asshole (@assholes) { | ||
| + | $list = $list . $asshole . " "; | ||
| + | } | ||
| + | |||
| + | exec "/ | ||
| + | </ | ||
| + | |||
| + | 加入 Syslog 中 | ||
| + | / | ||
| + | auth.info; | ||
| + | |||
| + | 例外之黑/ | ||
| + | < | ||
| + | touch / | ||
| + | chmod 644 / | ||
| + | touch / | ||
| + | chmod 644 / | ||
| + | </ | ||
| + | |||
| + | 觀看已經紀錄的列表 | ||
| + | pfctl -t bruteforce -T show | ||
| + | |||
| + | ====== Denyhosts ====== | ||
| + | Reference: http:// | ||
| + | |||
| + | |||
| + | |||
freebsd/pf.1186495827.txt.gz · 上一次變更: 由 wenpei
