首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于读取Ips和域列表的Bro脚本

用于读取Ips和域列表的Bro脚本
EN

Stack Overflow用户
提问于 2019-05-21 21:26:10
回答 1查看 387关注 0票数 0

我正在尝试读取一个包含IP地址列表的文件和另一个包含域的文件,作为https://docs.zeek.org/en/stable/frameworks/input.html中定义的输入框架的概念证明

我已经准备好了下面的bro脚本:

reading.bro:

代码语言:javascript
复制
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

代码语言:javascript
复制
@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时,我得到以下错误:

代码语言:javascript
复制
error: Input stream ips: Table type does not match index type. Need type 'string':string, got 'addr':addr
Segmentation fault (core dumped)
EN

回答 1

Stack Overflow用户

发布于 2019-05-23 18:10:31

您不能将string类型分配给addr类型。为此,您必须使用实用程序函数to_addr()。当然,明智的做法是首先验证该字符串是否包含有效的addr。例如:

代码语言:javascript
复制
 if(is_valid_ip(inputString){
   inputAddr = to_addr(inputString)
 } else { print "addr expected, got a string"; }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56239349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档