Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CTFで出題されたXS-Leaks
Search
ntomoya
June 29, 2024
2.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CTFで出題されたXS-Leaks
ntomoya
June 29, 2024
Featured
See All Featured
A better future with KSS
kneath
240
18k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
160
How STYLIGHT went responsive
nonsquared
100
6.2k
Un-Boring Meetings
codingconduct
0
320
Designing Powerful Visuals for Engaging Learning
tmiket
1
420
My Coaching Mixtape
mlcsv
0
150
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
320
Transcript
CTFで出題された XS-Leaks ntomoya #kurenaif_party6
自己紹介 ntomoya 所属CTFチーム:KUDoS Xアカウント :@nntomoya CTFでは主にWeb問を解いています
Same Origin Policy、Content Security PolicyとXS- Leaks
Same Origin Policy (SOP) ブラウザにおける基本的なセキュリティ機構: http://user:
[email protected]
:3000/hoge/fuga?abc=def#test あるOriginによって読み込まれたdocumentやスクリプトが、異なるOriginのリソースにアクセスす ることを制限するもの プロトコル 同一Originの例
(Same-Origin): 異なるOriginの例 (Cross-Origin): ホスト ポート番号 の3つの組で決定される http://example.com:3000/test.html http://example.com:3000/hoge/fuga/abc https://example.com/abc http://flag.example.com:3000/abc http://example.com:8080/abc
Same-Originに対するwindowアクセス https://example.com/xss https://example.com/flag iframe や window.open()で開いたdocument window.open(‘…’) iframe.contentWindow <script> <h1>flag</h1>
</script> 読み取り可能 Same-Originのページに対してはwindowの各プロパティやDOM にアクセスできる
Cross-Originに対するwindowアクセス https://example.com/xss https://flag.example.com/flag window.open(‘…’) iframe.contentWindow <script> <h1>flag</h1> </script> 読み取りできない Cross-Originのページに対してはwindowの各プロパティやDOM
にアクセスできない iframe や window.open()で開いたdocument
Content Security Policy (CSP) ロードされるページに対して読み込み可能なリソースを制限する仕組み (HTTP Headerやmetaタグで指定) Content-Security-Policy: default-src ‘none’;
scriptやstyle、fetch APIなどの あらゆるソースの読み込みを 無効化 Content-Security-Policy: script-src: ‘nonce-2726c7f26c’; 一致するnonceを指定したscript タグのみ許可 Content-Security-Policy: sandbox allow-scripts; iframe内のscript実行を許可、 ダウンロードやtopの別URLへの 移動を許可しない
Content Security Policy https://example.com/flag document. querySelector(‘…’) <script> flagの情報 </script> CSPでスクリプトの実行が制限されている場合、flagを直接取得できない
HTTP/1.1 OK 200 … Content-Security-Policy: script-src 'none’ ; …
XS-Leaksの仕組み https://example.com/xss https://flag.example.com/flag <script> flagの情報 </script> 本来SOPやCSPなどの制限によって取得できない情報を、 これと紐づく観測可能な情報(Oracle)を用いて間接的に取得する手法 iframe や
window.open()で開いたdocument ? <style> </style> flagの情報 ?
XS-Leaksの具体例
Facebook CTF 2019 Secret Note Keeper 問題概要 Noteの保存と検索ができるサービス noteの追加 noteの検索
https://www.s1r1us.ninja/2019/06/facebook-ctf-2019-writeup_2.html#secret
Facebook CTF 2019 Secret Note Keeper 問題概要 検索結果をiframeタグで表示している noteの追加 noteの検索
https://www.s1r1us.ninja/2019/06/facebook-ctf-2019-writeup_2.html#secret
Cross-Originでも読み取り可能なwindowプロパティ https://developer.mozilla.org/ja/docs/Web/Security/Same-origin_policy その中の一つが window.length window.lengthとは? ウィンドウにおけるフレーム (iframeかframeタグ)の数を返す
URLに含まれる検索クエリがフラグの一部になっている場合 https://challenges.fbctf.com:8082/search?query=fbctf{ <iframe …></iframe> window.length は 1 になる
検索クエリがフラグの一部になっていない場合 https://challenges.fbctf.com:8082/search?query=fbctfx window.length は 0 になる
問題の解法 https://challenges.fbctf.com:8082/search?query=fbctf{a https://ctf.ntomoya.com/ Cross-Originでも読み込み可能なwindow.lengthを使って、 URL中の検索クエリがフラグに一部になっているかを総当たりで判定(XS-Search) iframe.contentWindow.length <iframe …></iframe> iframeの数を観測して flagを正誤判定
fbctf{b fbctf{c fbctf{d … と試す
CTFで出題されたXS-Leaks
pbctf 2021: Vault
pbctf 2021 Vaultの概要 リンクをクリックすると同じ見た目のページへ遷移する階層構造のページ クリックした数字(1-32)がURLのパスに付加される https://localhost:5000/3/ https://localhost:5000/3/12/ 12をクリック
pbctf 2021 Vaultの概要 問題のbotは14階層クリックしてフラグを保存してから提出されたページを訪問 flagが保存されたURLのパスを特定する必要がある https://localhost:5000/12/16/12/15/18/11/9/6/11/12/13/16/17/19
訪問したURLに対するスタイルを適用する際に使用される CSS疑似クラス「:visited」を利用 getComputedStyleで適用されている色を観測すれば訪問しているかを判別 できそう・・・?
訪問したURLに対するスタイルを適用する際に使用される CSS疑似クラス「:visited」を利用 getComputedStyleで適用されている色を観測すれば訪問しているかを判別 できそう・・・? プライバシー観点から 「:visited」には厳しい 制約がある getComputedStyleは:visitedでない 状態の色の値を返す
解法 Chromiumでは:visitedの色のレンダリング時間を利用した識別が可能 https://bugs.chromium.org/p/chromium/issues/detail?id=252165 あるページを訪問したかどうかの識別: aタグを大量に並べてレンダリングが重いスタイルを適用 text-shadow: black 1px 1px 50px;
opacity: 1; font-size: 15px; requestAnimationFrameのタイミングで時間を測定 botが訪問した階層 (/12/, /12/16/)を識別できる
HackTM CTF Quals 2023: secrets
自身のsecretを検索する機能が存在、flagもbot自身のsecretの中にある 問題の概要 該当する検索結果が存在する場合 結果を表示するページへリダイレクト https://lactea.kr/entry/hacktm-ctf-2023-writeup URL: http://results.wtl.pw/results?ids=<note_uuid>&query=<query>
問題の概要 該当する検索結果が存在する場合 クエリに応じたfragmentのみを付加して遷移 https://lactea.kr/entry/hacktm-ctf-2023-writeup URL:http://secrets.wtl.pw/#<query>
ChromiumにおけるURLの2MB制限 問題の解法 https://chromium.googlesource.com/chromium/src/+/master/docs/security/url_display_guidelines/url_display_guidelines.md 超えた場合には about:blank#blocked へ遷移
遷移先のURLの長さの違いを用いてURLを細工、一致するフラグがある場合に about:blank#blockedへ遷移させる 遷移先はwindow.originの結果がエラーになるかどうかをtry-catchで観測 問題の解法 http://results.wtl.pw/results?ids=<note_uuid>&query=<query>#A...A http://secrets.wtl.pw/#<query> http://secrets.wtl.pw/search?query=test#AAA...AAA about:blank#blocked Cross-Originからのwindow.originの結果 エラーにならずに読み取りが可能
エラーになる
Dice CTF Quals 2024: another-csp
作成されたiframe内でユーザーが指定した好きなHTMLタグを挿入可能 ただし、CSPとiframe sandboxによってscript実行が制限されたiframeが作成される 問題の概要 <iframe sandbox> <h1 data-token=“…”></h1> (任意のHTMLタグ) http://challenge.example.com
Content-Security-Policy: default-src 'none’ ;
さらにbotはブラウザが正常に開かれたかを判定するコードが存在 ブラウザが時間内に開かれたかどうかを観測可能 問題の概要 https://blog.huli.tw/2024/02/12/en/dicectf-2024-writeup/
flag取得に必要なdata-tokenの値に応じて重いCSSスタイルの適用、ブラウザが クラッシュするかどうかで識別 問題の解法 https://blog.huli.tw/2024/02/12/en/dicectf-2024-writeup/ CSS変数を入れ子にして指定
その他のXS-Leaks問
その他のXS-Leaks フレームカウント - Facebook CTF 2019: Secret Note Keeper エラーページ
- DragonCTF 2020: Scratchpad CSS - pbctf 2021: Vault - Dice CTF 2024: another-csp - SECCON 2023 Finals: DOMLeakify タイミング計測 - justCTF 2020: Computeration Fixed コネクション - Sekai CTF 2022: safelist Lazy loading - Lake CTF 2023: GeoGuessy リダイレクト - HackTM CTF Quals 2023: secrets CSP - pbctf 2020: XSP - SECCON 2023 Finals: cgi-2023 XS-Leaksまとめ: https://xsleaks.dev/