-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# http-proxy | ||
|
||
This is a sample implementation of HTTP(S) proxy. | ||
|
||
## Setup | ||
You need to generate a CA key and trust it. | ||
|
||
```sh | ||
openssl genrsa -out rootCAKey.pem 2048 | ||
openssl req -x509 -sha256 -new -nodes -key rootCAKey.pem -days 3650 -out rootCACert.pem -subj "/CN=localhost" | ||
openssl x509 -outform der -in rootCACert.pem -out rootCA.crt | ||
``` | ||
|
||
Install the certificate according to your environment. | ||
|
||
```sh | ||
trust anchor --store rootCA.crt | ||
``` | ||
|
||
## Run | ||
```sh | ||
go run . -rootCACert rootCACert.pem -rootCAKey rootCAKey.pem | ||
``` | ||
|
||
```sh | ||
curl -x http://localhost:8080 -v http://github.com/homuler/mitm-go | ||
curl -x http://localhost:8080 -v https://github.com/homuler/mitm-go | ||
curl -x https://localhost:8443 -v http://github.com/homuler/mitm-go | ||
curl -x https://localhost:8443 -v https://github.com/homuler/mitm-go | ||
curl --proxy-http2 https://localhost:8443 -v http://github.com/homuler/mitm-go | ||
curl --proxy-http2 https://localhost:8443 -v https://github.com/homuler/mitm-go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# http-tproxy | ||
|
||
This is a sample implementation of transparent HTTP(S) proxy. | ||
|
||
Note that this program assumes that the host machine is the default route of the client. | ||
If you are testing on a single machine, consider using `netns`. | ||
|
||
## Setup | ||
### Certificate | ||
You need to generate a CA key and trust it. | ||
|
||
```sh | ||
openssl genrsa -out rootCAKey.pem 2048 | ||
openssl req -x509 -sha256 -new -nodes -key rootCAKey.pem -days 3650 -out rootCACert.pem -subj "/CN=mitm-go" | ||
openssl x509 -outform der -in rootCACert.pem -out rootCA.crt | ||
``` | ||
|
||
Install the certificate according to your environment. | ||
|
||
```sh | ||
trust anchor --store rootCA.crt | ||
``` | ||
|
||
### TPROXY | ||
You also need to configure TPROXY. | ||
|
||
```sh | ||
iptables -t mangle -N DIVERT | ||
iptables -t mangle -A DIVERT -j MARK --set-mark 1 | ||
iptables -t mangle -A DIVERT -j ACCEPT | ||
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT | ||
iptables -t mangle -A PREROUTING -p udp -m socket -j DIVERT | ||
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-ip 127.0.0.1 --on-port 8080 | ||
iptables -t mangle -A PREROUTING -p tcp --dport 443 -j TPROXY --tproxy-mark 0x1/0x1 --on-ip 127.0.0.1 --on-port 8443 | ||
iptables -t mangle -A PREROUTING -p udp --dport 443 -j TPROXY --tproxy-mark 0x1/0x1 --on-ip 127.0.0.1 --on-port 443 | ||
iptables -t mangle -A PREROUTING -p udp --dport 8443 -j TPROXY --tproxy-mark 0x1/0x1 --on-ip 127.0.0.1 --on-port 8443 | ||
|
||
ip rule add fwmark 1 lookup 100 | ||
ip route add local 0.0.0.0/0 dev lo table 100 | ||
``` | ||
|
||
## Run | ||
```sh | ||
go run . -rootCACert rootCACert.pem -rootCAKey rootCAKey.pem | ||
``` | ||
|
||
```sh | ||
curl -v http://github.com/homuler/mitm-go | ||
curl -v https://github.com/homuler/mitm-go | ||
``` |