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
知られざるSerialize
Search
Yuichi Sugiyama
PRO
July 31, 2019
Technology
540
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
知られざるSerialize
Yuichi Sugiyama
PRO
July 31, 2019
More Decks by Yuichi Sugiyama
See All by Yuichi Sugiyama
20年以上続く PHP 大規模プロダクトを Kubernetes へ ── クラウド基盤刷新プロジェクトの4年間
oogfranz
PRO
0
540
サイボウズ と Garoon と The PHP Foundation と 私 / Cybozu and Garoon and The PHP Foundation and me
oogfranz
PRO
1
630
可能な限り確実にmkdirを成功させるには / Make mkdir
oogfranz
PRO
0
770
サイボウズ #Garoon 開発チームの 「 完成度低いの歓迎LT大会 」 PHPerKaigi出張版 / Low quality LT in PHPerKaigi 2023
oogfranz
PRO
0
790
20年ものの巨大プロダクトをKubernetesに移行している話 後日談/Garoon on Kubernetes after talk
oogfranz
PRO
0
660
20年ものの巨大プロダクトをKubernetesに移行している話/Garoon on Kubernetes
oogfranz
PRO
0
590
PHPアプリケーションだってモニタリングしたい / Monitoring PHP application
oogfranz
PRO
1
690
効果的な静的解析の CI導入パターンを求めて / Great static analysis with CI
oogfranz
PRO
3
4.1k
Dev-meets-Ops
oogfranz
PRO
1
1.1k
Other Decks in Technology
See All in Technology
Essential architectural thinking (revised edition)
ufried
0
120
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
430
ハードウェアコンペでもAI駆動開発が進んでいる話
iotengineer22
1
700
Classmethod Company Deck
satoshi7
0
150
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
170
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
350
サブエージェントと Claude Mods で作る独自 Advisor ツールの話
kenichiodo
1
120
会社説明資料
persolserverworks
0
9.7k
OR学会2026年秋期大会_機械学習と数理最適化の融合による、配合レシピ最適化システム開発事例
brainpadpr
0
140
Loop Engineering これくらいでいい
mikanichinose
0
230
契約書画像からの情報抽出に特化した視覚接地モデルを育てる話
sansantech
PRO
1
180
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
3
810
Featured
See All Featured
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
270
How to build a perfect <img>
jonoalderson
1
6.1k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Chasing Engaging Ingredients in Design
codingconduct
0
360
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
How to train your dragon (web standard)
notwaldorf
96
6.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Transcript
ΒΕ͟ΔSerialize @PHP Study Cybozu Inc, Yuichi Sugiyama
Who am I • ਿࢁ ༞Ұ @oogFranz • αΠϘζ5ΤϯδχΞ •
େاۀ͚άϧʔϓΣΞ Λ࡞ͬͯΔʢPHP 7.2) • ෳۀδϟζϛϡʔδγϟϯ@MASHݭָஂ
serialize(), unserialize()ͬͯ·͔͢ʁ
serialize() όϦϕϯϦ $a = ["hoge", 3, true]; $a[] = &$a;
echo serialize($a); # a:4:{i:0;s:4:"hoge";i:1;i:3;i:2;b:1;i:3;a:4: {i:0;s:4:"hoge";i:1;i:3;i:2;b:1;i:3;R:5;}} • PHPͷΛ෮ݩՄೳͳจࣈྻʹม͢Δɻ • ΫϥεͷΠϯελϯεͰ͋ͬͯมՄೳʂ • DBʹอଘͰ͖ΔʂͬͨͶʂ
serialize() όϦϕϯϦ $a = ["hoge", 3, true]; $a[] = &$a;
echo serialize($a); # a:4:{i:0;s:4:"hoge";i:1;i:3;i:2;b:1;i:3;a:4: {i:0;s:4:"hoge";i:1;i:3;i:2;b:1;i:3;R:5;}} • PHPͷΛ෮ݩՄೳͳจࣈྻʹม͢Δɻ • ΫϥεͷΠϯελϯεͰ͋ͬͯมՄೳʂ • DBʹอଘͰ͖ΔʂͬͨͶʂ
Կ͕ʁ • serialize() ʹ࣮ͦΜͳʹͳ͍ • ٯؔͷunserialize()ʹ͍͔ͭ͘ͷ੬ऑੑ͕͋Δ
PHP Object Injection ʢPOIʣ • ҎԼͷ͕݅ຬͨ͞Ε͍ͯΔ߹ɺ։ൃऀ͕ҙਤ͍ͯ͠ͳ͍ ίʔυΛ߈ܸऀ͕࣮ߦͰ͖Δɻ • __wakeup(), __destruct()ͳͲͷϚδοΫϝιουʹ
෭࡞༻ͷ͋Δίʔυ͕ॻ͔Ε͍ͯΔ • unserialize()ͷҾʹϢʔβʔ͔Βͷೖྗ͕͞ΕΔ
ϚδοΫϝιου • ಛఆͷ݅ͰࣗಈͰൃಈ͢Δຐ๏ • serialize()ͷ࣮ߦ࣌ʹϚδοΫϝιουͷ __sleep() ͕ ͋ͬͨΒࣗಈͰ࣮ߦ͞ΕΔ • unserialize()࣌ʹɺϚδοΫϝιουͷ
__wakeup() ͕ ͋ͬͨΒࣗಈͰ࣮ߦ͞ΕΔ
αϯϓϧ class POIExample{ private $filename; public function __destruct() { unlink($this->filename);
} } unserialize('O:10:"POIExample":1:{s: 20:"POIExamplefilename";s:8:"test.php";}')
αϯϓϧ class POIExample{ private $filename; public function __destruct() { unlink($this->filename);
} } unserialize('O:10:"POIExample":1:{s: 20:"POIExamplefilename";s:8:"test.php";}') ߈ܸऀ͕ҙͷϑΝΠϧͷআ͕Մೳʂ
POIͷ͕͜͜ා͍ • ࣮ࡍʹunserializeʹ͞ΕΔ͜ͱ͕ͳ͍ΫϥεͰ͋ͬͯɺ auto_loadͷΈ͕͋Δͱ࣮ߦ͞Εͯ͠·͏ɻ • privateͷϝϯόมʹҙͷΛೖՄೳ setterΛհ͞ͳ͍ͷͰɺߟྀ͕͍͠ɻ • ԾʹsetterͰσΟϨΫτϦτϥόʔαϧΛ͍Ͱ͍ͯແҙຯ
• json_encode(), json_decode()Λ͏ɻ ˠΦϒδΣΫτΛγϦΞϥΠζɾσγϦΞϥΠζ͢ΔͷͰͳ͚Ε ेɻ • allowed_classesΦϓγϣϯΛ͏ ˠࢦఆ͞ΕͨΫϥεͷΦϒδΣΫτʹ͔͠ ɹม͞Εͳ͍͜ͱ͕อূ͞ΕΔ POIΛ͙ʹʁ
allowed_classes Φϓγϣϯ $serialized_str = 'O:10:"POIExample":1:{s:20:"POIExamplefilename";s: 8:"test.php";}'; $result = unserialize($serialized_str, ['allowed_classes'
=> false]); var_dump($result); /* object(__PHP_Incomplete_Class)#2 (2) { ["__PHP_Incomplete_Class_Name"]=> string(10) "POIExample" ["filename":"POIExample":private]=> string(8) "test.php" } */ echo serialize($result); // O:10:"POIExample":1:{s:20:"POIExamplefilename";s:8:"test.php";}
allowed_classesͰकΕΔͷ • ڐՄ͞Ε͍ͯͳ͍ΫϥεΛunserialize()͢Δͱɺ__PHP_Incomplete_Class ʹม͞ΕΔ • ͦͷΦϒδΣΫτΛ͏Ұserialize͢Δͱ ʢͳ͔ͥʣݩʹΔɻ • σϑΥϧτ true
(ΨόΨό)ͳͷͰ໌ࣔతʹࢦఆ͢Δඞཁ͕͋Δ • falseΛࢦఆ͢Εɺ͋ΒΏΔΫϥεΛڋઈ͢Δ
__PHP_Incomplete_ClassʹͳͬͨΒΤϥʔʹ͍ͨ͠ • ةͳ͍ͷ͕͖͍ͬͯͯΔͷͰΤϥʔʹ͍ͨ͠ • get_class Λͯ͠ɺ__PHP_Incomplete_Class ͔ΛௐΔ • unserialize_callback_func ݺͼग़͞Εͳ͍ͷͰҙɻ
allowed_classes͕͋Εunserializeͬ ͯྑ͍ʁ https://twitter.com/nikita_ppv/status/895571304325062656
allowed_classes͕͋Εunserializeͬ ͯྑ͍ʁ https://www.php.net/manual/ja/function.unserialize.php
unserializeͷ੬ऑੑ੬ऑੑͱΈͳ͞Εͳ͍ • ϝϞϦपΓͳͲͷෆ۩߹Ͱ͋ͬͯ੬ऑੑͱΈͳ͞Εͳ͍ Մೳੑ͕͋Δ • ΧδϡΞϧʹϝϞϦपΓͷෆ۩߹͕ใࠂ͞Ε͍ͯΔ
serializeͨ͠ΛDBʹೖΕΔ͜ͱʹ͍ͭͯ • SQL Ξϯνύλʔϯͷ 5ষ EAVʢΤϯςΟςΟɾΞτϦϏϡʔτɾόϦϡʔʣ ʹͳͬͯΔՄೳੑ͕ߴ͍ɻ
MySQLͱserialize • MySQLͷtextʹγϦΞϥΠζσʔλΛೖΕ͍ͯΔ߹ɺ จࣈ͕Φʔόʔ͢Δͱɺ్தͰΒΕͯ͠·͍ɺ ෮ݩͰ͖ͳ͘ͳΔɻʢStrict SQL Modeʹґଘʣ • MySQL 5.7͔ΒJSONܕ͕͑ΔΑ͏ʹͳͬͨͷͰɺ
ಈతεΩʔϚ͕Ͳ͏ͯ͠ඞཁͳ߹JSONܕΛߟ͑ͨํ͕ Αͦ͞͏ɻ
·ͱΊ • serialize(), unserialize()Λ͍ͬͯͳ͍ͷͳΒɺͦΕ͕Ұ൪ • ͍ͬͯ͠ΔͷͳΒɺPOIΛ͙ͨΊɺϢʔβʔೖྗσʔλ͕ೖͬͯ͜ͳ͍͜ͳ͍͜ͱΛ͔֬Ί Α͏ • ՄೳͰ͋Εjson_encode, json_decodeʹஔ͖͔͑Α͏
• ͦΕແཧͳΒɺallowed_classesΦϓγϣϯͰPOI͠ͷ͝͏ • DBʹอଘ͠ͳ͍Α͏ʹ͠·͠ΐ͏ • ϝϞϦपΓͷෆ۩߹͋ΔͷͰஔ͖͑Λݕ౼͠·͠ΐ͏ɻ