Slide 1

Slide 1 text

ディストピアブラウザ tyage

Slide 2

Slide 2 text

こんにちは ● id: tyage ● M1 ○ 情報学研究科知能情報学専攻 ネットワークメディア分野 ( 岡部研究室 ) ● 活動 ○ CTF ○ JavaScript

Slide 3

Slide 3 text

本日伝えたいこと

Slide 4

Slide 4 text

冬の旧花背峠は危ない!!

Slide 5

Slide 5 text

旧花背峠とは

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

!!! 危険ゾーン !!! 峠下

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

http://eitaroxninja.blog.jp/archives/4744124.html

Slide 15

Slide 15 text

http://imagefo.tea-nifty.com/blog/2014/01/post-c4c9.html

Slide 16

Slide 16 text

峠下〜旧花背峠は危ない!!

Slide 17

Slide 17 text

TODO: 裏枠がないので話を簡単にする

Slide 18

Slide 18 text

突然ですが

Slide 19

Slide 19 text

皆さんは、監視されてますか?

Slide 20

Slide 20 text

多くの人が、 「監視され」を体験しています

Slide 21

Slide 21 text

あの有名人も

Slide 22

Slide 22 text

検閲済み あのKMC部員も

Slide 23

Slide 23 text

体験してみよう

Slide 24

Slide 24 text

インターネット監視

Slide 25

Slide 25 text

様々なインターネット監視 ● 金盾 ○ 中国十数年の歴史 ● i-Filter ● 安心フィルタリング ● etc...

Slide 26

Slide 26 text

イメージ

Slide 27

Slide 27 text

ユーザ Webサーバ 投稿

Slide 28

Slide 28 text

オッ、待てい 投稿 ユーザ Webサーバ

Slide 29

Slide 29 text

ちょっと確認

Slide 30

Slide 30 text

HTTP ● Web サイトを見る時にやりとりされてるメッセージの規格 POST /tyage/edit HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive Content-Length: 157 Origin: http://anond.hatelabo.jp Content-Type: application/x-www-form-urlencoded title=保育園落ちた日本死ね &body=何なんだよ日本。一億総活躍社 会じゃねーのかよ ... HTTP リクエスト 投稿

Slide 31

Slide 31 text

HTTP ● Web サイトを見る時にやりとりされてるメッセージの規格 HTTP/1.1 200 OK Server: nginx Date: Thu, 16 Mar 2017 12:07:45 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Content-Encoding: gzip ... HTTP レスポンス 投稿できたよー

Slide 32

Slide 32 text

確認おわり

Slide 33

Slide 33 text

どうすれば体験できるか ● ユーザとサーバ間の通信って見れる? ○ ユーザの環境をコントロールできる ○ ネットワークをコントロールできる ○ サーバをコントロールできる

Slide 34

Slide 34 text

どうすれば体験できるか ● ユーザとサーバ間の通信って見れる? ○ ユーザの環境をコントロールできる ■ 今日はこの状況を想定 ○ ネットワークをコントロールできる ○ サーバをコントロールできる

Slide 35

Slide 35 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ GET http://anond.hatelabo.jp HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive Origin: http://anond.hatelabo.jp HTTP Proxy

Slide 36

Slide 36 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ http://anond.hatelabo.jp にアクセスしたいんだな !? HTTP Proxy

Slide 37

Slide 37 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive Origin: http://anond.hatelabo.jp HTTP Proxy

Slide 38

Slide 38 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ HTTP/1.1 200 OK Server: nginx Date: Thu, 16 Mar 2017 12:07:45 GMT Content-Type: text/html; charset=utf-8 HTTP Proxy

Slide 39

Slide 39 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ 返事きたでー HTTP Proxy

Slide 40

Slide 40 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ HTTP/1.1 200 OK Server: nginx Date: Thu, 16 Mar 2017 12:07:45 GMT Content-Type: text/html; charset=utf-8 HTTP Proxy

Slide 41

Slide 41 text

HTTP Proxy ● いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる ● ユーザの代わりに Web サーバにアクセスしてくれるやつ 我々がProxyになれば 通信を読み書き可能!? HTTP Proxy

Slide 42

Slide 42 text

Squid ● HTTP Proxy の一種 ● Web サーバの出力 ( レスポンス ) をキャッシュしたり ● イカちゃん

Slide 43

Slide 43 text

Squidで金盾もどきを作る ● 「天安門事件」という文字を置き換える ● → しかし、 Squid 自体にコンテンツの書き換え機能はない

Slide 44

Slide 44 text

Squidで金盾もどきを作る ● ICAP を使う ○ Internet Content Adaptation Protocol ○ HTTP Proxy から、外部のコンテンツ処理の機能を呼び出すプロトコル HTTP/1.1 200 OK ICAP Server

Slide 45

Slide 45 text

Squidで金盾もどきを作る ● ICAP を使う ○ Internet Content Adaptation Protocol ○ HTTP Proxy から、外部のコンテンツ処理の機能を呼び出すプロトコル RESPMOD icap://localhost ICAP/1.0 Encapsulated: req-hdr=0, res-hdr=137, res-body=296 GET / HTTP/1.1 HTTP/1.1 200 OK リクエストヘッダ レスポンスヘッダ レスポンスボディ ICAP Server

Slide 46

Slide 46 text

Squidで金盾もどきを作る ● ICAP を使う ○ Internet Content Adaptation Protocol ○ HTTP Proxy から、外部のコンテンツ処理の機能を呼び出すプロトコル ICAP/1.0 200 OK Encapsulated: res-hdr=0, res-body=222 GET / HTTP/1.1 HTTP/1.1 200 OK 検閲済み レスポンスを編集 ICAP Server

Slide 47

Slide 47 text

Squidで金盾もどきを作る ● ICAP を使う ○ Internet Content Adaptation Protocol ○ HTTP Proxy から、外部のコンテンツ処理の機能を呼び出すプロトコル ICAP/1.0 200 OK Encapsulated: res-hdr=0, res-body=222 GET / HTTP/1.1 HTTP/1.1 200 OK 検閲済み ICAP Server

Slide 48

Slide 48 text

Squidで金盾もどきを作る $ git clone https://github.com/tyage/spring-camp-2017.git $ cd spring-camp-2017/gfw-squid $ docker build -t gfw-squid . $ docker run -d -P --name gfw gfw-squid

Slide 49

Slide 49 text

Squidで金盾もどきを作る squid.conf icap_enable on icap_service gfw respmod_precache bypass=1 icap://127.0.0.1:1344/gfw adaptation_access gfw allow all icap_send_client_ip on icap_send_client_username on icap_client_username_header X-Authenticated-User icap_retry allow all icap_retry_limit -1

Slide 50

Slide 50 text

Squidで金盾もどきを作る squid.conf icap_enable on icap_service gfw respmod_precache bypass=1 icap://127.0.0.1:1344/gfw adaptation_access gfw allow all icap_send_client_ip on icap_send_client_username on icap_client_username_header X-Authenticated-User icap_retry allow all icap_retry_limit -1 ICAPのサポートを有効に

Slide 51

Slide 51 text

Squidで金盾もどきを作る squid.conf icap_enable on icap_service gfw respmod_precache bypass=1 icap://127.0.0.1:1344/gfw adaptation_access gfw allow all icap_send_client_ip on icap_send_client_username on icap_client_username_header X-Authenticated-User icap_retry allow all icap_retry_limit -1 ICAPサーバを指定 ID どのタイミングでICAPサーバに渡すか (request or response)

Slide 52

Slide 52 text

Squidで金盾もどきを作る squid.conf icap_enable on icap_service gfw respmod_precache bypass=1 icap://127.0.0.1:1344/gfw adaptation_access gfw allow all icap_send_client_ip on icap_send_client_username on icap_client_username_header X-Authenticated-User icap_retry allow all icap_retry_limit -1 ICAPサーバにユーザのIPを渡す

Slide 53

Slide 53 text

Squidで金盾もどきを作る server.py (ICAP Server) from pyicap import * class ICAPHandler(BaseICAPRequestHandler): def gfw_RESPMOD(self): buf = '' while True: chunk = self.read_chunk() if chunk == b'': break buf += chunk self.write_chunk(buf.replace(' 天安門事件 ', ' 検閲済み !!!'))

Slide 54

Slide 54 text

デモ

Slide 55

Slide 55 text

↓ココ

Slide 56

Slide 56 text

↓ココ ↓ココ

Slide 57

Slide 57 text

http://bit.ly/2nwkRfl を見てみよう

Slide 58

Slide 58 text

あれ、HTTPSは?

Slide 59

Slide 59 text

HTTPS ● Secure な HTTP ○ TLS を使って HTTP 通信を暗号化 ○ ネットワーク経路上での盗聴を防ぐ GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive

Slide 60

Slide 60 text

HTTPS ● Secure な HTTP ○ TLS を使って HTTP 通信を暗号化 ○ ネットワーク経路上での盗聴を防ぐ ˁ FCK? �Ϥ� O ���� o ƫ ' �� ZX � � 4M � KF �� ]4m �� [ � e �ѩ��� y(7 ���ٛ DFy t � kW � x ユーザが 暗号化 GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive 見てもわからん

Slide 61

Slide 61 text

HTTPS ● Secure な HTTP ○ TLS を使って HTTP 通信を暗号化 ○ ネットワーク経路上での盗聴を防ぐ ˁ FCK? �Ϥ� O ���� o ƫ ' �� ZX � � 4M � KF �� ]4m �� [ � e �ѩ��� y(7 ���ٛ DFy t � kW � x ユーザが 暗号化 GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive サーバが 復号

Slide 62

Slide 62 text

HTTPS検閲 ● 暗号化・復号に使う鍵をすり替える ○ 詳細は省く (taisei 君の講座と少し被るかも? ) ● CA 証明書もインストール ○ 警告が出ないように

Slide 63

Slide 63 text

mitmproxy ● HTTPS 通信も見れる proxy ○ Squid でも可能だが、こっちのが楽 ● python で連携 script を書けて便利 ○ mitmproxy -s gfw.py ● インターフェースもいろいろ ○ mitmproxy ○ mitmdump ○ mitmweb

Slide 64

Slide 64 text

mitmproxyで金盾もどき $ git clone https://github.com/tyage/spring-camp-2017.git $ cd spring-camp-2017/gfw-mitmproxy $ docker build -t gfw-mitmproxy . $ docker run -d -P --name gfw gfw-mitmproxy

Slide 65

Slide 65 text

mitmproxyで金盾もどき gfw.py # -*- coding: utf-8 -*- def response(flow): flow.response.header['X-CIA'] = 'This HTTP flow is watching by CIA' if ' 天安門事件 '.encode('utf-8') in flow.response.content: flow.response.content = ' 検閲済み '.encode('utf-8') # request を変えたいときは def request(flow):

Slide 66

Slide 66 text

デモ

Slide 67

Slide 67 text

↓ココ

Slide 68

Slide 68 text

↓ココ

Slide 69

Slide 69 text

応用編

Slide 70

Slide 70 text

This slide has been deleted

Slide 71

Slide 71 text

This slide has been deleted

Slide 72

Slide 72 text

This slide has been deleted

Slide 73

Slide 73 text

This slide has been deleted

Slide 74

Slide 74 text

本日伝えたいこと

Slide 75

Slide 75 text

冬の旧花背峠は危ない!!