mitm

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 22 Imported by: 0

README

mitm

A golang mitm library

Request

To use this library, you should have a CA (cert.pem and key.pem).

If you don't have CA files, you can use openssl to generate a custom one like below.

# generate a local RSA CA
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout ca-key.pem -out ca-cert.pem
Usage
package main

import (
    "github.com/xslook/mitm"
)

func mitmHandler(w http.ResponseWriter, r *http.Request) {
    // TODO: handle request/response here
}

func main() {
    certFile := "ca-cert.pem"
    keyFile := "ca-key.pem"
    ca, err := tls.LoadX509KeyPair(certFile, keyFile)
    if err != nil {
        panic(err)
    }
    opts := mitm.Options{
        CA:     ca,
        Handle: mitmHandler,
    }
    proxy, err := mitm.New(opts)
    if err != nil {
        panic(err)
    }
    http.ListenAndServe(":8080", proxy)
}
LICENSE

This project is licensed under the terms of the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BypassHandler added in v0.1.1

func BypassHandler(w http.ResponseWriter, r *http.Request)

BypassHandler pipe request and response, like a normal transparent proxy

Types

type Option added in v0.1.1

type Option func(*Proxy) error

Option to custom proxy

func CA added in v0.1.1

func CA(ca *tls.Certificate) Option

CA option custom CA certificates to use as root CA, it will be used to sign sites' mitm certificates

func Default added in v0.1.2

func Default(h http.HandlerFunc) Option

func Dir added in v0.1.1

func Dir(dir string) Option

Dir option custom directory to store certificates

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy mitm requests

func New

func New(rules Rules, options ...Option) (*Proxy, error)

New a mitm proxy

func (Proxy) ServeHTTP

func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Rules added in v0.1.1

type Rules map[string]http.HandlerFunc

Rules for mitm proxy

Jump to

Keyboard shortcuts

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