elasticsearch Logstash Elasticsearch筛选器IPv6解析异常
我有一个威胁intel feed将黑名单IP地址索引到我们的Elasticsearch群集,我想根据该索引检查日志源(Suricata、Firewall、Packetbeat等),以查看是否找到匹配的IP地址。这对于IPv4地址非常有效,但是收回IPv6地址会导致解析失败 以下是我的日志存储配置中Elasticsearch过滤器的相关部分:elasticsearch Logstash Elasticsearch筛选器IPv6解析异常,elasticsearch,filter,logstash,ipv6,elasticsearch,Filter,Logstash,Ipv6,我有一个威胁intel feed将黑名单IP地址索引到我们的Elasticsearch群集,我想根据该索引检查日志源(Suricata、Firewall、Packetbeat等),以查看是否找到匹配的IP地址。这对于IPv4地址非常有效,但是收回IPv6地址会导致解析失败 以下是我的日志存储配置中Elasticsearch过滤器的相关部分: filter { if [source][ip] { elasticsearch { hosts => [ "
filter {
if [source][ip] {
elasticsearch {
hosts => [
"ESDATA01.Contoso.com:9200",
"ESDATA02.Contoso.com:9200",
"ESDATA03.Contoso.com:9200",
"ESDATA04.Contoso.com:9200",
"ESDATA05.Contoso.com:9200"
]
index => "threat_feed"
query => "source.ip:%{[source][ip]}"
add_field => {"[source][is_malicious]" => "true"}
add_tag => ["malicious_ip"]
}
}
}
每当查询返回IPv6地址时,我都会在Logstash中得到这个[过长]错误:
Failed to query elasticsearch for previous event {:index=>"threat_feed", :error=>"[400] {\"error\":{\"root_cause\":[{\"type\":\"parse_exception\",\"reason\":\"parse_exception: Encountered \\\" \\\":\\\" \\\": \\\"\\\" at line 1, column 14.\\nWas expecting one of:\\n <EOF> \\n <AND> ...\\n <OR> ...\\n <NOT> ...\\n \\\"+\\\" ...\\n \\\"-\\\" ...\\n <BAREOPER> ...\\n \\\"(\\\" ...\\n \\\"*\\\" ...\\n \\\"^\\\" ...\\n <QUOTED> ...\\n <TERM> ...\\n <FUZZY_SLOP> ...\\n <PREFIXTERM> ...\\n <WILDTERM> ...\\n <REGEXPTERM> ...\\n \\\"[\\\" ...\\n \\\"{\\\" ...\\n <NUMBER> ...\\n \"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"threat_feed-2019.08.15-000001\",\"node\":\"sH3qEWb3SJCP6oAoyjLTuA\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"Failed to parse query [source.ip:fe80::a4ab:6b47:c0c2:3594]\",\"index_uuid\":\"IFNFpVtWTcq8kl7iuUqXgA\",\"index\":\"threat_feed-2019.08.15-000001\",\"caused_by\":{\"type\":\"parse_exception\",\"reason\":\"parse_exception: Cannot parse 'source.ip:fe80::a4ab:6b47:c0c2:3594': Encountered \\\" \\\":\\\" \\\": \\\"\\\" at line 1, column 14.\\nWas expecting one of:\\n <EOF> \\n <AND> ...\\n <OR> ...\\n <NOT> ...\\n \\\"+\\\" ...\\n \\\"-\\\" ...\\n <BAREOPER> ...\\n \\\"(\\\" ...\\n \\\"*\\\" ...\\n \\\"^\\\" ...\\n <QUOTED> ...\\n <TERM> ...\\n <FUZZY_SLOP> ...\\n <PREFIXTERM> ...\\n <WILDTERM> ...\\n <REGEXPTERM> ...\\n \\\"[\\\" ...\\n \\\"{\\\" ...\\n <NUMBER> ...\\n \",\"caused_by\":{\"type\":\"parse_exception\",\"reason\":\"parse_exception: Encountered \\\" \\\":\\\" \\\": \\\"\\\" at line 1, column 14.\\nWas expecting one of:\\n <EOF> \\n <AND> ...\\n <OR> ...\\n <NOT> ...\\n \\\"+\\\" ...\\n \\\"-\\\" ...\\n <BAREOPER> ...\\n \\\"(\\\" ...\\n \\\"*\\\" ...\\n \\\"^\\\" ...\\n <QUOTED> ...\\n <TERM> ...\\n <FUZZY_SLOP> ...\\n <PREFIXTERM> ...\\n <WILDTERM> ...\\n <REGEXPTERM> ...\\n \\\"[\\\" ...\\n \\\"{\\\" ...\\n <NUMBER> ...\\n \"}}}}],\"caused_by\":{\"type\":\"parse_exception\",\"reason\":\"parse_exception: Encountered \\\" \\\":\\\" \\\": \\\"\\\" at line 1, column 14.\\nWas expecting one of:\\n <EOF> \\n <AND> ...\\n <OR> ...\\n <NOT> ...\\n \\\"+\\\" ...\\n \\\"-\\\" ...\\n <BAREOPER> ...\\n \\\"(\\\" ...\\n \\\"*\\\" ...\\n \\\"^\\\" ...\\n <QUOTED> ...\\n <TERM> ...\\n <FUZZY_SLOP> ...\\n <PREFIXTERM> ...\\n <WILDTERM> ...\\n <REGEXPTERM> ...\\n \\\"[\\\" ...\\n \\\"{\\\" ...\\n <NUMBER> ...\\n \"}},\"status\":400}"}
也许这是因为冒号
:
需要转义?如果是这样的话,我如何在返回数据之前转义字符呢?我后退了一步,现在我认为在查询之前需要“处理”IPv6地址的正是事件数据。我现在不在我的系统进行测试,但我将稍后进行测试。我在考虑将[source][ip]字段复制到一个临时字段,使用gsub
转义任何:
,并以这种方式进行查询。我明天有机会测试后会发回。query=>'source.ip:“%{[source][ip]}”做得更好吗?谢谢@Badger。这看起来也值得一试(而且比我的想法简单)。我要试一试!此外,IPv6链路本地地址(如您提供的)必须包含区域ID,因为每个链路使用相同的网络。@RonMaupin我实际上已经在使用CIDR筛选器标记事件,因此我没有查找私有、环回或多播地址,因此这不会成为问题。该地址只是我面前的一个事件的复制/粘贴。我后退了一步,现在我认为在查询之前需要对IPv6地址进行“处理”的正是事件数据。我现在不在我的系统进行测试,但我将稍后进行测试。我在考虑将[source][ip]字段复制到一个临时字段,使用gsub
转义任何:
,并以这种方式进行查询。我明天有机会测试后会发回。query=>'source.ip:“%{[source][ip]}”做得更好吗?谢谢@Badger。这看起来也值得一试(而且比我的想法简单)。我要试一试!此外,IPv6链路本地地址(如您提供的)必须包含区域ID,因为每个链路使用相同的网络。@RonMaupin我实际上已经在使用CIDR筛选器标记事件,因此我没有查找私有、环回或多播地址,因此这不会成为问题。那个地址只是我面前一个活动的复制/粘贴。
"Failed to parse query [source.ip:fe80::a4ab:6b47:c0c2:3594]"
Cannot parse 'source.ip:fe80::a4ab:6b47:c0c2:3594'