Skip to content

PRATHAM777P/Deep-Packet-Inspection-DPI-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”Ž Deep Packet Inspection (DPI) Engine

A Deep Packet Inspection (DPI) engine written in C++ that analyzes network traffic from PCAP files, identifies applications using packet metadata and TLS SNI inspection, and applies filtering rules to block specific applications, domains, or IP addresses.

The system parses multiple network protocol layers, tracks connections using the Five-Tuple, and processes packets using a multi-threaded architecture to improve performance and scalability.


๐Ÿ“Œ Project Overview

This project demonstrates how modern network monitoring and security systems analyze traffic beyond traditional packet filtering.

Captured network traffic is provided as a PCAP file, which is processed by the DPI engine. The engine analyzes each packet, applies filtering rules, and writes allowed traffic into a new filtered PCAP output file.

โš™๏ธ Workflow

Input PCAP โ†’ DPI Engine โ†’ Filtered PCAP Output

๐Ÿ”„ Core Processing Steps

  • ๐Ÿ“ฆ Packet parsing
  • ๐Ÿ”— Flow identification
  • ๐Ÿง  Application detection
  • ๐Ÿšซ Rule-based filtering
  • ๐Ÿ“Š Traffic statistics generation

๐Ÿš€ Key Features

๐Ÿ“ฆ Packet Parsing

The engine parses multiple network protocol layers:

  • Ethernet
  • IPv4
  • TCP / UDP
  • Application payload

This enables extraction of critical network metadata for deeper inspection.


๐Ÿ”— Flow Identification

Each connection is tracked using the Five-Tuple:

  • ๐ŸŒ Source IP address
  • ๐ŸŒ Destination IP address
  • ๐Ÿ”Œ Source port
  • ๐Ÿ”Œ Destination port
  • ๐Ÿ“ก Protocol

Packets sharing the same Five-Tuple belong to the same network flow, allowing stateful traffic analysis.


๐Ÿ” Deep Packet Inspection

The engine inspects packet payloads to detect applications.

For HTTPS traffic, it extracts the Server Name Indication (SNI) from the TLS handshake.

SNI reveals the domain name being accessed before encryption begins.

Example

SNI: www.youtube.com
Detected Application: YouTube

๐Ÿšซ Traffic Blocking

The system supports rule-based traffic filtering, allowing blocking by:

  • ๐Ÿงพ IP address
  • ๐Ÿ“ฑ Application type
  • ๐ŸŒ Domain name

Packets matching blocking rules are dropped and not written to the output file.


๐Ÿ— Architecture

The project includes two implementations.


๐Ÿงฉ Single-Threaded Version

A simple implementation where packets are processed sequentially.

Useful for:

  • Learning packet inspection
  • Debugging packet processing
PCAP Reader โ†’ Packet Parser โ†’ Classifier โ†’ Rule Engine โ†’ Output

โšก Multi-Threaded Version

A high-performance implementation that processes packets in parallel.

Threads Used

  • ๐Ÿ“ฅ Reader thread โ†’ Reads packets from PCAP
  • โš–๏ธ Load balancer threads โ†’ Distribute packets
  • โš™๏ธ Worker threads (Fast Path) โ†’ Process packets
  • ๐Ÿ’พ Output writer thread โ†’ Writes filtered packets
Reader โ†’ Load Balancer โ†’ Worker Threads โ†’ Output Writer

This architecture allows the system to scale with available CPU cores.


๐Ÿ“‚ Project Structure

deep-packet-inspector
โ”‚
โ”œโ”€โ”€ include/
โ”‚   Header files for packet parsing, flow tracking, and DPI logic
โ”‚
โ”œโ”€โ”€ src/
โ”‚   Core implementation of the DPI engine
โ”‚
โ”œโ”€โ”€ generate_test_pcap.py
โ”‚   Script used to generate sample network traffic
โ”‚
โ”œโ”€โ”€ test_dpi.pcap
โ”‚   Example PCAP file used for testing
โ”‚
โ”œโ”€โ”€ CMakeLists.txt
โ”‚   Build configuration file
โ”‚
โ”œโ”€โ”€ WINDOWS_SETUP.md
โ”‚   Windows build instructions
โ”‚
โ””โ”€โ”€ README.md

๐Ÿ”„ Packet Processing Pipeline

Packets pass through several stages during analysis.

1๏ธโƒฃ Packet Reading

Packets are sequentially read from the PCAP file.

2๏ธโƒฃ Protocol Parsing

Network headers are parsed to extract:

  • MAC addresses
  • IP addresses
  • Ports
  • Protocol type

3๏ธโƒฃ Flow Identification

The system generates a Five-Tuple to track each connection.

4๏ธโƒฃ Payload Inspection

For HTTPS packets, the TLS handshake is inspected to extract the SNI hostname.

5๏ธโƒฃ Rule Evaluation

Blocking rules are checked against the connection.

6๏ธโƒฃ Forward or Drop

  • โœ… Allowed packets โ†’ written to output PCAP
  • โŒ Blocked packets โ†’ dropped

๐Ÿ›  Building the Project

๐Ÿ“‹ Requirements

  • C++17 compatible compiler
  • Linux / macOS / Windows (MinGW)
  • Python (optional, for generating test PCAP)

๐Ÿ”ง Compile

Example build command:

g++ -std=c++17 -O2 -I include \
src/*.cpp \
-o dpi_engine

โ–ถ๏ธ Running the Engine

Basic Usage

./dpi_engine input.pcap output.pcap

Example with Blocking Rules

./dpi_engine input.pcap output.pcap \
--block-app YouTube \
--block-ip 192.168.1.50 \
--block-domain facebook

๐Ÿ“Š Example Output

Total Packets: 77
Forwarded: 69
Dropped: 8

Detected Applications:
HTTPS
YouTube
Facebook
DNS

The output displays traffic statistics and application detection results.


๐Ÿ”ฎ Future Improvements

Possible enhancements include:

  • โž• Adding more application signatures
  • ๐Ÿ“ก Supporting live network packet capture
  • โฑ Implementing bandwidth throttling
  • ๐ŸŒ Creating a web dashboard for monitoring
  • โšก Adding support for QUIC / HTTP3 traffic

๐ŸŽ“ Educational Purpose

This project demonstrates important network security and packet analysis concepts:

  • ๐Ÿ“ฆ Network packet structure
  • ๐Ÿ”— Flow tracking using Five-Tuple
  • ๐Ÿ”Ž Deep packet inspection techniques
  • ๐Ÿ” TLS handshake analysis
  • โšก Multi-threaded packet processing

It serves as a practical learning project for:

Network Security โ€ข Packet Analysis โ€ข Traffic Monitoring Systems

About

A Deep Packet Inspection (DPI) engine written in C++ that analyzes PCAP network traffic, identifies applications using packet metadata and SNI inspection, and applies filtering rules to block specific apps, domains, or IP addresses using a multi-threaded packet processing architecture.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors