nDPI基本介绍

nDPI是什么

先来说下什么是DPI,DPI(Deep Packet Inspection)是深度包检测系统,网络的流量种类现在越来越多,有些是恶意使用,比如p2p占用带宽或恶意网络应用,由于恶意应用可能使用随机端口,因此有必要对报文进行深度分析。

nDPI是从openDPI发展而来,功能上更强大,都是基于C实现的基于LGPL3.0开源的深度包分析库。

nDPI有以下特点:
1、跨平台,支持windows,linux、mac等操作系统。
2、支持流量大小监控。
3、目前支持185种协议解析。
4、能够定义端口或端口范围来匹配协议。
5、能够根据字符串匹配子子协议。
6、nDPI实现了线程安全。
7、nDPI实现了加密流量的解析。

主要功能:
1、核心库用于处理数据包抽取基本信息。
2、解析器用插件方式实现,用于解析报文检测的 协议类别。

nDPI安装

1、点击下载最新的版本,2017年8月8日版本2.1.0.

2、编译nDPI库
简单的三步:

  • ./autogen.sh
  • ./configure
  • make

3、测试

  • cd tests; ./do.sh

4、安装

  • make install
    需要具备root权限

5、例子工具使用
nDPI在example下面提供了一个ndpiReader,这个在编译程序的时候自动编译好了。

nDPI基本介绍_第1张图片
ndpiReader

协议配置文件:

协议配置文件:
#  Format:
#  :,:,.....@
#抓取特定端口或特定端口端的协议

tcp:81,tcp:8181@HTTP
udp:5061-5062@SIP
tcp:860,udp:860,tcp:3260,udp:3260@iSCSI
tcp:3000@ntop

#  Subprotocols
#  Format:
#  host:"",host:"",.....@
#通过字符串匹配方式来定义新的子协议
host:"googlesyndication.com"@Google
host:"venere.com"@Venere
host:"kataweb.it",host:"repubblica.it"@Repubblica
host:"ntop"@ntop
host:"www.baidu.com"@baidu

#  IP based Subprotocols
#  Format:
#  ip:,ip:,.....@
#通过ip的方式来定义子协议
ip:213.75.170.11@CustomProtocol

主要功能:
1)分析网卡的数据包

  ./ndpiReader -p protos.txt  -i eth0   -s 120 -w result.txt

说明:监听网卡报文120分钟,结果数据保存到result.txt中。
结果展示:

-----------------------------------------------------------
* 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 (2.1.0) [1 thread(s)]
Capturing live traffic from device eth0...
Capturing traffic up to 120 seconds
Running thread 0...

nDPI Memory statistics:
    nDPI Memory (once):      112.30 KB    
    Flow Memory (per flow):  1.97 KB      
    Actual Memory:           2.60 MB      
    Peak Memory:             2.60 MB      

Traffic statistics:
    Ethernet bytes:        860224        (includes ethernet CRC/IFC/trailer)
    Discarded bytes:       3528         
    IP packets:            1669          of 1729 packets total
    IP bytes:              820168        (avg pkt size 474 bytes)
    Unique flows:          57           
    TCP Packets:           1558         
    UDP Packets:           111          
    VLAN Packets:          0            
    MPLS Packets:          0            
    PPPoE Packets:         0            
    Fragmented Packets:    0            
    Max Packet size:       1480         
    Packet Len < 64:       832          
    Packet Len 64-128:     214          
    Packet Len 128-256:    46           
    Packet Len 256-1024:   143          
    Packet Len 1024-1500:  434          
    Packet Len > 1500:     0            
    nDPI throughput:       13.94 pps / 56.13 Kb/sec
    Analysis begin:        31/Dec/1969 16:00:00
    Analysis end:          31/Dec/1969 16:00:00
    Traffic throughput:    13.94 pps / 56.13 Kb/sec
    Traffic duration:      119.723 sec
    Guessed flow protos:   9            


Detected protocols:
    DNS                  packets: 70            bytes: 7360          flows: 22           
    HTTP                 packets: 885           bytes: 662027        flows: 14           
    NetBIOS              packets: 1             bytes: 248           flows: 1            
    SSDP                 packets: 4             bytes: 860           flows: 1            
    SSL                  packets: 317           bytes: 68648         flows: 22           
    SSH                  packets: 219           bytes: 22990         flows: 4            
    DHCPV6               packets: 6             bytes: 882           flows: 1            
    Google               packets: 33            bytes: 3645          flows: 7            
    baidu                packets: 134           bytes: 53508         flows: 6            


Protocol statistics:
    Safe                         68648 bytes
    Acceptable                  751520 bytes

flows:数据流,为一系列数据包组成。
packets:数据包。
以上有baidu协议为我新添加的子协议,添加子协议配置很简单,通过hosts提取的http协议定义为baidu这个子协议。

host:"www.baidu.com"@baidu

即只要http的host为www.baidu.com就当做为baidu协议。

结果文件:

DNS 70  7360    22
HTTP    885 662027  14
NetBIOS 1   248 1
SSDP    4   860 1
SSL 317 68648   22
SSH 219 22990   4
DHCPV6  6   882 1
Google  33  3645    7
baidu   134 53508   6

依次为协议名称、报文数、字节数、数据流数。

2)分析抓包文件
通过tcpdump进行抓包

$tcpdump -ni eth0 -s0 -w /var/tmp/capture.pcap -v
利用ndpiReader分析抓到的报文
$ ./ndpiReader -i /var/tmp/capture.pcap

你可能感兴趣的:(nDPI基本介绍)