5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CIDR表記でIPアドレスを検索する方法

Last updated at Posted at 2019-01-14

はじめに

Kibanaにおいて、IPアドレスをCIDR表記を用いて検索する方法を書きます。

利用環境

product version
Kibana 6.5.4
Elasticsearch 6.5.4
Winlogbeat 6.5.4
Sysmon 8.04

前提

Sysmonによって出力されたSysmon EventID 3のNetwork connectionログを利用します。
Windowsイベントログとして出力されたSysmonログをWinlogbeatでElasticsearchに取り込み、KibanaでCIDR表記の検索をします。

Kibanaとは

Elasticsearchを開発しオープンソースとして提供しているElastic社のBIツールになります。
Elasticsearchに格納されているデータをWebブラウザで検索したり、グラフで可視化したりするためのツールです。

【参考URL】
Kibanaとは

datatypeをipに設定する

Elasticsearchは事前にスキーマ定義が必要ないスキーマレスアーキテクチャになります。
スキーマを定義せずにLogstashやBeatsでログを取り込むと多くのフィールドは文字列データ(textやkeyword)として取り込まれます。

今回検索に利用するフィールドはevent_data.DestinationIpとなります。
値としてIPv4やIPv6が入りますが、WinlogbeatのIndex Templateではdatatypestring(keyword)として取り込まれCIDR表記で検索できません。
image.png

event_data.DestinationIpのdatatype(2018/12/29分)
GET /winlogbeat-6.5.4-2018.12.29/_mapping/doc/field/event_data.DestinationIp

{
  "winlogbeat-6.5.4-2018.12.29" : {
    "mappings" : {
      "doc" : {
        "event_data.DestinationIp" : {
          "full_name" : "event_data.DestinationIp",
          "mapping" : {
            "DestinationIp" : {
              "type" : "keyword"      ここの値
            }
          }
        }
      }
    }
  }
}

event_data.DestinationIpフィールドのIPアドレス件数を集計した表グラフにおいて
"172.217.0.0/16"と検索してもNo results foundとなってしまいます。
image.png

一度取り込んだデータのdatatypeは変更出来ないようです。
Index Templateを更新して新たに取り込むデータにおいて、datatypeipとなるようにします。

IndexTemplate
PUT _template/winlogbeat-6.5.4
{
  "index_patterns" : [
    "winlogbeat-6.5.4-*"
  ],
  "settings" : {
    "index" : {
      "mapping" : {
        "total_fields" : {
          "limit" : "10000"
        }
      },
      "refresh_interval" : "5s",
      "number_of_routing_shards" : "30",
      "number_of_shards" : "1"
    }
  },
  "mappings" : {
    "doc" : {
      "_meta" : {
        "version" : "6.5.4"
      },
      "date_detection" : false,

   (中略・・・)

        "event_data" : {
          "type" : "object",
          "properties" : {            追記(179行目)
            "DestinationIp" : {       追記(180行目)
              "type" : "ip"           追記(181行目) 
            }
          }
        },

CIDR表記で検索する

2019年01月13日(月)のログを新しいIndex Templateを利用して取り込みます。
新たに生成されたIndexであるwinlogbeat-6.5.4-2019.01.13において、datatypeipとなっていることを確認します。
image.png

event_data.DestinationIpのdatatype(2019/01/13分)
GET /winlogbeat-6.5.4-2019.01.13/_mapping/doc/field/event_data.DestinationIp
{
  "winlogbeat-6.5.4-2019.01.13" : {
    "mappings" : {
      "doc" : {
        "event_data.DestinationIp" : {
          "full_name" : "event_data.DestinationIp",
          "mapping" : {
            "DestinationIp" : {
              "type" : "ip"      ここの値
            }
          }
        }
      }
    }
  }
}

対象期間を2019/01/13に変更します。
今度は"172.217.0.0/16"と検索すると該当するIPアドレスのみが表示されるようになりました。
image.png

検索バー下にあるAdd a filterではOR条件の検索はできませんが、"172.217.0.0/16" OR "13.107.0.0/16"と検索すれば複数のセグメントを対象にログ検索することも可能です。
意外と便利ですね。
image.png

まとめ

いかがでしたでしょうか。
アクセスログやセキュリティログの分析において、送信元や宛先のIPアドレスをレンジで検索したいことは多分にあると思います。
ネットワークエンジニアであれば、CIDR表記でセグメント単位で絞り込むケースもあると思いますので、是非活用してみてはいかがでしょうか。

不明な点、誤植などありましたら、コメントをお願いします!!

参考

Field datatypes
IP datatype
Index Template

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?