LoginSignup
0
0

More than 1 year has passed since last update.

Martian ProxyでMITM

Posted at

概要

go製のMITMプロキシであるMartian Proxyでレスポンスヘッダを書き換える方法。

インストール

$ go install github.com/google/martian/cmd/proxy@latest

起動

$ ${GOPATH}/proxy \
    -v=2 \
    -addr=:9999 \
    -api-addr=:9898 \
    -generate-ca-cert    # MITM用の証明書を生成する

ヘッダ書き換えの設定

$ vi config.json
{
  "header.Modifier": {
    "scope": ["response"],
    "name": "Test-Header",
    "value": "true"
  }
}

$ curl \
    -x 127.0.0.1:9898 \
    -H 'content-type: application/json' \
    -XPOST \
    -d @config.json \
    http://martian.proxy/configure

証明書の取得

$ curl \
    --proxy http://127.0.0.1:9999 \
    -O authority.cer
    http://martian.proxy/authority.cer

動作確認

$ curl -D - -k --cacert authority.cer --proxy http://127.0.0.1:9999 https://qiita.com/
HTTP/1.1 200 OK
Test-Header: true
Content-Length: 0

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: max-age=0, private, must-revalidate
Content-Type: text/html; charset=utf-8
...
Test-Header: true   # 成功!!
...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0