xyk blog

最近は iOS 開発の記事が多めです。

mitmproxyメモ

インストール

homebrewからインストールすると古いバージョンがインストールされたので

https://github.com/mitmproxy/mitmproxy/releases

こちらから最新のバージョンv1.0.2のバイナリmitmproxy-1.0.2-osx.tar.gzをダウンロードした。
以下、実機端末で確認するための手順。


設定手順

MaciPhoneをケーブルで接続
MacIPアドレスを調べる
iPhoneWifi設定のHTTPプロキシ設定を「手動」にして上で調べたIPアドレスとポート番号8080を設定する

f:id:xyk:20170207115427p:plain

mitmproxyを起動する
$ ./mitmproxy -p 8080

-

iPhoneのブラウザから http://mitm.it にアクセスして証明書をiPhoneにインストールする

f:id:xyk:20170207115646p:plain

※ このとき以前インストールした証明書が期限切れになっていた。
しばらく期限切れになっているのに気付かずHTTPSの通信ができなくてハマった。
昔にmitmproxyをインストールしたことがあって、その時の古い証明書がMac側に残っていたのが原因だった。
$HOME/mitmproxy/以下に証明書があるので、いったんこのディレクトリを削除して、再度mitmproxyを起動すると新しい証明書が作成された。
ちなみに前は、mitmproxy-ca-cert.pemをメールに添付してiPhoneに送り、それをクリックしてインストールしていた。
手動でやる手順
http://docs.mitmproxy.org/en/stable/certinstall.html

証明書信頼設定をONにする

設定 -> 一般 -> 情報 -> 証明書信頼設定 -> mitmproxy をONにする

f:id:xyk:20190417172125j:plain

ここまでやればOKなはず。

SSL通信ができない場合は、
iPhoneからmitmproxyのプロファイル削除
mac~/mitmproxyディレクトリ削除
を行ってからこの手順を最初から行ってみる。

別のMacでも同一iPhoneに対して mitmproxy を使用する場合は、最初のMacで作成した証明書が必要なので~/mitmproxyディレクトリ毎コピーして持ってくる。
~/mitmproxyディレクトリは mitmproxy 起動時に作成されるので既に作成済みなら先に削除しておく。


キーボードショートカット

以前のバージョンと変わっていた。

http://docs.mitmproxy.org/en/stable/mitmproxy.html

?を押すと一覧が確認できる。

This view:

      A      accept all intercepted flows
      a      accept this intercepted flow
      b      save request/response body
      C      export flow to clipboard
      d      delete flow
      D      duplicate flow
      e      toggle eventlog
      E      export flow to file
      f      filter view
      F      toggle follow flow list
      L      load saved flows
      m      toggle flow mark
      M      toggle marked flow view
      n      create a new request
      o      set flow order
      r      replay request
      S      server replay request/s
      U      unmark all marked flows
      v      reverse flow order
      V      revert changes to request
      w      save flows
      W      stream flows to file
      X      kill and delete flow, even if it's mid-intercept
      z      clear flow list or eventlog
      tab    tab between eventlog and flow list
      enter  view flow
      |      run script on this flow


Movement:

      j, k           down, up
      h, l           left, right (in some contexts)
      g, G           go to beginning, end
      space          page down
      pg up/down     page up/down
      ctrl+b/ctrl+f  page up/down
      arrows         up, down, left, right


Global keys:

      i  set interception pattern
      O  options
      q  quit / return to previous page
      Q  quit without confirm prompt
      R  replay of requests/responses from file


Filter expressions:

      ~a          Match asset in response: CSS, Javascript, Flash, images.
      ~b regex    Body
      ~bq regex   Request body
      ~bs regex   Response body
      ~c int      HTTP response code
      ~d regex    Domain
      ~dst regex  Match destination address
      ~e          Match error
      ~h regex    Header
      ~hq regex   Request header
      ~hs regex   Response header
      ~http       Match HTTP flows
      ~m regex    Method
      ~marked     Match marked flows
      ~q          Match request with no response
      ~s          Match response
      ~src regex  Match source address
      ~t regex    Content-type header
      ~tcp        Match TCP flows
      ~tq regex   Request Content-Type header
      ~ts regex   Response Content-Type header
      ~u regex    URL
      !           unary not
      &           and
      |           or
      (...)       grouping

    Regexes are Python-style.
    Regexes can be specified as quoted strings.
    Header matching (~h, ~hq, ~hs) is against a string of the form "name: value".
    Expressions with no operators are regex matches against URL.
    Default binary operator is &.

    Examples:

      google\.com             Url containing "google.com
      ~q ~b test              Requests where body contains "test"
      !(~q & ~t "text/html")  Anything but requests with a text/html content type.

よく使うやつ。

  • 全クリア
    z

  • followingモード
    F

  • フィルタ
    f

  • インタセプト
    i

  • コピー
    Altを押したまま選択