Skip to content

Repository files navigation

πŸ›‘οΈ PCAP Storyteller

The Cyber Attack Storyteller

Transform PCAP network traffic into an interactive, visual storyboard of cyber attacks. Analyze network events, visualize attack patterns, detect threats, and generate professional reportsβ€”all with a modular, production-ready architecture.


πŸš€ Features

Core Analysis

  • πŸ“Š Advanced PCAP Parser - Extracts TCP, UDP, DNS, HTTP, TLS, ICMP, ARP events with full protocol support
  • πŸ”— Intelligent Causal Linking - Automatically correlates DNS queries with HTTP requests and TLS handshakes
  • πŸ“ˆ Interactive Attack Graph - Dynamic visualization of network events and their relationships
  • ⏱️ Chronological Event Timeline - Time-series view of all network events with filtering capabilities

Advanced Intelligence

  • ⚠️ Threat Detection Engine - Identifies port scanning, data exfiltration, suspicious DNS patterns, and C2 activity
  • 🎯 Risk Scoring System - Assigns threat scores (0-100) to each event based on multi-factor analysis
  • 🌍 Geolocation Intelligence - Maps IP addresses to geographic locations with interactive Leaflet maps
  • πŸ“Š Analytics Dashboard - Statistical insights: top IPs, ports, protocols, traffic heatmaps, and traffic distribution

Reporting & Export

  • πŸ“„ PDF Reports - Professional multi-page reports with summaries, statistics, and detailed tables
  • πŸ“ Word Documents - DOCX format for easy editing and stakeholder sharing
  • πŸ“… Timestamp Breakdown - Clean event details with source/destination analysis
  • πŸ’Ύ JSON Export - Raw event data for further analysis and integration

οΏ½ Screenshots


οΏ½πŸ“‹ Requirements

  • Python 3.7+
  • Flask - Web framework
  • Scapy - Packet parsing and analysis
  • ReportLab - PDF generation
  • python-docx - Word document generation
  • requests - HTTP library for GeoIP lookups
  • folium - Interactive map generation
  • chart-studio - Advanced charting capabilities
  • geoip2 - GeoIP database support

All dependencies are listed in requirements.txt


⚑ Quick Start

1. Install Dependencies

cd backend
pip install -r requirements.txt

2. Run the Application

python app.py

The application will start on http://localhost:5000

3. Upload & Analyze

  • Open your browser to http://localhost:5000
  • Click "Analyze PCAP" and select your PCAP/PCAPng file
  • Wait for analysis to complete
  • Explore results using the navigation dashboard

🎯 Usage Guide

Dashboard Navigation

After analyzing a PCAP, use these tabs for different analytical views:

Button Purpose Details
πŸ“Š Report Download professional reports PDF or Word formats with summaries
πŸ“ˆ Analytics View aggregated statistics Event distribution, top IPs, ports, protocols
⚠️ Threats Threat intelligence view Detected attack patterns, risk scores, severity levels
πŸ” Search Advanced filtering IP, domain, event type, port searches
🌍 Geolocation Interactive IP mapping Global view of traffic origins and destinations
⏱️ Timeline Dedicated timeline view Chronological event progression (opens in new tab)

Keyboard Shortcuts

  • Ctrl+F or Ctrl+K - Open search in new tab
  • Ctrl+S - Download current report

πŸ“ Project Architecture

The project follows a modular, layered architecture for maintainability and scalability:

PCAP-StoryTeller/
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ templates/                # HTML templates for all views
β”‚   β”‚   β”œβ”€β”€ index.html           # Main dashboard
β”‚   β”‚   β”œβ”€β”€ analytics.html       # Analytics & statistics view
β”‚   β”‚   β”œβ”€β”€ threats.html         # Threat intelligence page
β”‚   β”‚   β”œβ”€β”€ search.html          # Search & filter interface
β”‚   β”‚   β”œβ”€β”€ geolocation.html     # Interactive map visualization
β”‚   β”‚   β”œβ”€β”€ timeline.html        # Dedicated timeline view
β”‚   β”‚   └── report.html          # Report download page
β”‚   β”‚
β”‚   └── static/                   # Frontend assets
β”‚       β”œβ”€β”€ script.js            # Main dashboard logic
β”‚       β”œβ”€β”€ timeline.js          # Timeline page logic
β”‚       β”œβ”€β”€ shared.js            # Shared utilities & helpers
β”‚       └── style.css            # Dark theme styling
β”‚
└── backend/                      # Flask API & Core Analysis Engine
    β”‚
    β”œβ”€β”€ app.py                   # Flask application entry point
    β”œβ”€β”€ config.py                # Configuration settings
    β”œβ”€β”€ routes.py                # Route definitions & handlers
    β”œβ”€β”€ logger.py                # Logging configuration
    β”‚
    β”œβ”€β”€ parsers/                 # Protocol-specific packet parsers
    β”‚   β”œβ”€β”€ network_parser.py    # TCP/UDP connection parsing
    β”‚   β”œβ”€β”€ dns_parser.py        # DNS query/response parsing
    β”‚   β”œβ”€β”€ http_parser.py       # HTTP request/response parsing
    β”‚   β”œβ”€β”€ tls_parser.py        # TLS/SSL handshake parsing
    β”‚   └── encoder.py           # Custom JSON encoding
    β”‚
    β”œβ”€β”€ services/                # Business logic & analysis services
    β”‚   β”œβ”€β”€ threat_service.py    # Threat detection & scoring
    β”‚   β”œβ”€β”€ analytics_service.py # Statistical analysis & aggregation
    β”‚   β”œβ”€β”€ search_service.py    # Search & filtering capabilities
    β”‚   β”œβ”€β”€ geolocation_service.py # GeoIP lookups & mapping
    β”‚   β”œβ”€β”€ folium_map_service.py # Interactive map generation
    β”‚   └── validation_service.py # Input validation & sanitization
    β”‚
    β”œβ”€β”€ repositories/            # Data access layer
    β”‚   β”œβ”€β”€ data_repository.py   # Event data persistence
    β”‚   └── models/              # Data models & schemas
    β”‚
    β”œβ”€β”€ api_handlers.py          # API endpoint handler functions
    β”œβ”€β”€ file_handler.py          # PCAP file upload & validation
    β”œβ”€β”€ pcap_parser.py           # Main PCAP parsing orchestrator
    β”œβ”€β”€ threat_analyzer.py       # Threat analysis engine
    β”œβ”€β”€ report_generator.py      # PDF/DOCX report generation
    β”œβ”€β”€ utils.py                 # Utility functions
    β”œβ”€β”€ requirements.txt         # Python dependencies
    β”‚
    β”œβ”€β”€ uploads/                 # Temporary PCAP upload directory
    β”œβ”€β”€ models/                  # Data models
    └── __pycache__/             # Python cache directory

Architecture Highlights

Modular Design: Each parser and service handles a specific responsibility

  • Parsers: Extract protocol-specific information from packets
  • Services: Apply business logic (threat detection, analytics, search)
  • Repositories: Manage data access and persistence
  • API Handlers: Bridge between routes and services

Separation of Concerns: Frontend and backend are cleanly separated

  • Frontend: Vanilla JavaScript with interactive visualizations
  • Backend: Flask API with Python-based analysis engines

πŸ”§ API Endpoints

Template Routes (HTML Views)

GET  /                    # Main dashboard
GET  /timeline            # Dedicated timeline view
GET  /report              # Report generation page
GET  /analytics           # Analytics dashboard
GET  /threats             # Threat intelligence page
GET  /search              # Advanced search interface
GET  /geolocation         # Geolocation mapping page

PCAP Upload & Processing

POST /upload              # Upload and analyze PCAP file
GET  /events.json         # Retrieve parsed events as JSON

Analytics & Intelligence APIs

GET  /api/analytics       # Statistical data (events, distribution, top IPs)
GET  /api/threats         # Threat scores and detected patterns
GET  /api/search          # Search events (query: q, field: ['all'|'ip'|'domain'|'type'])
GET  /api/geoips          # GeoIP data for all identified IPs
GET  /api/geoip/<ip>      # GeoIP data for specific IP
GET  /api/geomap          # Summarized geolocation data

Report Generation

GET  /report/pdf          # Download PDF report
GET  /report/docx         # Download Word document report

πŸ“Š Supported Protocols & Event Types

Packet Protocol Support

Protocol Support Details
TCP βœ… Full Connection establishment, flags, ports
UDP βœ… Full Port information, datagram analysis
DNS βœ… Full Queries, responses, domain resolution
HTTP βœ… Full Methods, URIs, headers, user agents
HTTPS/TLS βœ… Full SNI, certificate chains, handshakes
ICMP βœ… Full Ping, unreachables, type/code analysis
ARP βœ… Full Requests, replies, MAC/IP mappings

File Format Support

Format Status Notes
.pcap βœ… Supported Standard packet capture format
.pcapng βœ… Supported PCAP Next Generation format
.cap βœ… Supported Alternative capture format

All formats are automatically detected and parsed.


🎨 Threat Detection & Risk Scoring

Detected Threat Patterns

Pattern Severity Indicators
πŸ”΄ Port Scanning CRITICAL Multiple unique ports from single source
πŸ”΄ Data Exfiltration CRITICAL Unusual HTTP traffic volumes, large payloads
🟑 Suspicious DNS HIGH Domains containing "malware", "c2", "exploit"
🟑 C2 Communication HIGH Suspicious TLS SNI or dynamic domains
🟑 External Connection MEDIUM Non-private IPs initiating connections
🟒 Suspicious User-Agent LOW Missing or obfuscated user agents

Risk Scoring Algorithm

Events are scored 0-100 based on multiple factors:

Scoring Factors:

  • Port Suspiciousness: Raw ports (0-10 points), privileged ports (15 points), scan ports (10 points)
  • Protocol Analysis: POST/PUT methods (15 points), missing user-agent (10 points)
  • Domain Keywords: Malware indicators (40 points), length anomalies (15 points)
  • IP Reputation: External IPs (10 points), geolocation analysis
  • Payload Indicators: Suspicious patterns, encoding signatures

Risk Levels:

  • πŸ”΄ CRITICAL: Score β‰₯ 70
  • 🟠 HIGH: Score β‰₯ 50
  • 🟑 MEDIUM: Score β‰₯ 30
  • 🟒 LOW: Score < 30

πŸ’‘ Analysis Examples

Example 1: Analyze a Malware Attack

# 1. Start the server
python backend/app.py

# 2. Upload a suspicious PCAP file via the web interface
# 3. System automatically:
#    βœ“ Parses all packets into events
#    βœ“ Links related events (DNS β†’ HTTP β†’ TLS)
#    βœ“ Calculates risk scores for each event
#    βœ“ Identifies attack patterns
#    βœ“ Geolocates involved IPs

# 4. View Results:
# - Attack Graph: Visual relationship between network events
# - Timeline: Chronological progression of the attack
# - Threats: Risk scores and patterns identified
# - Analytics: Event distribution, top IPs, suspicious protocols
# - Reports: Download professional PDF/Word reports

Example 2: Hunt Suspicious IPs

# In the Search tab:
1. Enter IP address in search field
2. Filter by "Source IP" or "Destination IP"
3. View all related events and their risk scores
4. Check geolocation to identify origin
5. Review timeline to understand activity pattern

πŸ”’ Security & Privacy

  • πŸ” Local Processing: All analysis runs locallyβ€”no data sent externally (except GeoIP lookups)
  • βœ‹ Automatic Cleanup: PCAP files are automatically deleted after processing
  • πŸ“‹ Payload Filtering: Generated reports contain no raw payloads by default
  • 🌐 GeoIP API: Uses free public API (ipapi.co) for location lookups
  • πŸ”’ No Logging: Sensitive network data is not logged to disk

βš™οΈ Performance Characteristics

PCAP Size Event Count Processing Time
Small < 100 Instant
Medium 100-1000 1-5 seconds
Large 1000-5000 5-30 seconds
Very Large > 5000 30+ seconds

Optimization Tips:

  • Filter PCAP by time range before analysis
  • Extract specific protocols using tcpdump before processing
  • Enable multithreading for concurrent request handling (default enabled)
  • Use smaller PCAPs for faster feedback during investigation

πŸ› οΈ Troubleshooting

Issue: "Scapy not installed"

Solution: pip install scapy

Issue: "Module not found" or "Import error"

Solution: 
1. Ensure you're using the correct Python environment
2. Run: pip install -r requirements.txt
3. In VS Code, configure Python interpreter to use your venv

Issue: GeoIP lookups not working

Solution:
- Ensure you have an active internet connection
- Check firewall/proxy settings
- Verify ipapi.co is accessible from your network

Issue: PCAP file upload fails

Solution:
- Confirm file is valid PCAP/PCAPng format
- Check file size (default max: 1GB)
- Verify file permissions
- Try with a smaller test PCAP first

Issue: Large PCAP causes 500 error or timeout

Solution:
1. Process in smaller time windows
2. Filter protocols before analysis: tcpdump -r big.pcap -w filtered.pcap "tcp.port == 80"
3. Split PCAP with editcap: editcap -c 10000 big.pcap chunk.pcap
4. Enable verbose logging: Check the logs/ directory

Issue: Web interface not loading

Solution:
- Clear browser cache (Ctrl+Shift+Delete)
- Check if Flask server is running on port 5000
- Try accessing http://127.0.0.1:5000 instead of localhost
- Check browser console for JavaScript errors

πŸ“ˆ Roadmap

Planned Features

  • ✨ Live Packet Capture - Real-time network monitoring mode
  • 🦠 YARA Rule Integration - Malware detection using signature rules
  • πŸ€– Machine Learning - Anomaly detection and threat prediction
  • πŸ“Š Multi-File Comparison - Compare PCAPs for attack pattern clustering
  • πŸ“ˆ Baseline Detection - Network baseline anomaly detection
  • πŸ”„ MISP/STIX Export - Threat intelligence framework integration
  • πŸ’Ύ Database Backend - SQLite/PostgreSQL storage for large datasets
  • πŸ‘₯ Collaborative Analysis - Multi-user analysis sessions
  • πŸ“± Mobile Interface - Responsive design for tablets/mobile devices
  • πŸ”Œ Plugin System - User-defined custom parsers and services

πŸ“š Technology Stack

Frontend

  • HTML5 - Semantic markup
  • CSS3 - Dark theme with responsive design
  • Vanilla JavaScript - No frameworks required
  • vis.js - Network graph visualization
  • Chart.js - Statistical charts and graphs
  • Leaflet - Interactive mapping

Backend

  • Flask - Lightweight Python web framework
  • Scapy - Packet manipulation and analysis
  • ReportLab - PDF generation
  • python-docx - Word document creation
  • Folium - Interactive map generation
  • geoip2 - Geolocation lookups

Architecture

  • Modular Parsers - Protocol-specific packet parsing
  • Service Layer - Business logic separation
  • Repository Pattern - Data access abstraction
  • REST API - JSON-based communication

πŸ™ Acknowledgments

Built with πŸ”§ using these amazing open-source projects:


πŸ‘€ Connect with Author

Kaif Tarasgar

Β Β  Β Β  Β Β  Β Β 


Made with ❀️ by Kaif Tarasgar

About

πŸ›‘οΈ Transform raw PCAP files into interactive cyber attack storyboards. Features threat detection, attack graphs, geolocation maps, and automated forensic reports.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages