You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.9 KiB
Markdown

# go-mitmproxy
2 years ago
[简体中文](./README_CN.md)
4 years ago
2 years ago
`go-mitmproxy` is a Golang implementation of [mitmproxy](https://mitmproxy.org/) that supports man-in-the-middle attacks and parsing, monitoring, and tampering with HTTP/HTTPS traffic.
4 years ago
2 years ago
## Key features
4 years ago
2 years ago
- Parses HTTP/HTTPS traffic and displays traffic details via a [web interface](#web-interface).
- Supports a [plugin mechanism](#adding-functionality-by-developing-plugins) for easily extending functionality. Various event hooks can be found in the [examples](./examples) directory.
- HTTPS certificate handling is compatible with [mitmproxy](https://mitmproxy.org/) and stored in the `~/.mitmproxy` folder. If the root certificate is already trusted from a previous use of `mitmproxy`, `go-mitmproxy` can use it directly.
- Refer to the [configuration documentation](#additional-parameters) for more features.
4 years ago
2 years ago
## Unsupported features
2 years ago
2 years ago
- Only supports setting the proxy manually in the client, not transparent proxy mode.
- Currently does not support HTTP/2 protocol parsing or WebSocket protocol parsing.
4 years ago
2 years ago
> For more information on the difference between manually setting a proxy and transparent proxy mode, please refer to the mitmproxy documentation for the Python version: [How mitmproxy works](https://docs.mitmproxy.org/stable/concepts-howmitmproxyworks/). go-mitmproxy currently supports "Explicit HTTP" and "Explicit HTTPS" as mentioned in the article.
## Command Line Tool
### Installation
```bash
3 years ago
go install github.com/lqqyt2423/go-mitmproxy/cmd/go-mitmproxy@latest
4 years ago
```
2 years ago
### Usage
4 years ago
2 years ago
Use the following command to start the go-mitmproxy proxy server:
3 years ago
2 years ago
```bash
3 years ago
go-mitmproxy
4 years ago
```
2 years ago
After starting, the HTTP proxy address is set to port 9080 by default, and the web interface is set to port 9081 by default.
3 years ago
2 years ago
The certificate needs to be installed after the first startup to parse HTTPS traffic. The certificate will be automatically generated after the first startup command and stored in `~/.mitmproxy/mitmproxy-ca-cert.pem`. Installation steps can be found in the Python mitmproxy documentation: [About Certificates](https://docs.mitmproxy.org/stable/concepts-certificates/).
3 years ago
2 years ago
### Additional Parameters
3 years ago
2 years ago
ou can use the following command to view more parameters of go-mitmproxy:
```bash
go-mitmproxy -h
3 years ago
```
2 years ago
```txt
3 years ago
Usage of go-mitmproxy:
4 years ago
-addr string
proxy listen addr (default ":9080")
2 years ago
-allow_hosts value
a list of allow hosts
2 years ago
-cert_path string
path of generate cert files
-debug int
debug mode: 1 - print debug log, 2 - show debug from
2 years ago
-f string
Read configuration from file by passing in the file path of a JSON configuration file.
-ignore_hosts value
a list of ignore hosts
3 years ago
-ssl_insecure
not verify upstream server SSL/TLS certificates.
3 years ago
-version
2 years ago
show go-mitmproxy version
4 years ago
-web_addr string
web interface listen addr (default ":9081")
4 years ago
```
2 years ago
## Importing as a package for developing functionalities
### Simple Example
```golang
package main
import (
"log"
"github.com/lqqyt2423/go-mitmproxy/proxy"
)
func main() {
opts := &proxy.Options{
Addr: ":9080",
StreamLargeBodies: 1024 * 1024 * 5,
}
p, err := proxy.NewProxy(opts)
if err != nil {
log.Fatal(err)
}
log.Fatal(p.Start())
}
```
### Adding Functionality by Developing Plugins
Refer to the [examples](./examples) for adding your own plugins by implementing the `AddAddon` method.
The following are the currently supported event nodes:
```golang
type Addon interface {
// A client has connected to mitmproxy. Note that a connection can correspond to multiple HTTP requests.
ClientConnected(*ClientConn)
// A client connection has been closed (either by us or the client).
ClientDisconnected(*ClientConn)
// Mitmproxy has connected to a server.
ServerConnected(*ConnContext)
// A server connection has been closed (either by us or the server).
ServerDisconnected(*ConnContext)
// The TLS handshake with the server has been completed successfully.
TlsEstablishedServer(*ConnContext)
// HTTP request headers were successfully read. At this point, the body is empty.
Requestheaders(*Flow)
// The full HTTP request has been read.
Request(*Flow)
// HTTP response headers were successfully read. At this point, the body is empty.
Responseheaders(*Flow)
// The full HTTP response has been read.
Response(*Flow)
// Stream request body modifier
StreamRequestModifier(*Flow, io.Reader) io.Reader
// Stream response body modifier
StreamResponseModifier(*Flow, io.Reader) io.Reader
}
```
## WEB Interface
You can access the web interface at http://localhost:9081/ using a web browser.
3 years ago
2 years ago
### Features
4 years ago
2 years ago
- View detailed information of HTTP/HTTPS requests
- Supports formatted preview of JSON requests/responses
- Supports binary mode to view response body
- Supports advanced filtering rules
- Supports request breakpoint function
3 years ago
2 years ago
### Screenshot Examples
3 years ago
![](./assets/web-1.png)
![](./assets/web-2.png)
![](./assets/web-3.png)
4 years ago
4 years ago
## License
[MIT License](./LICENSE)