原文地址:
https://www.bro.org/sphinx/frameworks/geoip.html
在处理策略脚本的时候可能需要知道一个ip地址所在的地理区位。Bro支持GeoIP库。为了使用这个功能,您需要先安装libGeoIP软件,并在构建Bro之前安装GeoLite city数据库。
安装libGeoIP:
在构建Bro之前需要安装libGeoIP
FreeBSD:
sudo pkg install GeoIP
RPM/RedHat-based Linux:
sudo yum install GeoIP-devel
DEB/Debian-based Linux:
sudo apt-get install libgeoip-dev
Mac OS X:
从你喜欢的包管理系统中安装(比如MaccPorts, Fink, Homebrew)。你所需要的包的名字可能是libgeoip, geoip, geoip-dev,这依赖于你所使用的管理系统。
GeoIPLite数据库安装:
下载GeoLite city binary database:
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
文件需要重命名并且放在GeoIP数据库目录下。这个目录应该已经存在,它会根据你使用的平台和包而变化。对于FreeBSD而言,使用/usr/local/share/GeoIP。对于linux,使用/usr/share/GeoIP或者/var/lib/GeoIP(选择存在的那个)。
mv GeoLiteCity.dat <path_to_database_dir>/GeoIPCity.dat
注意,有一个单独为IPv6地址准备的数据库,想要的话你也可以装。
测试:
在使用GeoIP功能之前,先验证一下装的对不对。用下面的语句试一试。
bro -e "print lookup_location(8.8.8.8);"
如果你看到类似于“Failed to open GeoIP City database”的消息,你可以尝试重命名或者移动你的GeoIP city数据库文件(错误信息会给你Bro要找的数据库文件的完整路径)。
如果你看到类似于“Bro was not configured for GeoIP support”的消息,你可以尝试重新构建Bro并保证它连接了libGeoIP。正常情况下,如果libGeoIP正确安装了,它会在构建Bro的时候自动找到。如果这样不行,你可以尝试将路径指向libGeoIP的安装路径(比如 ./configure --with-geoip=<path>)。
使用方法
有一个内置的函数提供GeoIP的功能:
function lookup_location(a:addr): geo_location
函数lookup_location的返回值是record类型geo_location,它由包含了一个ip地址的国家(country),地区(region),城市(city),纬度(latitude),经度(longitude)等信息。这些值不一定全都有,所以在取值之前先验证是否有这个值。
例子
从Ohio州的主机来的每个ftp连接,非常容易:
event ftp_reply(c: connection, code: count, msg: string, cont_resp: bool)
{
local client = c$id$orig_h;
local loc = lookup_location(client);
if (loc?$region && loc$region == "OH" && loc$country_code == "US")
{
local city = loc?$city ? loc$city : "<unknown>";
print fmt("FTP Connection from:%s (%s,%s,%s)", client, city,
loc$region, loc$country_code);
}
}
1840

被折叠的 条评论
为什么被折叠?



