labunix's blog

labunixのラボUnix

tsharkでSquid3のSSL転送を確認してみる。

■クライアントからプロキシサーバ宛のパケットキャプチャ

# tshark -i 1 \
         -b filesize:50000 -b files:10 -w ~/proxy \
         -f "tcp port 3128"

■例として「api.twitter.com」の情報を取り出す。

# tshark -2 -r proxy_* -n \
       -R "tcp.port==3128 && tcp.flags.syn==0" \
       -T fields -E separator=';' \
       -e frame.time \
       -e ip.src -e tcp.srcport \
       -e ip.dst -e tcp.dstport \
       -e tcp.flags.syn -e tcp.flags.ack \
       -e http.host -e http.request.uri 2>/dev/null | \
    awk -F\; '($NF>"[A-z.]*"){print}' | tail -1 | \
    sed -e 's/;0;1;/\n\t&/g' -e 's/JST;/&\n\t/'
Oct 22, 2015 02:06:16.883998000 JST;
	172.31.XXX.XXX;50344;172.31.YYY.YYY;3128
	;0;1;twitter.com:443;twitter.com:443


■プロキシサーバから外部へのパケットキャプチャ

# tshark -i 1 -b filesize:50000 -n -b files:10 -w ~/proxy

■例として「api.twitter.com」の証明書を取得したところ

# tshark -2 -r proxy_* -n -V \
         -R "(tcp.port==443 || tcp.port==80) && ssl.handshake.certificate" \
         -T fields -E separator=';' \
         -e frame.time \
         -e ip.src -e tcp.srcport \
         -e ip.dst -e tcp.dstport \
         -e tcp.flags.syn -e tcp.flags.ack \
         -e http.host -e http.request.uri \
         -e x509sat.uTF8String -e x509ce.dNSName 2>/dev/null | \
    grep ";api.twitter.com" | sed -e 's/JST;/&\n\t/'
Oct 22, 2015 01:54:53.265344000 JST;
	104.244.42.130;443;192.168.ZZZ.ZZZ;40011;0;1;;;;api.twitter.com