| Crates.io | slinger-mitm |
| lib.rs | slinger-mitm |
| version | 0.0.3 |
| created_at | 2025-11-16 06:05:05.578674+00 |
| updated_at | 2025-11-30 15:17:13.157078+00 |
| description | MITM proxy with transparent traffic interception using rustls backend for slinger |
| homepage | https://github.com/emo-crab/slinger |
| repository | https://github.com/emo-crab/slinger |
| max_upload_size | |
| id | 1935251 |
| size | 139,530 |
A Man-in-the-Middle (MITM) proxy library with transparent HTTPS traffic interception using rustls backend, similar to Burp Suite.
The MITM proxy uses an advanced certificate generation approach inspired by hudsucker:
Issuer for clean separation between root CA and server certificatesAdd this to your Cargo.toml:
[dependencies]
slinger-mitm = { path = "../slinger-mitm" }
tokio = { version = "1", features = ["full"] }
use slinger_mitm::{MitmConfig, MitmProxy, Interceptor};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create proxy with default configuration
let config = MitmConfig::default();
let proxy = MitmProxy::new(config).await?;
// Add logging interceptor
let interceptor_handler = proxy.interceptor_handler();
let mut handler = interceptor_handler.write().await;
handler.add_request_interceptor(Arc::new(Interceptor::logging()));
handler.add_response_interceptor(Arc::new(Interceptor::logging()));
drop(handler);
// Start the proxy
proxy.start("127.0.0.1:8080").await?;
Ok(())
}
use async_trait::async_trait;
use bytes::Bytes;
use http::{Request, Response, HeaderValue};
use slinger_mitm::{RequestInterceptor, ResponseInterceptor, Result};
struct CustomInterceptor;
#[async_trait]
impl RequestInterceptor for CustomInterceptor {
async fn intercept_request(&self, mut request: Request<Bytes>) -> Result<Option<Request<Bytes>>> {
// Modify request headers
request.headers_mut().insert(
"X-Custom-Header",
HeaderValue::from_static("value"),
);
Ok(Some(request))
}
}
#[async_trait]
impl ResponseInterceptor for CustomInterceptor {
async fn intercept_response(&self, mut response: Response<Bytes>) -> Result<Option<Response<Bytes>>> {
// Modify response
response.headers_mut().insert(
"X-Modified",
HeaderValue::from_static("true"),
);
Ok(Some(response))
}
}
Run your proxy application:
cargo run --example simple_proxy
The proxy will automatically generate a CA certificate at .slinger-mitm/ca_cert.pem.
For Firefox:
For Chrome/System:
/usr/local/share/ca-certificates/ and run sudo update-ca-certificatesThe MITM proxy supports both HTTP and SOCKS5 protocols:
HTTP Proxy Mode:
Set your browser to use HTTP proxy at 127.0.0.1:8080 (or whatever port you configured).
SOCKS5 Proxy Mode:
Set your browser/application to use SOCKS5 proxy at 127.0.0.1:8080. The proxy automatically detects the protocol and handles both HTTP and SOCKS5 connections on the same port.
Protocol Support:
use slinger_mitm::MitmConfig;
use std::path::PathBuf;
let config = MitmConfig {
// Directory to store CA certificates
ca_storage_path: PathBuf::from(".slinger-mitm"),
// Enable HTTPS interception (requires CA cert installation)
enable_https_interception: true,
// Maximum concurrent connections
max_connections: 1000,
// Connection timeout in seconds
connection_timeout: 30,
// Optional upstream proxy (supports HTTP, HTTPS, SOCKS5, SOCKS5h)
// Example: Some(slinger::Proxy::parse("socks5h://127.0.0.1:1080")?)
upstream_proxy: None,
};
You can configure slinger-mitm to forward all traffic through an upstream proxy. This is useful for:
use slinger_mitm::MitmConfig;
// Configure with SOCKS5h proxy (remote DNS resolution)
let proxy = slinger::Proxy::parse("socks5h://127.0.0.1:9050")?;
let config = MitmConfig {
upstream_proxy: Some(proxy),
..Default::default()
};
// Supported proxy types:
// - HTTP: "http://proxy.example.com:8080"
// - HTTPS: "https://proxy.example.com:8443"
// - SOCKS5: "socks5://127.0.0.1:1080"
// - SOCKS5h: "socks5h://127.0.0.1:1080" (with remote DNS)
// - With auth: "socks5h://user:pass@127.0.0.1:1080"
Client → MITM Proxy → Target Server
↓
Request Interceptor
↓
Slinger HTTP Client
↓
Response Interceptor
↓
Client
The proxy works by:
See the examples/ directory for more examples:
simple_proxy.rs - Basic logging proxycustom_interceptor.rs - Custom request/response modificationproxy_chain.rs - MITM proxy with upstream proxy support (SOCKS5h, HTTP, etc.)Run an example:
cargo run --example simple_proxy
cargo run --example proxy_chain
WARNING: This is a MITM proxy tool designed for security testing and debugging. Only use it on networks and systems you have permission to test. Installing the CA certificate allows the proxy to decrypt all HTTPS traffic, so protect it accordingly.
GPL-3.0-only
Contributions are welcome! Please feel free to submit a Pull Request.