我正在尝试读取一个包含IP地址列表的文件和另一个包含域的文件,作为https://docs.zeek.org/en/stable/frameworks/input.html中定义的输入框架的概念证明
我已经准备好了下面的bro脚本:
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);
}但是,当我运行bro时,我得到以下错误:
error: Input stream ips: Table type does not match index type. Need type 'string':string, got 'addr':addr
Segmentation fault (core dumped)发布于 2019-05-23 18:10:31
您不能将string类型分配给addr类型。为此,您必须使用实用程序函数to_addr()。当然,明智的做法是首先验证该字符串是否包含有效的addr。例如:
if(is_valid_ip(inputString){
inputAddr = to_addr(inputString)
} else { print "addr expected, got a string"; }https://stackoverflow.com/questions/56239349
复制相似问题