【L7アプリケーション分析を簡単に実現する方法】nDPIとは?使い方をマスターしよう!!

こんばんは!mieruka.link管理人の伊集院です。

夏休みということもあり、少し時間を取ってアプリケーション分析に関する調査と検証をしてみました。

アプリケーション分析ができる!といいながらL4止まりの製品が多い中、本ブログで何回か紹介しているntopの製品は、L7まで分析してくれます。

今回は、そのntopのL7分析ソフトウェアであるnDPIの説明とインストール方法、使い方を説明します。

また、次回のブログではnDPI拡張して独自プロトコルを分析するといった少しだけディープなネタをご紹介します。

本記事と次回の記事を参考にしていただければ、ntopがサポートしていないアプリケーション分析をご自分で実装することが可能となります。

nDPIとは?

まずは、nDPIとはなにか?を説明したいと思います。

以下は、本サイトの原文ママです。

nDPI is a ntop-maintained superset of the popular OpenDPI library. Released under the LGPL license, its goal is to extend the original library by adding new protocols that are otherwise available only on the paid version of OpenDPI. In addition to Unix platforms, we also support Windows, in order to provide you a cross-platform DPI experience. Furthermore, we have modified nDPI to be more suitable for traffic monitoring applications, by disabling specific features that slow down the DPI engine while being them un-necessary for network traffic monitoring.

https://www.ntop.org/products/deep-packet-inspection/ndpi/

要約すると、OpenDPIをntopがメンテンナンスするバージョンに書き換えたものでLGPLライセンスで提供しているよ!って感じでしょうか。

以下は、githubで参照できるnDPIのソースコードです。

https://github.com/ntop/nDPI

こちらから自環境にダウンロードして頂ければ、手軽にnDPIを試すことができます。

nDPI開発環境の構築方法

以下のステップに従って頂ければ簡単に実行・開発環境を構築することができます。

  • githubから、nDPI-dev.zipをダウンロード。Linuxマシンに保存・解凍
  • nDPI-devディレクトリ内で、以下を実行する。
    • ./autogen.sh
    • ./configure –enable-debug-messages CFLAG=”-g”
    • make
  • コンパイルが完了したら、以下のコマンドで実行ができます。
    • example/nDpiReader v 2 -V 4 -i hogemoge.pcap

次の出力結果は、Netflowパケットx1個を分析したものです。

$./ndpiReader -v 2 -V 4 -i ../../netflow-fritz.pcap

-----------------------------------------------------------
* NOTE: This is demo app to show *some* nDPI features.
* In this demo we have implemented only some basic features
* just to show you what you can do with the library. Feel
* free to extend it and send us the patches for inclusion
------------------------------------------------------------

Using nDPI (4.1.0) [1 thread(s)]
Using libgcrypt version 1.8.5
Reading packets from pcap file ../../netflow-fritz.pcap...
ndpi_main.c:ndpi_set_bitmask_protocol_detection:3511 - [Unknown]: [NDPI] Internal error: protocol Mining/42 has been already registered
ndpi_main.c:ndpi_set_protocol_detection_bitmask2:4046 - [Unknown]: callback_buffer_size is 169
Running thread 0...
ndpi_main.c:ndpi_detection_process_packet:5409 - [Unknown]: START packet processing
ndpi_main.c:ndpi_init_packet_header:4367 - [Unknown]: ipv4 header
ndpi_main.c:ndpi_detection_get_l4_internal:4211 - [Unknown]: ipv4 header
protocols/netflow.c:ndpi_search_netflow:108 - [NetFlow]: search netflow
pck-payload[0]: 0
pck-payload: 10
version: 10
length: 180
when value: 1498072477
protocols/netflow.c:ndpi_search_netflow:185 - [NetFlow]: found netflow

nDPI Memory statistics:
        nDPI Memory (once):      221.86 KB
        Flow Memory (per flow):  2.48 KB
        Actual Memory:           1.84 MB
        Peak Memory:             1.84 MB
        Setup Time:              7 msec
        Packet Processing Time:  0 msec

Traffic statistics:
        Ethernet bytes:        246           (includes ethernet CRC/IFC/trailer)
        Discarded bytes:       0
        IP packets:            1             of 1 packets total
        IP bytes:              222           (avg pkt size 222 bytes)
        Unique flows:          1
        TCP Packets:           0
        UDP Packets:           1
        VLAN Packets:          0
        MPLS Packets:          0
        PPPoE Packets:         0
        Fragmented Packets:    0
        Max Packet size:       188
        Packet Len < 64:       0
        Packet Len 64-128:     0
        Packet Len 128-256:    1
        Packet Len 256-1024:   0
        Packet Len 1024-1500:  0
        Packet Len > 1500:     0
        nDPI throughput:       4.24 K pps / 7.95 Mb/sec
        Analysis begin:        22/Jun/2017 04:18:27
        Analysis end:          22/Jun/2017 04:18:27
        Traffic throughput:    0.00 pps / 0 b/sec
        Traffic duration:      0.000 sec
        Guessed flow protos:   0
        DPI Packets (UDP):     1             (1.00 pkts/flow)


Detected protocols:
        NetFlow              packets: 1             bytes: 222           flows: 1


Protocol statistics:
        Acceptable                     222 bytes

        1       UDP 192.168.0.1:23384 -> 192.168.1.1:2055 [proto: 128/NetFlow][ClearText][cat: Network/14][1 pkts/222 bytes -> 0 pkts/0 bytes][Goodput ratio: 81/0][< 1 sec][Plen Bins: 0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

Detected protocols:のセクションで、しっかりNetFlowであることが識別できています。

L4止まりの製品ですと、UDPとだけしか表示されない場合がありますので、ネットワーク分析には非常に重宝するといったことが分かっていただけたかと思います。

次回は、nDPIを拡張して、独自プロトコルを解析する方法をご紹介します。

(Visited 651 times, 1 visits today)
The following two tabs change content below.
【好きなもの】 インフラ技術が好き。古いものが好き。 【生きてきたフィールド】 システム運用、ソフトウェア開発、ミドルウェア検証、OSSサポート、プリセールスエンジニア、プロジェクトマネジメント 【このサイトでの役割】 サイト管理者。