LoginSignup
0
0

More than 5 years have passed since last update.

botocore の通信の中身を mitmproxy で確認

Posted at

Overview

ちょっと前にこんな記事が出てたので、s3 アクセス時の署名のバージョンを確認したい話。
https://dev.classmethod.jp/cloud/aws/s3-sigv2-abolition/

tcpdump だと ssl の中身見れないので、Man-in-The-Middle proxy 使います。

準備

以下とりあえずサンプルで aws s3 で試してますが、
aws ec2 describe-instances とかでも使えます。

mitmproxy

インストールとpemの設定は済ませておいてください。
mac の人は homebrew じゃなくても pip install mitmproxy で普通に入ります。

export MITMPROXY_CA=mitmproxy-ca-cert.pem

起動

mitmproxy -p 8000

localhost:8000 で起動します(ポートはお好みで
あとでプロキシ経由でアクセスすると、ここに通信の中身が出ます。

botocore

awscliboto も中身 botocore を使用していて、AWS_CA_BUNDLE でオレオレ証明書をバンドルできるので、
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html

mitmproxy の証明書をバンドルしておきます。

export AWS_CA_BUNDLE=$MITMPROXY_CA

これを忘れると
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed になるので注意。

挙動確認

awscli の設定は済ませておいてください。

$ python -V
Python 2.7.15

$ virtualenv .venv
(..snip..)

$ . .venv/bin/activate

署名v2(古いバージョン)

あかんやつ
$ pip install awscli==1.10.35
(..snip..)

$ aws --version
aws-cli/1.10.35 Python/2.7.15 Darwin/17.4.0 botocore/1.4.25
$ export HTTPS_PROXY=http://localhost:8000
$ export YOUR_BUCKET=your_bucket

$ aws s3 ls s3://$YOUR_BUCKET

ng.png

署名v4

OKなやつ
$ unset HTTPS_PROXY

$ pip install -U awscli
(..snip..)

$ aws --version
aws-cli/1.16.125 Python/2.7.15 Darwin/17.4.0 botocore/1.12.115
$ export HTTPS_PROXY=http://localhost:8000
$ export YOUR_BUCKET=your_bucket

$ aws s3 ls s3://$YOUR_BUCKET

ok.png

という話。

おまけ

まぁ署名のバージョン知りたいだけなら --debug オプションで見れるんですけどね。

$ aws s3 --debug ls s3://${YOUR_BUCKET} 2>&1 | grep -A 1 -i 'signature'
2019-03-18 17:07:00,252 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2019-03-18 17:07:00,252 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
--
2019-03-18 17:07:00,252 - MainThread - botocore.auth - DEBUG - Signature:
466b9a9d3febd9940d5948b285b41516307c618ad024df36be331490350eb05e
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