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
530
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
470
サイボウズ と Garoon と The PHP Foundation と 私 / Cybozu and Garoon and The PHP Foundation and me
oogfranz
PRO
1
620
可能な限り確実にmkdirを成功させるには / Make mkdir
oogfranz
PRO
0
760
サイボウズ #Garoon 開発チームの 「 完成度低いの歓迎LT大会 」 PHPerKaigi出張版 / Low quality LT in PHPerKaigi 2023
oogfranz
PRO
0
780
20年ものの巨大プロダクトをKubernetesに移行している話 後日談/Garoon on Kubernetes after talk
oogfranz
PRO
0
660
20年ものの巨大プロダクトをKubernetesに移行している話/Garoon on Kubernetes
oogfranz
PRO
0
580
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
【技術的負債conf】事業成長に伴う技術的負債の説明責任とAIによるモニタリング、認知的負債について
i35_267
3
1.8k
おい、エージェントを使って終わらせろ
nwiizo
2
760
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
5
490
リアーキテクチャ後の障害ゼロを目指したShadow Testingの取り組み
nihonbuson
PRO
1
160
現場で役立つ技術負債の効果的な返済方法
masuda220
PRO
9
4.7k
C#コードの結合を可視化する Roslyn解析による設計改善と リファクタリング判断
dora56
0
220
品質と信頼性を地続きにする
grimoh
2
820
CLIライブラリ開発を支える技術
htnabe
0
140
「どのログを見ればいい?」 から始めた サーバーレス障害解析
y_waka1
1
110
AIエージェントを最高のパートナーに育てる方法|評価と判断軸を育てる5つのステップ
koichiaoki
1
150
Railsのように考える: See through the Master
snoozer05
PRO
4
1.2k
人間はどの意思決定を手放せるのか
kawasima
15
7.5k
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Site-Speed That Sticks
csswizardry
13
1.5k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
430
So, you think you're a good person
axbom
PRO
2
2.2k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.2k
Thoughts on Productivity
jonyablonski
76
5.4k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.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ʹอଘ͠ͳ͍Α͏ʹ͠·͠ΐ͏ • ϝϞϦपΓͷෆ۩߹͋ΔͷͰஔ͖͑Λݕ౼͠·͠ΐ͏ɻ