# jeanrafaellourenco/pcap-forensics-toolkit architecture

> Architecture diagram of the GitHub repository jeanrafaellourenco/pcap-forensics-toolkit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jeanrafaellourenco/pcap-forensics-toolkit
- Repository: https://github.com/jeanrafaellourenco/pcap-forensics-toolkit

## Overview

##### Project type and purpose
- This is an open-source, command-line PCAP forensics toolkit implemented in Python.
- Its goal is to parse `.pcap` files (and hex dumps), detect suspicious activity (scans, C2, exfiltration, credential leaks, etc.), reconstruct files transferred over TCP, and generate reports in Markdown/PDF.

##### File structure
- All scripts live at the top level (no deep folder hierarchy), each acting as a CLI entry point:
- analisador.py / analisador_plus.py: hex parser + HTTP header extraction
- leitor_pcap.py: SCAPY-based packet reader/exporter
- extrator_arquivos_pcap.py: TCP reassembly + file extraction
- auditoria_forense_pcap.py / auditoria_forense_pcap_completo.py: forensic analysis + report generation
- md_para_html.py / md_para_pdf.py: Markdown → HTML/PDF conversion
- No dedicated `src` folder—implies a modular internal structure within each script (parsers, detectors, reporters).

##### Extract additional insights from the README
- Dependencies: Python ≥3.6, Scapy.
- Key features: advanced forensic detection, file reconstruction, hex decoding, report generation.
- Output: Markdown forensic reports and extracted files on disk.

a. Main components
1. CLI Layer
- Individual scripts (each script’s `main()` function)
2. Core Library Modules (grouped logically, not physically foldered)
- PCAP Loader (Scapy wrapper)
- Hex Interpreter
- TCP Session Reassembler
- File Signature Detector (magic-byte lookup)
- Packet/HTTP Analyzer (flags, headers, user-agent, referer)
- Forensic Detection Engine (SYN scans, C2 patterns, exfiltration, creds leak)
- Report Generator (Markdown builder)
- Converter (Markdown → HTML/PDF)
3. Storage & Output
- Extracted files directory (`./arquivos_extraidos/`)
- Report files (`.md`, `.html`, `.pdf`)
4. External Libraries
- Scapy
- Python stdlib (argparse, os, io)
b. Relationships and interactions
- CLI scripts invoke the PCAP Loader or Hex Interpreter.
- Loaded data flows into the Packet/HTTP Analyzer and/or TCP Reassembler.
- TCP Reassembler hands off reconstructed streams to the File Signature Detector.
- Packet/HTTP Analyzer and Detection Engine cooperate to produce forensic indicators.
- Detection Engine outputs structured findings to the Report Generator.
- Report Generator writes `.md` files.
- md_para_html / md_para_pdf take Markdown → produce HTML/PDF.
- Extractor script also writes binary files to the file system.
c. Architectural patterns & design principles
- Modular CLI façade over reusable core modules.
- Single-responsibility: each component (loader, analyzer, detector, reporter) has a clear role.
- Pipeline pattern: data flows through a sequence of processors.
- No persistent DB; all state is transient or written to files.
d. Key technologies & libraries
- Python 3.6+
- Scapy for packet parsing
- Magic-byte signatures for file extraction
- Markdown for report templating

##### Detailed capture of architectural elements
- Break out submodules (e.g., separate “HTTP header parser” from “packet flag decoder”).
- Parallel branches (e.g., one branch for forensic detection, another for file extraction).
- Transformation steps (Markdown → PDF/HTML).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Layer
    subgraph "CLI Layer"
        direction TB
        CLI_HexBasic["analisador.py"]:::cli
        CLI_HexPlus["analisador_plus.py"]:::cli
        CLI_PCAPLoader["leitor_pcap.py"]:::cli
        CLI_FileExtractor["extrator_arquivos_pcap.py"]:::cli
        CLI_ForensicBasic["auditoria_forense_pcap.py"]:::cli
        CLI_ForensicFull["auditoria_forense_pcap_completo.py"]:::cli
        CLI_MD2HTML["md_para_html.py"]:::cli
        CLI_MD2PDF["md_para_pdf.py"]:::cli
    end

    %% Core Modules
    subgraph "Core Modules"
        direction TB
        CM_PCAPLoader["PCAP Loader"]:::core
        CM_HexInterpreter["Hex Interpreter"]:::core
        CM_TCPSession["TCP Session Reassembler"]:::core
        CM_FileSig["File Signature Detector"]:::core
        CM_PacketHTTP["Packet/HTTP Analyzer"]:::core
        CM_Detection["Forensic Detection Engine"]:::core
        CM_ReportGen["Report Generator"]:::core
        CM_Converter["Converter Modules"]:::core
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        EXT_Scapy["Scapy"]:::external
        EXT_Stdlib["Python stdlib"]:::external
    end

    %% Output & Storage
    subgraph "Output & Storage"
        direction TB
        OUT_Extracted["./arquivos_extraidos/"]:::output
        OUT_MD["Markdown Reports (.md)"]:::output
        OUT_HTML["HTML Reports (.html)"]:::output
        OUT_PDF["PDF Reports (.pdf)"]:::output
    end

    %% Data Flows
    CLI_HexBasic -->|"invoke"| CM_HexInterpreter
    CLI_HexPlus -->|"invoke"| CM_HexInterpreter
    CLI_HexPlus -->|"invoke"| CM_PacketHTTP
    CLI_PCAPLoader -->|"invoke"| CM_PCAPLoader
    CLI_FileExtractor -->|"invoke"| CM_PCAPLoader
    CLI_FileExtractor -->|"invoke"| CM_TCPSession
    CLI_FileExtractor -->|"writes"| OUT_Extracted
    CLI_ForensicBasic -->|"invoke"| CM_Detection
    CLI_ForensicFull -->|"invoke"| CM_Detection
    CLI_ForensicBasic -->|"invoke"| CM_ReportGen
    CLI_ForensicFull -->|"invoke"| CM_ReportGen
    CLI_MD2HTML -->|"invoke"| CM_Converter
    CLI_MD2PDF -->|"invoke"| CM_Converter

    CM_PCAPLoader -->|"Packet stream"| CM_PacketHTTP
    CM_PCAPLoader -->|"Packet stream"| CM_TCPSession
    CM_TCPSession -->|"Reassembled streams"| CM_FileSig
    CM_PacketHTTP -->|"Analysis results"| CM_Detection
    CM_FileSig -->|"Extraction results"| CM_Detection
    CM_Detection -->|"Findings"| CM_ReportGen
    CM_ReportGen -->|".md"| OUT_MD
    CM_Converter -->|"convert .md"| OUT_HTML
    CM_Converter -->|"convert .md"| OUT_PDF

    EXT_Scapy -.-> CM_PCAPLoader
    EXT_Stdlib -.-> CM_HexInterpreter
    EXT_Stdlib -.-> CM_PacketHTTP
    EXT_Stdlib -.-> CM_TCPSession

    %% Click Events
    click CLI_HexBasic "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/analisador.py"
    click CLI_HexPlus "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/analisador_plus.py"
    click CLI_PCAPLoader "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/leitor_pcap.py"
    click CLI_FileExtractor "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/extrator_arquivos_pcap.py"
    click CLI_ForensicBasic "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap.py"
    click CLI_ForensicFull "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap_completo.py"
    click CLI_MD2HTML "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/md_para_html.py"
    click CLI_MD2PDF "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/md_para_pdf.py"
    click CM_PCAPLoader "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/leitor_pcap.py"
    click CM_HexInterpreter "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/analisador.py"
    click CM_HexInterpreter "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/analisador_plus.py"
    click CM_TCPSession "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/extrator_arquivos_pcap.py"
    click CM_FileSig "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/extrator_arquivos_pcap.py"
    click CM_PacketHTTP "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/analisador_plus.py"
    click CM_Detection "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap.py"
    click CM_Detection "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap_completo.py"
    click CM_ReportGen "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap.py"
    click CM_ReportGen "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/auditoria_forense_pcap_completo.py"
    click CM_Converter "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/md_para_html.py"
    click CM_Converter "https://github.com/jeanrafaellourenco/pcap-forensics-toolkit/blob/main/md_para_pdf.py"

    %% Styles
    classDef cli fill:#cce5ff,stroke:#004085,color:#004085;
    classDef core fill:#d4edda,stroke:#155724,color:#155724;
    classDef output fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external stroke-dasharray: 5 5,fill:none,stroke:#6c757d,color:#6c757d;
```
