eCapture

repository·master·Indexed 12 days ago

https://github.com/gojue/ecapture

An eBPF-based tool for capturing SSL/TLS plaintext content and sensitive data, such as SQL queries or shell commands, without requiring CA certificates. Designed for security auditing and traffic analysis on Linux and Android systems, it includes a WebSocket server for event streaming, a Go-based client, and support for OpenSSL 1.0.* and 1.1.* protocol versions.

Tokens
40.5K
Snippets
133
Records
181
Agent score
96%

What's inside eCapture

  1. Overview of eCapture documentation

    master

    eCapture is a tool designed to capture SSL/TLS text content without requiring a CA certificate by leveraging eBPF. The documentation is organized into several key areas to help developers build, extend, and integrate with the project:

    • Getting Started: Guides for building and compiling the project.
    • Architecture & Development: Deep dives into probe refactoring, migration from v1 to v2, and specific module case studies (e.g., GoTLS).
    • Testing: Instructions for end-to-end (e2e) testing.
    • Security & Operations: Guidance on Linux capabilities (least-privilege), performance benchmarking, and defending against unauthorized eBPF tool usage.
    • API Documentation: Technical references for the Event Forwarding API and the Remote Configuration Update API.
    • Integration: Information on using event forwarding with applications and GUI clients.
    • Examples: Sample outputs for various eCapture modes and modules.
  2. Secret Derivation Logic for Handshake and Application Labels

    master

    The following logic describes how specific traffic secrets are derived from the master or handshake secrets:

    Server Application Traffic

    • Input Secret: s->master_secret
    • Label: server_application_traffic
    • Log Label: SERVER_APPLICATION_LABEL

    Client Application Traffic

    • Input Secret: s->master_secret
    • Label: client_application_traffic
    • Log Label: CLIENT_APPLICATION_LABEL

    Server Handshake Traffic

    • Input Secret: s->handshake_secret
    • Final Secret: s->server_finished_secret
    • Label: server_handshake_traffic
    • Log Label: SERVER_HANDSHAKE_LABEL
    • Process: Uses derive_secret_key_and_iv with the handshake secret and the server_handshake_traffic label.

    Client Handshake Traffic

    • Input Secret: s->handshake_secret
    • Final Secret: s->client_finished_secret
    • Label: client_handshake_traffic
    • Log Label: CLIENT_HANDSHAKE_LABEL

    Client Early Traffic

    • Input Secret: s->early_secret
    • Label: client_early_traffic
    • Log Label: CLIENT_EARLY_LABEL
  3. Understand eCapture performance characteristics and limitations

    master

    eCapture uses eBPF uprobes to intercept function calls. The overhead is composed of uprobe entry/exit, eBPF program execution, perf buffer transfer, and userspace processing.

    Expected Overhead Profile

    ScenarioExpected OverheadNotes
    Low traffic (< 100 req/s)Negligible (< 1% CPU)Uprobe cost amortized over few events
    Medium traffic (100-1K req/s)Low (1-3% CPU)Perf buffer well within capacity
    High traffic (1K-10K req/s)Moderate (3-8% CPU)May need to tune perf buffer size
    Very high traffic (> 10K req/s)Significant (> 10% CPU)Risk of perf buffer overflow; use --pid to limit scope

    Mitigating Perf Buffer Overflows

    If you see "lost X events" in the logs, the perf buffer (default 4 MB per CPU) is overflowing. Mitigate this by:

    • Using --pid to limit capture scope to specific processes.
    • Using keylog mode instead of text mode (reduces data per event).
    • Increasing the perf buffer size (if supported by your version).

    Known Limitations

    • Call Frequency Scaling: Overhead scales with the frequency of SSL_read/SSL_write calls, regardless of data size.
    • No Sampling: All events are captured; there is no probabilistic sampling.
    • Single-threaded Processing: The userspace event reader is single-threaded and can become a bottleneck under high load.
    • No Backpressure: If the reader falls behind, events are dropped silently via perf buffer overflow.
  4. Understand the eCapture Protobuf Protocol

    master
    eCapture uses a Protobuf protocol defined in v1/ecaptureq.proto to communicate between the eCapture engine and external components like collectors or debugging tools. The protocol is structured around a top-level LogEntry message that uses a oneof pattern to encapsulate different types of data (Events, Heartbeats, or Process Logs).
  5. Understand the eCapture Protobuf protocol structure

    master
    eCapture uses a Protobuf protocol defined in v1/ecaptureq.proto to communicate with external components like collectors and debugging tools. The protocol is organized around a top-level LogEntry message that uses a oneof pattern to deliver different types of data based on a LogType enum.
  6. Configure OpenSSL capture modes (pcap, keylog, text)

    master

    The OpenSSL module supports three distinct capture modes via the -m flag:

    Pcap Mode

    Saves captured plaintext data in pcap-NG format, viewable in Wireshark. Supports HTTP 1.0/1.1/2.0 over TCP and HTTP/3 (QUIC) over UDP.

    • Use -m pcap or -m pcapng.
    • Use --pcapfile to specify the output file (default: ecapture_openssl.pcapng).
    • Use -i to specify the interface.

    Keylog Mode

    Saves TLS handshake Master Secret keys to a file. You can use these keys in Wireshark to decrypt captured packets.

    • Use -m keylog or -m key.
    • Use --keylogfile to specify the output file (default: ecapture_masterkey.log).

    Text Mode

    Outputs all plaintext data packets directly to the command line or a specified file.

    • Use -m text.
    • Note: As of v0.7.0, this mode no longer captures SSLKEYLOG information.
    ### Pcap Mode Example
    sudo ecapture tls -m pcap -i eth0 --pcapfile=ecapture.pcapng tcp port 443
    
    ### Keylog Mode Example
    sudo ecapture tls -m keylog -keylogfile=openssl_keylog.log
    
    ### Text Mode Example
    sudo ecapture tls -m text
  7. Git tag naming conventions for eCapture

    master

    eCapture uses semantic versioning with specific suffixes to distinguish between pre-release and stable versions. This distinction controls how GitHub Actions builds binaries and Docker images.

    Pre-release Versions

    Used for testing and development. These are marked as Pre-release in GitHub and do not update the latest Docker tag.

    • Alpha: v2.0.0-alpha.1
    • Beta: v2.0.0-beta.1
    • RC (Release Candidate): v2.0.0-rc.1

    Stable Versions

    Standard semantic versions. These are marked as Latest Release and do update the latest Docker tag.

    • Examples: v2.0.0, v2.1.0, v1.8.13
  8. Handle eCapture Log Types and Payloads

    master

    When consuming the WebSocket stream, use the log_type field in the LogEntry to determine how to process the payload:

    1. LOG_TYPE_HEARTBEAT (0): Contains a Heartbeat object with timestamp, count, and message.
    2. LOG_TYPE_PROCESS_LOG (1): Contains a run_log string. This includes application startup info and runtime logs. Note that eCapture caches the first 128 logs and sends them immediately upon client connection.
    3. LOG_TYPE_EVENT (2): Contains an Event object. The payload field within the Event object contains the actual raw bytes of the captured SSL/TLS plaintext.
  9. How the boringssl-offset.c tool works

    master

    The boringssl-offset.c tool is a C++17 utility designed to detect the exact byte offsets of structure fields for a specific version of BoringSSL.

    Key Mechanism: Instead of using fragile shell scripts with sed to handle renamed or deleted fields, the tool uses C++17 type traits (std::void_t + SFINAE) and partial template specialization to detect field existence at compile time.

    • If a field exists: It outputs offsetof(T, field).
    • If a field is missing: It outputs a feature-flag macro or a sentinel value (e.g., 0xFF).

    This allows downstream eBPF headers like kern/boringssl_masterkey.h to use #ifdef logic to adapt to different library versions automatically without manual code changes.

  10. How the Remote Configuration Update API works

    master

    The Remote Configuration Update API allows you to adjust eCapture's capture behavior (such as target processes, ports, and filters) without restarting the process.

    Core Mechanics

    • Protocol: HTTP
    • Method: POST
    • Content-Type: application/json
    • Endpoints: The endpoint paths are the module names themselves (e.g., /tls, /gotls) and have no prefix.
    • Payload: A JSON object matching the internal config.*Config type for that specific module.

    When a configuration is successfully accepted (HTTP 200 + code: 0), eCapture begins applying the new configuration by restarting the relevant module internally.

  11. How BoringSSL adaptive headers handle version changes

    master

    The headers boringssl_const.h and boringssl_masterkey.h use feature flags emitted by the offset tool to adapt to changes in BoringSSL internal structures across Android versions without manual code edits.

    boringssl_const.h (TLS 1.3 Secret Offsets)

    Uses #ifdef SSL_SESSION_ST_SSL_VERSION to switch logic between Android ≤ 15 and Android 16+:

    • Android ≤ 15: Uses private uint8_t secret_[48] and a 48-byte step size.
    • Android 16+: Uses public InplaceVector<uint8_t,48> and a 49-byte step size (SSL_HANDSHAKE_FIELD_STEP).

    boringssl_masterkey.h (TLS Version Detection)

    Uses feature flags to identify TLS versions correctly:

    • Android ≤ 15: Reads TLS version from ssl_st.version (via #ifndef SSL_SESSION_ST_SSL_VERSION).
    • Android 16+: Reads TLS version from SSL3_STATE.version (via #ifdef BSSL__SSL3_STATE_VERSION) to ensure TLS 1.3 connections are identified before the version branch decision.
  12. Understand eCapture WebSocket client behavior

    master

    The ecaptureq WebSocket implementation follows these operational patterns:

    • Broadcast Model: All connected clients receive the same events simultaneously.
    • Real-time Streaming: Events are broadcast as they occur, not buffered (except for initial connection).
    • Initial Buffer: Upon a new connection, the client immediately receives the last 128 log entries.
    • Keep-alive: The server sends a heartbeat every 60 seconds to maintain the connection.
    • Event Format: Captured events include a UUID, PID, Process name, Source/Destination addresses, Type, Length, and the Payload (both plaintext and Base64 encoded).