How gojue/ecapture works
Main Components
• CLI/Command Interface – Represented by the “cli” directory (with subfolders like “cmd”, “http”, and “cobrautl”). This is where command parsing, user flags (e.g., mode selection: pcap, keylog, text, gotls, etc.), and the HTTP server (for configuration and monitoring) are initiated.
• eBPF Engine & Kernel Integration – The “kern” folder houses many C source files and header files for different libraries (e.g., OpenSSL, GnuTLS, etc.) as well as sub-folders for BPF bytecode (found inside “kern/bpf”). This component loads and attaches eBPF programs to the target functions in shared libraries.
• Event Processing Pipeline – Located in “pkg/event_processor” and “pkg/proc”. This layer handles the processing, transformation, and testing (via accompanying test files) of captured plaintext and protocol metadata.
• Upgrade and Utility Modules – In “pkg/upgrade” and “pkg/util”, where upgrade checking and various utility functions (like ebpf helper functions, ethernet operations, HKDF, and kernel version parsing) are implemented.
• User Configuration & Custom Modules – Found in the “user” directory (with subdirectories “config”, “event”, and “module”) which indicate pluggable modules that determine what events to capture, how to parse configuration parameters, and how to process the captured events.
• Build & Deployment – Although not part of runtime, the “builder” directory (with Dockerfile, Makefiles, and initialization scripts) and CI configurations (in “.github”) denote the automation and release pipelines for the project.
Relationships and Interactions
• The CLI component (initiated via main.go) first parses command-line arguments. Depending on the selected subcommand (e.g., tls, gotls, bash, mysqld), it then loads the appropriate configuration from the “user/config” folder.
• The CLI triggers the loading of eBPF programs (from pre-compiled bytecode files positioned in “user/bytecode” and referenced in the “utils” and “kern” directories). These are then attached to target functions in the shared libraries found on the host system.
• Once the kernel hooks are in place, the kernel sends captured event data back to userspace. The “pkg/event_processor” processes this data and passes it to different output handlers: either writing to a pcap file (if in pcap mode), logging key material (in keylog mode), or directly outputting plaintext to the console (text mode).
• Additional auxiliary components (like the HTTP server in “cli/http”) provide a GUI-like configuration interface and real-time monitoring.
• Utility packages and upgrade modules ensure sustainability, version checks, and help in adapting the tool for different environments (for instance, handling differences between Android and Linux kernels).
Architectural Patterns and Technologies
• Modular Design – Each function (e.g., capturing for a specific library, processing events, handling configuration) is separated into its own module (e.g., “pkg/event_processor”, “user/module”), following a loosely coupled design.
• Client-Server Pattern – The CLI component doubles as both a command-line tool and a server (via an embedded HTTP server) that listens on a configurable port.
• eBPF and Kernel Space Interaction – The project leverages eBPF’s capability to run custom programs in kernel space, which is central to its functionality. The architecture clearly delineates user-space components (CLI, event processors) from kernel-space components (eBPF programs and probes).
• Deployment & Build Automation – Presence of CI workflows, Docker support, and Makefiles indicate that the project follows modern build and deployment practices.