我正在尝试读取一个包含IP地址列表和另一个包含域的文件,以作为https://docs.zeek.org/en/stable/frameworks/input.html
中定义的输入框架的概念证明我准备了以下兄弟脚本:
reading.bro:
type Idx: record {
ip: addr;
};
type Idx: record {
domain: string;
};
global ips: table[addr] of Idx = table();
global domains: table[string] of Idx = table();
event bro_init() {
Input::add_table([$source="read_ip_bro", $name="ips",
$idx=Idx, $destination=ips, $mode=Input::REREAD]);
Input::add_table([$source="read_domain_bro", $name="domains",
$idx=Idx, $destination=domains, $mode=Input::REREAD]);
Input::remove("ips");
Input::remove("domains");
}
还有bad_ip.bro脚本,该脚本检查IP是否在黑名单中,并加载上一个IP:
bad_ip.bro
@load reading.bro
module HTTP;
event http_reply(c: connection, version: string, code: count, reason: string)
{
if ( c$id$orig_h in ips )
print fmt("A malicious IP is connecting: %s", c$id$orig_h);
}
但是,当我运行兄弟时,出现错误:
error: Input stream ips: Table type does not match index type. Need type 'string':string, got 'addr':addr
Segmentation fault (core dumped)
答案 0 :(得分:2)
您不能将string
类型分配给addr
类型。为此,必须使用实用程序功能to_addr()
。当然,首先验证该字符串包含有效的addr
是明智的。例如:
if(is_valid_ip(inputString){
inputAddr = to_addr(inputString)
} else { print "addr expected, got a string"; }