Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ディストピアブラウザ

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for tyage tyage
March 21, 2017

 ディストピアブラウザ

Avatar for tyage

tyage

March 21, 2017
Tweet

More Decks by tyage

Other Decks in Technology

Transcript

  1. 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 リクエスト 投稿
  2. 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 <!DOCTYPE><html><head> ... HTTP レスポンス 投稿できたよー
  3. 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
  4. HTTP Proxy • いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる • ユーザの代わりに

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

    Web サーバにアクセスしてくれるやつ GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive Origin: http://anond.hatelabo.jp HTTP Proxy
  6. 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 <!DOCTYPE><html><head> HTTP Proxy
  7. HTTP Proxy • いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる • ユーザの代わりに

    Web サーバにアクセスしてくれるやつ 返事きたでー HTTP Proxy
  8. 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 <!DOCTYPE><html><head> HTTP Proxy
  9. HTTP Proxy • いろいろ方法はあるが、 (Forward) HTTP Proxy 使ってみる • ユーザの代わりに

    Web サーバにアクセスしてくれるやつ 我々がProxyになれば 通信を読み書き可能!? HTTP Proxy
  10. Squid • HTTP Proxy の一種 • Web サーバの出力 ( レスポンス

    ) をキャッシュしたり • イカちゃん
  11. Squidで金盾もどきを作る • ICAP を使う ◦ Internet Content Adaptation Protocol ◦

    HTTP Proxy から、外部のコンテンツ処理の機能を呼び出すプロトコル HTTP/1.1 200 OK <!DOCTYPE><html><head> ICAP Server
  12. 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 <!DOCTYPE><html><head> リクエストヘッダ レスポンスヘッダ レスポンスボディ ICAP Server
  13. 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
  14. 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
  15. 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
  16. 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のサポートを有効に
  17. 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)
  18. 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を渡す
  19. 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(' 天安門事件 ', ' 検閲済み !!!'))
  20. HTTPS • Secure な HTTP ◦ TLS を使って HTTP 通信を暗号化

    ◦ ネットワーク経路上での盗聴を防ぐ GET / HTTP/1.1 Host: anond.hatelabo.jp Connection: keep-alive
  21. 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 見てもわからん
  22. 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 サーバが 復号
  23. mitmproxy • HTTPS 通信も見れる proxy ◦ Squid でも可能だが、こっちのが楽 • python

    で連携 script を書けて便利 ◦ mitmproxy -s gfw.py • インターフェースもいろいろ ◦ mitmproxy ◦ mitmdump ◦ mitmweb
  24. 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):