トップ «前の日記(2013-08-28) 最新 次の日記(2013-08-30)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2013-08-29 :-(

_ 午前

0520 起床

0900 出勤 && 自習

_ 午後

1300 自習

_

1800 退勤

1930 おうちサーバーほげ

2130 飯

_ [SSH][ruby][GeoIP][gem][攻撃][セキュリティ]SSH ブルートフォースアタック 攻撃元の国トップ10

環境

準備

hosts.deny

DenyHosts を導入済みであり hosts.deny にある程度 記録されていることとする。

hosts.deny はこんな感じになっている。

ALL : ALL

sshd: 218.61.11.78
sshd: 118.145.25.90
sshd: 211.154.151.150
sshd: 218.108.85.240
sshd: 218.248.30.116
sshd: 114.255.40.1
gem geoip

cjheath/geoip をインストールしておく。

% gem install geoip

GeoIP データベースが必要なので REQUIREMENTS にあるとおりにダウンロードしておく。

% wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
% tar xzf GeoIP.dat.gz

コード

# -*- coding: utf-8 -*-

# cjheath/geoip https://github.com/cjheath/geoip

require 'geoip'

def build_hosts(hosts_file)
  hosts ||= []
  lines = File.open(hosts_file).readlines()
  lines.each{|line|
    if line =~ /^sshd/
      hosts << line.gsub('sshd: ', '').chomp
    end
  }
  return hosts
end

def build_geoip(geoip_dat)
  return geoip = GeoIP.new(geoip_dat)
end

def main(argv)
  hosts_file = argv[0]
  geoip_dat = argv[1]
  
  hosts = build_hosts(hosts_file)
  geoip = build_geoip(geoip_dat)
  
  countries ||= {}
  countries.default = 0
  
  hosts.each{|host|
    c3 = geoip.country(host).country_code3
    countries[c3] += 1
  }
  
  countries.sort {|a, b| (b[1] <=> a[1]) }.each{|c|
    puts "#{c[0]} #{c[1]}"
  }
end

main(ARGV)

実行

トップ 10

% ruby denyhosts.rb  hosts.deny GeoIP.dat | head
CHN 649
USA 142
KOR 111
IND 47
RUS 40
DEU 33
TWN 27
GBR 27
BRA 26
TUR 25

_ ,

Filtering attacks from China and Korea using FreeBSD and pf - BSD Security

これはさすがにやり過ぎかと思うけど CHN はたしかに弾いていいかもしれんなあ。

_ [艦これ]艦これ

五十鈴さんゲット