|
1 | | -## https proxy |
2 | | -It's mitm http/https proxy. It outputs the https request and response for test. |
3 | | - |
4 | | -### Requires |
5 | | -1. require JDK 19+ |
6 | | -2. https cert and private key |
7 | | -3. https certificate. |
8 | | - |
9 | | -If you want to install self-signed certificate, you could use [mkcert](https://github.com/FiloSottile/mkcert) to do this. |
10 | | -more info can be found here [mkcert.md](mkcert.md) |
11 | | - |
12 | | -### Usage |
13 | | -If you want to get all requests and responses about `https://www.exmample.com (192.168.3.3)` |
14 | | -1. change domain ip like:`127.0.0.1 www.example.com` |
15 | | -2. run commands below: |
16 | | -```shell |
17 | | -# run with sbt |
18 | | -sbt "runMain Main --dns=192.168.3.3:www.example.com --jks-path=jks.jks --jks-password=123456 --viewPort=9000" |
19 | | - |
20 | | - |
21 | | -# run with docker |
22 | | -# config file would be: |
23 | | - |
24 | | -# jks { |
25 | | -# path=/server/config/jks.jks |
26 | | -# password=123456 |
27 | | -# } |
28 | | -# resolver=[114.114.114.114] |
29 | | -# viewerPort=9000 |
30 | | -# ##selfSignedCert = "" # if you use self signed cert. |
| 1 | +## HTTPS Proxy |
| 2 | +A MITM (Man-In-The-Middle) HTTP/HTTPS proxy that logs HTTPS requests and responses for debugging and testing purposes. |
| 3 | +### Features |
| 4 | +- Logs HTTPS request and response details. |
| 5 | +- View traffic through a browser UI. |
| 6 | +- Docker & CLI supported. |
| 7 | +- Supports custom DNS mappings and JKS SSL certificates. |
| 8 | +### Requirements |
| 9 | +1. JDK 19+ |
| 10 | +2. HTTPS certificate and private key (in JKS format). |
| 11 | +3. If using self-signed certificates, consider using [mkcert](https://github.com/FiloSottile/mkcert). |
| 12 | + |
| 13 | +> 📄 more info: [mkcert.md](mkcert.md) |
| 14 | +
|
| 15 | +### Quick Start |
| 16 | +Suppose you're intercepting traffic for https://www.example.com (IP: 192.168.3.3). |
| 17 | +#### Step 1: Local Host Mapping |
| 18 | +Edit your system's host file (e.g., `/etc/hosts` or `C:\Windows\System32\drivers\etc\hosts`): |
31 | 19 |
|
32 | | -docker run --rm -v ${pwd}/private.conf:/server/config/application.conf -v${pwd}/jks.jks:/server/config/jks.jks -p 443:443 -p 9000:9000 ghcr.io/timzaak/log-http-proxy:latest |
| 20 | +``` |
| 21 | +127.0.0.1 www.example.com |
| 22 | +``` |
| 23 | +#### Step 2: Run the Proxy |
| 24 | +##### Using SBT |
| 25 | +```bash |
| 26 | +sbt "runMain Main --dns=192.168.3.3:www.example.com --jks-path=jks.jks --jks-password=123456 --viewPort=9000" |
| 27 | +``` |
| 28 | +##### Using Docker |
| 29 | +Create a `private.conf` file with the following content: |
| 30 | +```hocon |
| 31 | +jks { |
| 32 | + path = "/server/config/jks.jks" |
| 33 | + password = "123456" |
| 34 | +} |
| 35 | +resolver = [114.114.114.114] |
| 36 | +viewerPort = 9000 |
| 37 | +# selfSignedCert = "" # Uncomment if using a self-signed cert |
| 38 | +``` |
| 39 | +Then run: |
| 40 | +```bash |
| 41 | +docker run --rm \ |
| 42 | + -v ${PWD}/private.conf:/server/config/application.conf \ |
| 43 | + -v ${PWD}/jks.jks:/server/config/jks.jks \ |
| 44 | + -p 443:443 -p 9000:9000 \ |
| 45 | + ghcr.io/timzaak/log-http-proxy:latest |
33 | 46 |
|
| 47 | +``` |
| 48 | +> Open your browser and navigate to http://127.0.0.1:9000 to view traffic logs. |
34 | 49 |
|
35 | | -# open your browser to access http://127.0.0.1:9000 |
| 50 | +<img src="/doc/usage.png" alt="Usage screenshot" width="500" /> |
36 | 51 |
|
37 | | -``` |
38 | | -<img src="/doc/usage.png" alt="usage" width="500" /> |
| 52 | +### Parameters |
39 | 53 |
|
40 | | -The params are: |
| 54 | +| Name | Description | |
| 55 | +|------------------| --------------------------------------------------------------- | |
| 56 | +| `--dns` | A list of `IP:domain` mappings to inject into the DNS resolver. | |
| 57 | +| `--jks-path` | Path to the JKS file containing the SSL certificate and key. | |
| 58 | +| `--jks-password` | Password for the JKS keystore. | |
| 59 | +| `--resolver` | (Optional) DNS resolver to use (e.g., `1.1.1.1`). | |
| 60 | +| `--viewPort` | (Optional) Port for the web UI or WebSocket logging. | |
41 | 61 |
|
42 | | -* dns: A list of domain-to-IP mappings in the format ip:domain. These mappings will be added to the DNS resolver. |
43 | | -* jksPath: An optional path to a JKS file for SSL/TLS configuration. |
44 | | -* jksPassword: An optional password for the JKS file specified by jksPath. |
45 | | -* resolver: An optional custom DNS resolver address, e.g., 1.1.1.1, 8.8.8.8. |
46 | | -* websocketPort: An optional port to start a WebSocket server for logging. If not provided, logs would output to the command line. |
47 | 62 |
|
48 | | -### Package as command-line tool |
49 | | -```shell |
50 | | -### you can package it with the following command: |
| 63 | +### Packaging as a CLI Tool |
| 64 | +```bash |
| 65 | +# Package with sbt |
51 | 66 | sbt stage |
52 | | -cd package |
53 | 67 |
|
| 68 | +# Then package with jpackage |
| 69 | +cd package |
54 | 70 | version="0.1.0" |
55 | | -jpackage --name https-proxy --input ../target/universal/stage/lib --main-jar https-proxy.https-proxy-${version}.jar --main-class Main --type app-image --win-console |
56 | 71 |
|
| 72 | +jpackage \ |
| 73 | + --name https-proxy \ |
| 74 | + --input ../target/universal/stage/lib \ |
| 75 | + --main-jar https-proxy.https-proxy-${version}.jar \ |
| 76 | + --main-class Main \ |
| 77 | + --type app-image \ |
| 78 | + --win-console |
57 | 79 | ``` |
58 | 80 |
|
59 | 81 |
|
60 | 82 | ### Known Issue |
61 | | -1. Request does not support brotli compression, would drop request header: Accept-Encoding. |
62 | | -2. Request would drop header remote-address |
| 83 | +1. Brotli compression (Accept-Encoding: br) is not supported. This header will be stripped. |
| 84 | +2. remote-address headers are not retained. |
63 | 85 |
|
64 | 86 |
|
65 | | -### Another way to log |
| 87 | +### Alternative Logging (Raw Packet Capture) |
| 88 | +#### On Linux Server |
| 89 | +> Note: Windows users may need to use `tshark` instead. |
66 | 90 |
|
67 | | -```shell |
68 | | -### Linux Server |
69 | | -#### Windows may need use tshark to replace it. |
| 91 | +```bash |
70 | 92 | ssh user@remote 'tcpdump -i any -w - -U port <port>' | wireshark -k -i - |
| 93 | +``` |
71 | 94 |
|
72 | | - |
73 | | -### K8S use debug to inject and run tcpdump, then k8s exec to get tcpdump output |
74 | | -kubectl debug -it <pod-name> -n <namespace> --image=nicolaka/netshoot --target=<container-name> |
75 | | - |
| 95 | +#### On Kubernetes |
| 96 | +```bash |
| 97 | +kubectl debug -it <pod-name> -n <namespace> \ |
| 98 | + --image=nicolaka/netshoot \ |
| 99 | + --target=<container-name> |
76 | 100 | ``` |
| 101 | +Use tcpdump inside the debug container to capture traffic. |
0 commit comments