interceptor

command
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: CC0-1.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

SOCKS Proxy Interceptor Example

A SOCKS5 proxy server that intercepts and modifies HTTP/HTTPS connections, serving mock responses instead of forwarding to real destinations.

Features

  • Protocol Detection: Automatically detects HTTP vs TLS traffic
  • Dynamic TLS: Generates TLS certificates on-the-fly using the provided CA
  • Custom Handlers: Demonstrates how to implement custom command handlers
  • Connection Interception: Serves mock HTTP responses

Prerequisites

Generate a CA certificate and key:

openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 1024 -out ca.crt -subj "/CN=MyTestCA/O=MyOrg/C=US"

Usage

go run .

Default listen address: 127.0.0.1:1080

Options
  • -tcp-addr: TCP listen address (default: 127.0.0.1:1080)
  • -crt: CA certificate file (default: ./ca.crt)
  • -key: CA private key file (default: ./ca.key)

Examples

Intercept HTTP Traffic
curl -4 --proxy socks5h://localhost:1080 http://example.com/
Intercept HTTPS Traffic
# Use the CA certificate to trust the dynamically generated TLS certificate
curl --cacert ca.crt -4 --proxy socks5h://localhost:1080 https://example.com/

How It Works

  1. Accept Connection: SOCKS server accepts incoming connections
  2. Pre-Command Hook: Logs client info, auth method, command, and target address
  3. Command Handler: For CONNECT commands, replies with success
  4. Protocol Detection: Peeks at first few bytes to detect HTTP vs TLS
  5. Interception:
    • HTTP: Directly serves mock response
    • TLS: Generates certificate for target host, performs TLS handshake, serves mock response
  6. Mock Response: Returns a response showing intercepted request details

Documentation

Overview

nolint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL