Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Webアプリケーション実行環境におけるセキュリティ

 Webアプリケーション実行環境におけるセキュリティ

福岡ゆるっとIT交流会 vol.9「セキュリティの話を聞こう」

2019/01/25

さくらインターネット株式会社
さくらインターネット研究所

上級研究員 松本亮介 / まつもとりー / @matsumotory

MATSUMOTO Ryosuke

January 25, 2019
Tweet

More Decks by MATSUMOTO Ryosuke

Other Decks in Technology

Transcript

  1. ͘͞ΒΠϯλʔωοτגࣜձࣾ
    (C) Copyright 1996-2019 SAKURA Internet Inc
    ͘͞ΒΠϯλʔωοτݚڀॴ
    WebΞϓϦέʔγϣϯ࣮ߦ؀ڥʹ
    ͓͚ΔηΩϡϦςΟ
    2019/01/25 ্ڃݚڀһ দຊ ྄հ
    ෱ԬΏΔͬͱITަྲྀձ vol.9ʮηΩϡϦςΟͷ࿩Λฉ͜͏ʯ

    View full-size slide

  2. 2
    ɾ͘͞ΒΠϯλʔωοτݚڀॴ ্ڃݚڀһ
    ɾגࣜձࣾGrooves Forkewll ٕज़ސ໰
    ɾϖύϘݚڀॴ ٬һݚڀһ ݚڀސ໰
    ɾηΩϡϦςΟɾΩϟϯϓߨࢣ
    ɾ৘ใॲཧֶձ Πϯλʔωοτͱӡ༻ٕज़ݚڀձ ֤छҕһ
    ɾژ౎େֶത࢜ʢ৘ใֶʣ
    দຊ྄հ / ·ͭ΋ͱΓʔ / @matsumotory

    View full-size slide

  3. 3
    WebΞϓϦέʔγϣϯΛ࣮ߦ͢Δ؀ڥͰ͋ΔWebαʔόɼ͞Βʹ͸ɼϗε
    ςΟϯάαʔϏε΍Ϋϥ΢υαʔϏεɼVM΍ίϯςφͱ͍༷ͬͨʑͳ؀ڥ͕
    ଘࡏ͠·͢ɽ
    ຊൃදͰ͸ɼͦΕΒΛͰ͖Δ͚ͩ੔ཧ্ͨ͠ͰɼOSͷηΩϡϦςΟʹؔ͢Δ
    جૅ஌ࣝΛ਎ʹ͚ͭΔͨΊʹɼϗεςΟϯάαʔϏεͷΑ͏ͳWebΞϓϦ
    έʔγϣϯ࣮ߦ؀ڥʹ͓͍ͯɼHWϦιʔείετ΍ੑೳΛ୲อͭͭ͠ɼη
    ΩϡϦςΟΛ୲อ͢ΔͨΊͷ༷ʑͳपลٕज़ʹ͍ͭͯ঺հ͠·͢ɽ
    ࠓ೔ͷ࿩

    View full-size slide

  4. 4
    1. WebαʔόͷԾ૝Խɾִ཭ٕज़ͷ෼ྨ
    2. Webαʔόʹ͓͚Δಈతίϯςϯπͱ೷͖ݟ
    3. CGI࣮ߦํࣜͷηΩϡϦςΟ
    4. DSO࣮ߦํࣜͷηΩϡϦςΟ
    5. ͦͷଞ࠷৽ͷݚڀಈ޲
    ໨࣍

    View full-size slide

  5. 1.
    WebαʔόͷԾ૝Խɾִ཭ٕज़ͷ෼ྨ

    View full-size slide

  6. 6
    1. XenɼKVM΍VMware౳ͷԾ૝ϚγϯͰϗετΛ෼͚Δํ๏
    2. LXCɼOpenVZɼDocker౳ͷίϯςφܕԾ૝ԽͷΑ͏ʹϑΝΠϧγεςϜ΍
    ໊લۭؒΛૢ࡞͢ΔγεςϜίʔϧʹΑͬͯOS্ʹෳ਺ͷԾ૝తͳִ཭؀ڥ
    Λ༻ҙ͠ϗετΛ෼͚Δํ๏
    3. IPΞυϨε΍ϙʔτ୯ҐͰෳ਺ͷϗετΛ෼཭֤͠ϗετʹݸผͷϓϩηεΛ
    ༻ҙͯ͠ىಈͤ͞Δख๏ → WebΞϓϦέʔγϣϯαʔό౳
    4. ୯Ұͷαʔόϓϩηε܈Ͱෳ਺ͷϗετΛԾ૝ϗετํࣜʹΑΓѻ͏ख๏
    Ϋϥ΢υɾϗεςΟϯάͷϗετͷִ཭෼ྨ

    View full-size slide

  7. 7
    • ϗετ୯ҐͰ(1)VMϞσϧɺ(2)ίϯςφϞσϧɺ(3)୯७ϓϩηεϞσϧͰ෼཭
    • (1)͔Βॱʹִ཭Ϩϕϧ͕ߴ͘ίετ΍༻్ʹ߹Θܾͤͯఆ͢Δ
    • (2)ͷϞσϧͷయܕతͳߏ੒
    αʔόӡ༻΍ηΩϡϦςΟΛॏࢹͨ͠৔߹

    View full-size slide

  8. 8
    • unshare(): IPCɺnetɺmountɺpidɺuserͳͲͷ໊લۭؒΛִ཭
    • chroot(): rootσΟϨΫτϦͷมߋ
    • Ծ૝Ϛγϯͱൺֱִͯ͠཭౓͸௿͍͕ऩ༰αʔό୯ҐͰͷऩ༰ޮ཰͸ߴ͍
    • OSͷγεςϜྖҬ͔ΒϑΝΠϧγεςϜɾ໊લۭؒͰִ཭Մೳ
    • chroot؀ڥʹϑΝΠϧϕʔεͰॆ࣮ͨ͠ϥΠϒϥϦ؀ڥΛߏஙՄೳ
    • ϗετ୯ҐͰෆඞཁͳίϚϯυ΍ϥΠϒϥϦΛ഑ஔ͠ͳ͍ͱ੍͍ͬͨޚ͕Մೳ
    unshare()౳ͰϓϩηεΛִ཭͢ΔϞσϧ(2)

    View full-size slide

  9. 9
    • ϗετ୯ҐͰݸผͷJVMΛ༻ҙ
    • ΞϓϦέʔγϣϯαʔόʹΑΔ୯७ͳϓϩηε෼཭Ϟσϧ(3)ʹ֘౰
    • SteinʹΑΔख๏ [1]
    • (3)ͷख๏ϕʔεͰҟͳΔϢʔβݖݶͰϓϩηεΛىಈ͢Δख๏
    • ෳ਺ͷαʔό΁εέʔϧΞ΢τ͢Δ͜ͱ͕ࠔ೉Ͱ͋Δ՝୊΋͋Δ
    JavaServlet΍Ruby on RailsͷϞσϧ(3)
    [1] L. Stein, “SBOX, put CGI scripts in a box,” USENIX Annual Technical Conference, General Track, pp.145–155, June 1999.

    View full-size slide

  10. 10
    • (4)୯Ұͷαʔόϓϩηε܊Ͱෳ਺ͷϗετΛԾ૝తʹॲཧ͢Δߏ੒
    • WebαʔόͷԾ૝ϗετํࣜͱΑ͹ΕΔϚϧνςφϯτΞʔΩςΫνϟ
    • ϦιʔείετΛޮ཰Խͤ͞ΔͨΊʹ͸౎߹ͷྑ͍ߴूੵϞσϧ
    ߴूੵʹϗετΛऩ༰͢Δ৔߹ͷϞσϧ

    View full-size slide

  11. 11
    • Ծ૝ϗετํࣜʹΑΔϚϧνςφϯτΞʔΩςΫνϟΛ࠾༻
    • ୯ҰͷҰൠతͳWebαʔόʹ਺ສҎ্ͷϗετΛऩ༰Մೳ
    • εϖοΫͱͯ͠CPU24εϨουɺϝϞϦ32GBఔ౓ͷWebαʔόΛ૝ఆ
    • ϗεςΟϯάαʔϏεͰྑ͘࠾༻͞ΕΔϞσϧͰ΋͋Δ
    ߴूੵWebαʔόͱ͸

    View full-size slide

  12. 12
    • ΞΫηεͷ߹ͬͨϗετ໊ʹରԠͨ͠υΩϡϝϯτϧʔτΛಈతʹղੳ
    • Ծ૝ϗετ਺ʹϓϩηε਺͕ґଘ͠ͳ͍ͨΊߴूੵऩ༰࣌ʹޮ཰͕ྑ͍
    • ڞ༗ετϨʔδʹσʔλΛల։͢Ε͹Webαʔό܈ͷෛՙ෼ࢄ͕Մೳ
    • σʔλ΍ઃఆ͕Webαʔόʹݻఆ͞Εͳ͍ͨΊ
    • ಈతίϯςϯπͷ࣮ߦʹ༷ʑͳ޻෉͕ඞཁͱͳΓෳࡶͰ͋Δ
    • Ϧιʔεڝ߹໰୊΍ηΩϡϦςΟͷ୲อɺߴूੵ࣌ͷੑೳ΍ӡ༻ٕज़ͷ໰୊
    Ծ૝ϗετํࣜͷϝϦοτͱσϝϦοτ

    View full-size slide

  13. 13
    • Ծ૝ϚγϯϨϕϧͷ෼཭
    • ߴूੵʹϗετΛऩ༰͢Δʹ͸ෆ޲͖ɾηΩϡϦςΟॏࢹͷ৔߹
    • ϓϩηεϨϕϧͷ෼཭
    • ϗετ਺ʹґଘͯ͠ϓϩηε਺͕૿Ճ͢ΔͨΊߴूੵʹ͸ෆ޲͖
    • ୯Ұͷαʔόϓϩηε܈Ͱෳ਺ͷϗετΛԾ૝తʹ෼཭
    • ϗετ਺ʹґଘ͠ͳ͍ͨΊߴूੵʹద͍ͯ͠Δ
    • ಛఆͷϗετͷϦιʔεઐ༗͕αʔόϓϩηεͷϦιʔεΛઐ༗͢Δ
    ߴूੵऩ༰ʹ͓͚Δϗετִ཭·ͱΊ

    View full-size slide

  14. 2.
    Webαʔόʹ͓͚Δಈతίϯςϯπͱ
    ೷͖ݟ

    View full-size slide

  15. 15
    • CGIʢCommon Gateway Interfaceʣ࣮ߦํࣜ
    • DSOʢDynamic Shared Objectʣ࣮ߦํࣜ
    Webαʔόʹ͓͚Δಈతίϯςϯπ࣮ߦํࣜ

    View full-size slide

  16. 16
    CGI࣮ߦํࣜ
    $(*QSPDFTT QIQDHJJOEFYQIQ
    $(*QSPDFTT
    GPSL

    UFSNJOBUFQSPDFTT
    FYFDWF

    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ϦΫΤετຖʹϓϩηεͷੜ੒ɾഁغͱൺֱతେ͖ͳ
    ΠϯλϓϦλόΠφϦʢ1)1ͩͱQIQDHJʣͷ
    FYFDWF
    ͕ඞཁ

    View full-size slide

  17. 17
    DSO࣮ߦํࣜ
    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF
    JOEFYQIQ
    QBSTFSVO
    αʔόϓϩηεʹΠϯλϓϦλΛϥΠϒϥϦ
    ͱͯ͠௚઀૊ΈࠐΜͰ͓͘

    View full-size slide

  18. 18
    • CGI࣮ߦํࣜ
    • ΠϯλϓϦλͷෳ਺όʔδϣϯΛ࣮ߦͰ͖Δ
    • DSO࣮ߦํࣜ
    • ੑೳ͸ߴ͍͕جຊతʹ͸୯ҰͷWebαʔόʹΠϯλϓϦλΛෳ਺όʔδϣϯ
    ࣋ͯͳ͍
    • ࣮ߦํࣜʹΑΒͣݖݶ෼཭ػೳΛར༻͠ͳ͍৔߹͸Webαʔόϓϩηεͱಉ༷
    ͷΦʔφͰ࣮ߦ͞ΕΔͨΊηΩϡϦςΟ্ͷ՝୊͕͋Δ
    ಈతίϯςϯπͷ࣮ߦํࣜͷͦͷଞಛ௃

    View full-size slide

  19. 19
    • OSͷγεςϜྖҬͰWebαʔόϓϩηεΛҰൠϢʔβͷݖݶͰىಈ
    • ҰൠϢʔβͰӾཡՄೳͳΦʔφઃఆͷϑΝΠϧ΍σΟϨΫτϦ͸ӾཡՄೳ
    • Webαʔόϓϩηε͸Ծ૝ϗετͷશͯͷίϯςϯπΛૢ࡞͢Δඞཁ͕͋Δ
    • ΞΫηε੍ޚΛ͠ͳ͍৔߹ɺશͯͷԾ૝ϗετ͕૬ޓʹίϯςϯπΛ೷͖ݟՄ
    ೳʹͳΔ
    Ծ૝ϗετํࣜͷݖݶ෼཭

    View full-size slide

  20. 20
    Ծ૝ϗετؒͰͷίϯςϯπ೷͖ݟ
    w JOEFYDHJ͸BQBDIFݖݶͰ࣮ߦ
    w JOEFYDHJͷதͰ֎෦ίϚϯυ࣮ߦʹ
    ΑΓIPTUͷJOEFYDHJΛSFBE͢Δͱ
    ಺༰͕ӾཡՄೳ
    w JOEFYDHJͷதʹECQBTT͕ॻ͔Εͯ
    ͍Δ͜ͱ΋͋Δ

    View full-size slide

  21. 21
    • suEXECͷΑ͏ͳΞΫηε੍ޚػߏΛར༻
    • ಈతίϯςϯπͷ࣮ߦΦʔφΛαʔόϓϩηεͷΦʔφͱม͔͑ͯΒ࣮ߦ
    • ֤ϗετ୯ҐͰ࣮ߦΦʔφΛݸผʹมߋ͢Δ͜ͱͰ೷͖ݟΛ๷͙
    Ծ૝ϗετํࣜͷΞΫηε੍ޚͷجຊઓུ

    View full-size slide

  22. 3.
    CGI࣮ߦํࣜͷηΩϡϦςΟ

    View full-size slide

  23. 23
    • VirtualHostʹ͓͍ͯଞϗετྖҬΛӾཡͰ͖ͳ͍ߏ੒ΛߏஙՄೳ
    • CGI࣮ߦ࣌ʹ࣮ߦΦʔφΛมߋ͢ΔΞʔΩςΫνϟ
    CGI࣮ߦํࣜͱsuEXECͷجຊઓུ

    View full-size slide

  24. 24
    CGI࣮ߦํࣜ
    $(*QSPDFTT QIQDHJJOEFYQIQ
    $(*QSPDFTT
    GPSL

    UFSNJOBUFQSPDFTT
    FYFDWF

    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ϦΫΤετຖʹϓϩηεͷੜ੒ɾഁغͱ
    ൺֱతେ͖ͳόΠφϦʢ1)1ͩͱQIQDHJόΠφϦʣͷ
    FYFDWF
    ͕ඞཁ

    View full-size slide

  25. $(*QSPDFTT
    PXOFSVTFS

    $(*QSPDFTT
    PXOFSSPPU

    QIQDHJJOEFYQIQ
    PXOFSVTFS

    $(*QSPDFTT
    PXOFSVTFS

    ੩తʹઃఆ͞ΕͨVJEΛݩʹTFUVJE
    TFUHJE

    GPSL

    FYFDWF
    TVFYFDQSPHSBN TFUVJESPPU

    UFSNJOBUFQSPDFTT
    FYFDWF

    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ϦΫΤετຖʹ$(*༻ϓϩηεͷ
    ੜ੒ഁغ͕ඞཁ
    ˞$(*TV&9&$

    View full-size slide

  26. 27
    • DoerschΒʹΑΔख๏[1]
    • suEXEC࣌ʹ֤ϗετ؀ڥͰchroot()γεςϜίʔϧʹΑΓִ཭
    • ϗετྖҬ֎ͷϑΝΠϧΛӾཡ͢Δ͜ͱ͕Ͱ͖ͳ͍
    • ϗετ୯ҐͰݸผʹϥΠϒϥϦ΍࣮ߦ؀ڥΛ༰қ͢Δඞཁ͸͋Δ
    • ෳ਺ͷ࣮ߦ؀ڥͷݻఆతͳϥΠϒϥϦ͸ϋʔυϦϯΫͰࢀর͢Δ͜ͱʹΑΓ
    ࣮ߦ؀ڥߏங΍࢖༻༰ྔͷίετΛ࡟ݮՄೳ
    suEXECͱchrootͷ૊Έ߹ΘͤʹΑΔִ཭ख๏

    View full-size slide

  27. $(*QSPDFTT
    PXOFSVTFS

    $(*QSPDFTT
    PXOFSSPPU

    QIQDHJJOEFYQIQ
    PXOFSVTFS

    $(*QSPDFTT
    PXOFSVTFS

    DISPPU
    ޙ
    TFUVJE
    TFUHJE

    GPSL

    FYFDWF
    TVFYFDQSPHSBN TFUVJESPPU

    UFSNJOBUFQSPDFTT
    FYFDWF

    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    DISPPU&OWJSPONFOU
    ˞%PFSTDIΒͷख๏

    View full-size slide

  28. 29
    • CGIϓϩάϥϜ࣮ߦ୯ҐͰϓϩηεͷੜ੒ɾഁغ͕ඞཁͱͳΓੑೳ͕௿͘ͳΔ
    • suEXECϓϩάϥϜͷexecv()΋ෳ਺ճ࣮ߦ
    • ϓϩάϥϜͷΠϯλϓϦλΛ࠷ॳ͔Βىಈ͢Δඞཁ͕͋Γىಈίετ͕ߴ͍
    • DSOͷΞΫηε੍ޚͷੑೳͱൺֱͯ͠ޙड़
    CGI࣮ߦํࣜͷΞΫηε੍ޚͷ՝୊

    View full-size slide

  29. 4-1.
    DSO࣮ߦํࣜͷηΩϡϦςΟ
    (ΞϓϦέʔγϣϯϨΠϠʔͰͷΞΫηε੍ޚ)

    View full-size slide

  30. 31
    • αʔόϓϩηεʹ૊ΈࠐΜͩΠϯλϓϦλ͕ϓϩάϥϜΛ௚઀࣮ߦ
    • ϦΫΤετ୯ҐͰϓϩηεͷੜ੒ɾഁغ͕ෆཁ
    • ΠϯλϓϦλΛ࠷ॳ͔Βϩʔυ͢Δඞཁ΋ແ͠
    • εΫϦϓτͷߦ಄ʹShebangߦͷهड़΋ඞཁແ͠
    • αʔόϓϩηεͷΦʔφͰ࣮ߦ͞ΕΔͨΊηΩϡϦςΟʹ஫ҙ͕ඞཁ
    • ΞΫηε੍ޚख๏͕͍͔ͭ͘ఏҊ͞Ε͖ͯͨ
    DSO࣮ߦํࣜͷϝϦοτͱݖݶ෼཭

    View full-size slide

  31. 32
    DSO࣮ߦํࣜ
    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF
    JOEFYQIQ
    QBSTFSVO
    αʔόϓϩηεʹΠϯλϓϦλΛϥΠϒϥϦ
    ͱͯ͠௚઀૊ΈࠐΜͰ͓͘

    View full-size slide

  32. 33
    • DSO࣮ߦํࣜͰ͋Δmod_php͸ηʔϑϞʔυͱ͍͏ػೳ͕͋ͬͨ
    • Ծ૝ϗετํࣜͷݖݶ෼཭Λ࣮ݱ͢ΔͨΊͷࢼΈ [2]
    • PHPಛ༗ͷηΩϡϦςΟػߏͰ͋Γ൚༻ੑʹ͚ܽͨ
    • OS΍ϑΝΠϧγεςϜͷݖݶ෼཭ͷ՝୊ΛΞϓϦέʔγϣϯϨΠϠʔͰ࣮ݱ
    ͢Δʹ͸ΞʔΩςΫνϟ্ݱ࣮తͰ͸Μ͔ͬͨ
    • PHP5.3.0Ͱ࢖༻͕ඇਪ঑ͱͳΓɺPHP5.4.0Ͱػೳ࡟আ
    PHPͷηʔϑϞʔυ
    <>IUUQQIQOFUNBOVBMKBGFBUVSFTTBGFNPEFQIQ

    View full-size slide

  33. DSO࣮ߦํࣜͷηΩϡϦςΟ
    (਌αʔόϓϩηεͷrootԽΛར༻ͨ͠ΞΫηε੍ޚ)
    4-2.

    View full-size slide

  34. 36
    • NakamitsuΒʹΑΔख๏ [3]
    • ApacheϞδϡʔϧmod_suid2ͱ࣮ͯ͠૷
    • αʔόϓϩηεΛrootݖݶͰىಈ͓͖ͯ͠ɺϦΫΤετ୯ҐͰݖݶΛมߋ
    rootͷαʔόϓϩηεͰݖݶ෼཭͢Δख๏
    [33] Hideo N, mod-suid2, http://code.google.com/p/ mod-suid2/

    View full-size slide

  35. 37
    DSO࣮ߦํࣜ
    1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF
    JOEFYQIQ
    QBSTFSVO
    αʔόϓϩηεʹΠϯλϓϦλΛϥΠϒϥϦ
    ͱͯ͠௚઀૊ΈࠐΜͰ͓͘

    View full-size slide

  36. 1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSSPPU

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE

    QBSTF SVO
    ˞NPE@TVJE
    $IJMEIUUQEQSPDFTT
    PXOFSVTFS

    $IJMEIUUQEQSPDFTT
    PXOFSVTFS

    UFSNJOBUFQSPDFTT
    ϦΫΤετຖͷࢠIUUQEϓϩηεͷੜ੒ഁغ͕ඞཁ

    View full-size slide

  37. 39
    • DSO࣮ߦํࣜͷϝϦοτͰ͋ΔύϑΥʔϚϯεͷԸܙ͕ಘΒΕͳ͍
    • ϦΫΤετ୯ҐͰࢠαʔόϓϩηεΛੜ੒ɾഁغ͢Δඞཁ͕͋Δ
    • ࢠαʔόϓϩηεͷੜ੒ɾഁغ͸CGIϓϩηεͷੜ੒ɾഁغΑΓ΋ίετߴ
    • ݁ՌతʹCGIํࣜͰϓϩάϥϜΛ࣮ߦ͢ΔΑΓ΋ੑೳ͕௿Լ
    • αʔόϓϩηεʹ೚ҙͷίϚϯυΛ࣮ߦ͢Δ੬ऑੑ͕͋Δ৔߹
    • ༰қʹrootݖݶΛ࣋ͬͨϓϩηεΛୣΘΕΔ
    mod_suid2ͷ՝୊

    View full-size slide

  38. 40
    • αʔόϓϩηεΛrootͰىಈ͠ηΩϡΞOSͰrootͷಛݖΛҰ෦੍ݶ͓ͯ͘͠
    • ϦΫΤετຖʹfork()ͰϓϩηεΛੜ੒͠ɺϓϩηεͷݖݶΛมߋ͔ͯ͠Βί
    ϯςϯπΛ࣮ߦɺϓϩηεΛഁغ͢Δख๏
    • mod_suid2ΑΓ҆શͰ͋Δ͕ϦΫΤετ୯ҐͰϓϩηεͷੜ੒ɾഁغ͕ඞཁ
    • ݪཧతʹDSO࣮ߦํࣜͰ͋ͬͯ΋suEXECΛ࢖ͬͨCGIఔ౓ͷੑೳʹͳΔ
    ݪΒʹΑΔख๏ [4]
    [4] ݪ େีɼඌ྄࡚ଠɼฌ಄࿨थɼதࢁହҰɼ“Harache: ϑΝΠϧॴ༗ऀͷݖݶͰಈ࡞͢Δ WWW αʔόɼ” ৘ॲֶ࿦ɼ
    vol.46, no.12, pp.3127–3137, 2005.

    View full-size slide

  39. 41
    • CGI࣮ߦํࣜ(chroot+suEXEC)ɺCGI࣮ߦํࣜ(suEXEC)ɺDSO(mod_suid2)
    • ಉ࣌઀ଓ਺Λ1͔Β450ʹมԽͤ͞ͳ͕ΒඵؒͷϨεϙϯε਺Λܭଌ
    • PHPͰจࣈྻΛग़ྗ͢Δ͚ͩͷCGIϓϩάϥϜΛར༻
    ࢀߟ: ੑೳධՁ

    View full-size slide

  40. DSO࣮ߦํࣜͷηΩϡϦςΟ
    (ಛݖΛ׆༻ͨ͠ϓϩηε୯ҐͷΞΫηε੍ޚ)
    4-3.

    View full-size slide

  41. 45
    • ੑೳ໘ʹ͓͍ͯCGI͸ຊདྷద͍ͯ͠ͳ͍
    • ऩ༰਺͕૿͑ΔͱϓϩηεͷϝϞϦ࢖༻ྔ͕૿͑fork()ͷޮ཰௿Լ
    • ͦ΋ͦ΋ϦΫΤετ୯ҐͰfork()͢ΔͷͰ஗͍
    • DSO͸ຊདྷfork()Λ࣮ߦ͠ͳ͍ͨΊߴ଎ʹಈ࡞͢Δ͕
    • ैདྷͷDSOͷΞΫηε੍ޚ͸ϦΫΤετຖʹfork()Λ࣮ߦ͢Δ
    ߴूੵϚϧνςφϯτͱCGIɾDSOͷੑೳ

    View full-size slide

  42. 46
    • NakamitsuΒʹΑΔmod_ruid2 [6]
    • rootͰαʔόϓϩηεΛىಈ͢ΔͷͰ͸ͳ͘rootͷಛݖΛࡉ෼Խ্ͨ͠ͰҰൠ
    ϢʔβʹಛݖΛҰ෦༩͑Δ → Linux Capability
    • ΦʔφΛมߋ͢ΔCAP_SETUIDͱCAP_SETGIDΛ༩͑Ε͹ྑ͍
    ҰൠϢʔβͷϓϩηεͰݖݶ෼཭͢Δख๏
    [6] Hideo, N, mod-ruid2, https://github.com/mind04/mod-ruid2
    ΦϑΟγϟϧͷURL͕΋͏ݟ౰ͨΒͳͯ͘୅ΘΓʹmind04͞Μ͕ఏڙΛଓ͚͍ͯΔ໛༷

    View full-size slide

  43. 47
    • ೚ҙΞΫηε੍ޚʢDACʣ
    • ࣗ਎͕࡞ͬͨϦιʔε΁ʹΞΫηε͸ࣗ਎͕ܾఆ
    • UNIXͷඪ४తͳϞσϧ
    • ڧ੍ΞΫηε੍ޚʢMACʣ
    • ࣗ਎͕࡞ͬͨϦιʔεʹ׬શʹΞΫηεͰ͖ΔΘ͚Ͱ͸ͳ͍
    • ؅ཧऀ͕ܾఆ → SELinuxɺTOMOYO Linux
    ΞΫηε੍ޚϞσϧͷ෮श

    View full-size slide

  44. 48
    • Linux2.2Ҏ߱
    • ैདྷͷ2֊૚ͷDACݖݶϞσϧͷ֦ு
    • εϨου୯Ґʹ੍ޚՄೳͳಛݖάϧʔϓ
    • εϨου͸3छྨͷcapability setΛ࣋ͭ
    • PermittedɺEffectiveɺInheritable
    • capability setͷ૊Έ߹ΘͤʹΑͬͯcapabilityͷݖݶΛ੍ޚ
    Linux Capabilities

    View full-size slide

  45. 49
    • Permitted͸ڐՄ
    • EffectiveͷηοτɾΞϯηοτ͕Մೳ
    • PermittedΛΞϯηοτ͢Δͱ໭Εͳ͍
    • Effective͸࣮ޮ
    • ࣮ࡍͷݖݶՄ൱νΣοΫ͸EffectiveΛ൑ఆ͢Δ
    • Permitted͕ڐՄ͞Ε͍ͯΕ͹Ξϯηοτޙͷ࠶ηοτ͕Մೳ
    PermittedͱEffective

    View full-size slide

  46. 50
    • ໿40άϧʔϓʹ෼ׂ͞Ε͍ͯΔ
    • uidɾgidมߋͷಛݖ
    • ಛݖϙʔτʢ1024ҎԼʣͷόΠϯυಛݖ
    • chrootͷಛݖ
    • rebootͷಛݖͳͲͳͲ……..
    ಛݖͷࡉ෼Խ

    View full-size slide

  47. 51
    • ಛݖΛ͍࣋ͬͯΔҰൠϢʔβͰ΋execve()࣌ʹಛݖ͕མͱ͞ΕΔ
    • ͨͩ͠ɺrootݖݶͰexecve()ͨ͠৔߹͸ಛݖΛҾ͖ܧ͛Δ
    • ϑΝΠϧࣗମʹಛݖΛઃఆͨ͠৔߹͸execve()࣌ʹಛݖΛҾ͖ܧ͙
    • ͋Β͔͡ΊϑΝΠϧʹಛݖΛઃఆ͢Δඞཁ͋Γ
    • ೚ҙͷίϚϯυΛ೚ҙͷϢʔβͰಛݖΛ༩࣮͑ͭͭߦ͢Δ৔߹͸Ͱ͖ͳ͍ʁ
    • ҰൠϢʔβͰͷexecve()͕ඞཁɺ͔ͭɺϑΝΠϧʹಛݖΛઃఆͰ͖ͳ͍
    ࣮૷࣌ͷ஫ҙ఺΍੍໿ͳͲ

    View full-size slide

  48. 52
    • Linux4.3͔Β௥Ճ͞Εͨcapability
    • ࢠϓϩηεʹҾ͖ͮͭಛݖ܈
    • ҰൠϢʔβͰfile capability͕ͳͯ͘΋execve()ޙʹҾ͖ܧ͛Δ
    • γϯϓϧͰ͋Δ͕࢖͍ํ࣍ୈͰ͸ඇৗʹڧྗ
    • ίϯςφ࣮૷࣌ʹAmbient capabilities͸͋͑ͯΞϯηοτ͢Δ࣮૷΋
    • exeve()ޙͷ਌͔Βͷҙਤ͠ͳ͍ಛݖͷҡ࣋ͱঢ֨Λ๷ࢭ͢ΔͨΊ
    Ambient capabilities

    View full-size slide

  49. 53
    • mod_ruid2Λ࢖ͬͯαʔόϓϩηεΛҰൠϢʔβͰىಈͭͭ͠ɺΦʔφΛมߋ
    ͢ΔಛݖΛ༩͑ͯ΍Ε͹ɺDSO࣮ߦํࣜͰ͋ͬͯ΋ߴ଎ʹݖݶ෼཭Մೳʁ
    • ϦΫΤετ୯ҐͰΦʔφΛมߋͯ͠ϨεϙϯεΛฦͨ͠ΒΦʔφΛ໭͢
    • αʔόϓϩηεʹ೚ҙͷίϚϯυΛ࣮ߦ͢Δ੬ऑੑ͕͋ͬͯ΋ಛݖ͸࠷খݶ
    ʹݶఆͰ͖Δ
    ҰൠϢʔβͷϓϩηεͰݖݶ෼཭͢Δख๏

    View full-size slide

  50. 1BSFOUIUUQEQSPDFTT
    PXOFSBQBDIF

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE

    QBSTF SVO
    ˞NPE@SVJE
    $IJMEIUUQEQSPDFTT
    PXOFSVTFS

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ϦΫΤετຖʹϓϩηεͷੜ੒ഁغ͕ෆཁʁʁʁ
    QSDUM
    TFUVJETFUHJEDBQT
    TFUVJE
    TFUHJE

    View full-size slide

  51. 1BSFOUIUUQEQSPDFTT
    PXOFSBQBDIF

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE

    QBSTF SVO
    ˞NPE@SVJE
    $IJMEIUUQEQSPDFTT
    PXOFSVTFS

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ϦΫΤετຖʹϓϩηεͷੜ੒ഁغ͕ෆཁʁʁʁ
    QSDUM
    TFUVJETFUHJEDBQT
    TFUVJE
    TFUHJE

    ίϯςϯπΛαʔϏεར༻ऀ͕࡞੒Ͱ͖Δ
    ৔߹͸੬ऑੑʹͳΔ

    View full-size slide

  52. 1BSFOUIUUQEQSPDFTT
    PXOFSBQBDIF

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE

    QBSTF SVO
    ˞NPE@SVJE
    $IJMEIUUQEQSPDFTT
    PXOFSVTFS

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    ࣮ߦϓϩηε͕ΦʔφมߋͷಛݖΛ࣋ͬ
    ͍ͯΔͨΊɺίϯςϯπܦ༝Ͱݖݶมߋ
    ͕Մೳʂʂ
    ˣ
    QSDUM
    TFUVJETFUHJEDBQT
    TFUVJE
    TFUHJE

    ίϯςϯπ࣮ߦલʹಛݖΛམͱ͞ͳ͍ͱ͍͚
    ͳ͍ɻͭ·ΓɺϓϩηεͷΦʔφมߋޙ͸ݩ
    ͷΦʔφʹ໭Εͳ͍ͨΊϓϩηεഁغ͕ඞཁ
    VOTFUDBQT

    View full-size slide

  53. 57
    • mod_suid2ͱಉ༷ɺ݁ہͷͱ͜ΖϗεςΟϯάαʔϏεʹ͓͍ͯɺDSO࣮ߦํ
    ࣜʹ͓͍ͯηΩϡϦςΟΛ୲อ͢ΔͨΊʹ͸ϦΫΤετ୯ҐͰαʔόϓϩηε
    ͷੜ੒ɾഁغ͕ඞཁ
    • ݁ՌతʹDSO࣮ߦํࣜΛ࢖͏ੑೳ্ͷϝϦοτ͕ڗडͰ͖ͳ͍
    • ͜ͷΑ͏ͳΞΫηε੍ޚख๏Λ࠾༻͢Δ৔߹͸CGIͷํ͕ϝϦοτ͕ଟ͍
    • ੑೳɾෳ਺ΠϯλϓϦλ͕ར༻ՄೳͳͲ
    ҰൠϢʔβͷϓϩηεͰݖݶ෼཭͢Δख๏

    View full-size slide

  54. 58
    • Webαʔό͔ΒͷݖݶมߋΛՄٯతʹมߋՄೳʹͭͭ͠ɺ࣮ߦ͞ΕΔίϯςϯ
    πϓϩάϥϜ͔Β͸ݖݶΛมߋ͞Εͳ͍Α͏ʹ͢Δख๏
    • ϓϩάϥϜ͔Β࣮ߦ͞ΕΔγεςϜίʔϧΛ͋Β͔͡Ίચ͍ग़͠ɺίϯςϯ
    π࣮ߦ࣌ʹ֘౰ͷγεςϜίʔϧΛϑοΫͯ͠ݖݶมߋͷॲཧΛແޮԽ͢Δ
    • Linuxʹ͓͍ͯγεςϜίʔϧΛద੾ʹϑοΫ͢Δʹ͸Χʔωϧʹ௚઀มߋΛՃ
    ͑Δඞཁ͕͋Δ
    • Χʔωϧ΍ϥΠϒϥϦΛܧଓతʹมߋ͢Δݱ৔Ͱ͸Մൖੑ͕௿͍
    ݪΒͷγεςϜίʔϧΛϑοΫ͢Δख๏ [7]
    [7] ݪ େีɼதࢁହҰɼ“Hussa:εέʔϥϒϧ͔ͭηΩϡΞ ͳαʔόΞʔΩςΫνϟ௿ίετͳαʔόϓϩηε࣮ߦݖ ݶม
    ߋػߏɼ” ୈ 8 ճ৘ใՊֶٕज़ϑΥʔϥϜ (FIT 2009) ߨԋ࿦จूɼRB-002, 2009.

    View full-size slide

  55. DSO࣮ߦํࣜͷηΩϡϦςΟ
    (ಛݖΛ׆༻ͨ͠εϨου୯ҐͷΞΫηε੍ޚ)
    4-4.

    View full-size slide

  56. 60
    • DSO൛ͷੑೳΛ׆͔͢ΞΫηε੍ޚख๏͕ແ͍
    • ࣮ߦํࣜ΍ΠϯλϓϦλ͕ಠࣗʹΞΫηε੍ޚख๏Λ࣮૷͓ͯ͠Γ൥ࡶ
    • Χʔωϧʹ൥ࡶͳ؅ཧΛٻΊΔख๏͸࣮༻্ɺՄൖੑʹ͚ܽΔ
    ͜͜·Ͱͷ·ͱΊ

    View full-size slide

  57. 61
    • ੑೳ໘ʹ͓͍ͯCGI͸ຊདྷద͍ͯ͠ͳ͍
    • ऩ༰਺͕૿͑ΔͱϓϩηεͷϝϞϦ࢖༻ྔ͕૿͑fork()ͷޮ཰௿Լ
    • ͦ΋ͦ΋ϦΫΤετ୯ҐͰfork()͢ΔͷͰ஗͍
    • DSO͸ຊདྷfork()Λ࣮ߦ͠ͳ͍ͨΊߴ଎ʹಈ࡞͢Δ͕
    • ͜͜·ͰͷDSOͷΞΫηε੍ޚ͸ϦΫΤετຖʹfork()Λ࣮ߦ͢Δ
    ߴूੵϚϧνςφϯτͱCGIɾDSOͷੑೳ

    View full-size slide

  58. 62
    • DSOํࣜͷੑೳΛ׆͔͢ΞΫηε੍ޚΞʔΩςΫνϟ
    • ಈతίϯςϯπ࣮ߦલʹΦʔφมߋͷಛݖͷΈΛ༩੍͑ͨޚ༻εϨουΛ࡞੒
    • ΦʔφΛมߋͨ͠εϨου্ͰίϯςϯπΛॲཧ
    • ίϯςϯπ࣮ߦޙ͸εϨουͷΈΛ࡟আ
    • ݖݶ෼཭ͷΦʔόʔϔουΛεϨουͷੜ੒ɾഁغϨϕϧʹ௿ݮ
    দຊΒͷεϨου୯ҐͰΞΫηε੍ޚ [8]
    [8] দຊ྄հ, Ԭ෦णஉ,εϨου୯ҐͰݖݶ෼཭Λߦ͏WebαʔόͷΞΫηε੍ޚΞʔΩςΫνϟ,ిࢠ৘ใ௨৴ֶձ࿦จࢽ
    Vol.J96-B, No.10, pp.1122-1130, Oct 2013.

    View full-size slide

  59. 63
    • ݖݶ෼཭༻ͷ੍ޚ༻εϨουΛੜ੒͢ΔͨΊɺCGI΋ಉҰͷ࿮૊ΈͷதͰݖݶ
    ෼཭͕ՄೳʹͳΔ
    • Ծ૝ϗετ୯ҐͷΦʔφ৘ใ΋ϦΫΤετͷ͋ͬͨίϯςϯπ͔ΒࣗಈͰऔಘ
    ͢ΔͨΊϗετ୯Ґͷݖݶ෼཭ઃఆΛඞཁͱ͠ͳ͍
    • ߴूੵ࣌ʹϗετͷऩ༰ઃఆ਺ͷ໰୊͔Βαʔόϓϩηεͷىಈ࣌ͷϝϞϦ࢖
    ༻ྔ͕૿େ͢Δ͜ͱ͔Βɺfork()࣌ͷੑೳྼԽͷ໰୊΋͕͋ͬͨɺ౷Ұతͳઃ
    ఆͷهड़͕ՄೳͱͳΓfork()ͷੑೳ΋վળՄೳ
    DSOɾCGI࣮ߦํࣜ྆ํʹରԠ

    View full-size slide

  60. 1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    UISFBE
    PXOFSVTFS

    UISFBE
    PXOFSBQBDIF

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE
    ʜ VOTFUDBQT
    DSFBUFUISFBE TFUDBQT
    EFTUSPZUISFBE
    QBSTF SVO
    QSDUM
    TFUVJETFUHJEDBQT
    UISFBE
    PXOFSVTFS

    ˞%40দຊΒͷΞΫηε੍ޚΞʔΩςΫνϟ

    View full-size slide

  61. 1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    UISFBE
    PXOFSVTFS

    UISFBE
    PXOFSBQBDIF

    JOEFYQIQ
    PXOFSVTFS

    TFUVJE
    TFUHJE
    ʜ VOTFUDBQT
    DSFBUFUISFBE TFUDBQT
    EFTUSPZUISFBE
    QBSTF SVO
    QSDUM
    TFUVJETFUHJEDBQT
    UISFBE
    PXOFSVTFS

    ˞%40দຊΒͷΞΫηε੍ޚΞʔΩςΫνϟ
    DISPPU&OWJSPONFOU

    View full-size slide

  62. 1BSFOUIUUQEQSPDFTT
    PXOFSSPPU

    $IJMEIUUQEQSPDFTT
    PXOFSBQBDIF

    UISFBE
    PXOFSVTFS

    UISFBE
    PXOFSBQBDIF

    TFUVJE
    TFUHJE
    ʜ VOTFUDBQT
    DSFBUFUISFBE TFUDBQT
    EFTUSPZUISFBE
    QSDUM
    TFUVJETFUHJEDBQT
    UISFBE
    PXOFSVTFS

    ˞$(*দຊΒͷΞΫηε੍ޚΞʔΩςΫνϟ
    $(*QSPDFTT
    PXOFSVTFS

    QIQDHJJOEFYQIQ
    PXOFSVTFS

    $(*QSPDFTT
    PXOFSVTFS

    GPSL

    UFSNJOBUFQSPDFTT
    FYFDWF

    View full-size slide

  63. 67
    • 1ϦΫΤετ1ϓϩηε઎༗͢ΔαʔόϞσϧલఏ
    • DSO͸εϨουͷ༗ແʹؔΘΒͣαʔόϓϩηεʹ૊Έࠐ·ΕͨΠϯλϓϦλ
    ͕௚઀ϓϩάϥϜΛ࣮ߦ
    • εϨουΛҰ࣌తʹ࡞Δ͜ͱʹΑΔηΩϡϦςΟϨϕϧͷ௿Լ͸ੜ͡ͳ͍
    WebαʔόϞσϧͱ੍ޚ༻εϨουͷߟ࡯

    View full-size slide

  64. 68
    • mod_process_securityϞδϡʔϧ
    • ઃఆ͸ҎԼͷΑ͏ʹγϯϓϧ
    LinuxͰApacheϞδϡʔϧͱ࣮ͯ͠૷

    View full-size slide

  65. 69
    • Apache httpdʹରͯ͠ఏҊΞʔΩςΫνϟΛ࣮૷
    • ඵؒͷϦΫΤετ਺ΛมԽͤ͞Ϩεϙϯε਺Λܭଌ
    • phpinfo()Λग़ྗ͢Δ͚ͩͷ؆୯ͳϓϩάϥϜΛ༻ҙ
    • ֤ख๏ͷੑೳΛධՁ
    ੑೳධՁ

    View full-size slide

  66. 71
    DSO࣮ߦํࣜͷΞΫηε੍ޚੑೳൺֱ
    w ඵؒϦΫΤετ਺Λ૿Ճͤ͞ͳ͕Βඵ
    ؒϨεϙϯε਺Λܭଌ
    w ྘ͷNPE@SVJEΛར༻ͨ͠ΞΫηε੍
    ޚ͸΄ͱΜͲੑೳ͕Ͱ͍ͯͳ͍
    w ੺ͷদຊΒͷΞΫηε੍ޚ͸ΞΫηε
    ੍ޚແ͠ͷ৔߹ͱൺ΂ͯ΋΄ͱΜͲΦʔ
    όʔϔου͸ແ͠
    ੨ɿΞΫηε੍ޚແ͠
    ੺ɿদຊΒͷΞΫηε੍ޚ
    ྘ɿNPE@SVJE౳ͷΞΫηε੍ޚ

    View full-size slide

  67. 72
    CGI࣮ߦํࣜͷΞΫηε੍ޚੑೳൺֱ
    w ඵؒϦΫΤετ਺Λ૿Ճͤ͞ͳ͕ΒඵؒϨ
    εϙϯε਺Λܭଌ
    w $(*ͷΞΫηε੍ޚͷ༗ແʹؔΘΒͣ$(*
    ͷ࣮ߦํࣜͷΦʔόʔϔου͕େ͖͍ͨΊɺ
    ΞΫηε੍ޚʹΑΔΦʔόʔϔου͸ແ͍
    ੨ɿΞΫηε੍ޚແ͠
    ੺ɿদຊΒͷΞΫηε੍ޚ
    ྘ɿTV&9&$

    View full-size slide

  68. 73
    ࣮ݧ݁Ռ·ͱΊ
    ࣮ߦํࣜ ΞΫηε੍ޚద༻ʹΑΔεϧʔϓοτ௿Լ཰
    $(*
    TV&9&$
    NPE@QSPDFTT@TFDVSJUZ
    %40
    NPE@SVJE౳
    NPE@QSPDFTT@TFDVSJUZ

    View full-size slide

  69. 74
    • phpinfo()΁ͷΞΫηεΛstrace͔Βղੳ
    • CGI ʴ suEXEC: 3377ճ
    • mod_php + mod_process_security: 155ճ
    • ΦʔόʔϔουʹͳͬͯΔγεςϜίʔϧ
    • clone() open() close() execve() ͳͲsuEXECؔ࿈
    ࢀߟɿγεςϜίʔϧͷ਺Λൺֱ
    ˞TUSBDFDGQ1*%
    ˞DBUDHJMPHcHSFQWFQPMM@XBJUcHSFQWGVUFYcQFSMBOF
    QSJOU@JG

    View full-size slide

  70. 75
    ࢀߟɿಋೖલޙͷCPU࢖༻ྔൺֱ
    Ұ೔ͷΞΫηε਺͸ͲͪΒͷαʔό΋໿ສ
    $(*ʴTV&9&$ %40ʴNPE@QSPDFTT@TFDVSJUZ
    ˙TZTUFN
    ˙VTFS
    ˙JEMF
    ref: দຊ྄հ, ηΩϡϦςΟͱੑೳཁ݅Λಉ࣌ʹຬͨ͢WebαʔόϗεςΟϯάٕज़ͷ࠷৽ಈ޲,
    https://speakerdeck.com/matsumoto_r/virtualhosting-security-performance-operasion

    View full-size slide

  71. 76
    • ߴूੵϚϧνςφϯτํࣜʹ͓͍ͯηΩϡϦςΟͱੑೳΛཱ྆ͨ͠ख๏
    • αʔόϓϩηεͦͷ΋ͷʹ೚ҙͷίϚϯυΛ࣮ߦͰ͖Δ৔߹͸Ͳ͏ͳΔ͔
    • ϓϩηεΛڞ༗͢ΔݶΓWebαʔόͷΞʔΩςΫνϟ্ϦεΫ͕͋Δ
    • ͦͷ৔߹͸ίετͷ؍఺͔ΒVM΍ίϯςφͷִ཭Λݕ౼͢Δ
    • ίϯςφϨϕϧͷ੬ऑੑͰίϯςφͷ֎ʹग़ΒΕΔϦεΫ͸ʁ
    • Ϧιʔείετ͸ߴ͘ͳΔ͕VMϨϕϧͰͷִ཭Λݕ౼͢Δ΂͖
    ·ͱΊͱϦεΫ

    View full-size slide

  72. 5.
    ͦͷଞ࠷৽ͷݚڀಈ޲

    View full-size slide

  73. 78
    • Time-of-check to time-of-Use Race Condition
    • ҎԼͷॲཧΛUNIX͸ΞτϛοΫʹͰ͖ͳ͍
    • ϑΝΠϧ͕ϦϯΫ͔ɺϑΝΠϧ·ͰͷύεʹϦϯΫؚ͕·ΕΔ͔ɺͦͷݕࠪ
    ޙʹϑΝΠϧΛopen()͢ΔΑ͏ͳॲཧ
    • Webίϯςϯπ͕ࣗ༝ͳϗεςΟϯάʹ͓͍ͯ͸େ͖ͳ໰୊ͱͳΔ
    • Ϛϧνϓϩηεͷαʔόιϑτ΢ΣΞͰ͸λΠϛϯάʹΑͬͯ͸ϦϯΫͷνΣο
    ΫޙʹผϑΝΠϧʹ͢Γସ͑ΒΕΔՄೳੑ༗Γ
    ϦϯΫݕࠪͷTOCTOU໰୊

    View full-size slide

  74. 79
    • ͱ͋ΔԾ૝ϗετA͕੬ऑੑΛಥ͔ΕΔ
    • ϨʔείϯσΟγϣϯΛར༻ͯ͠ଞϗετBͷ.cgiʹରͯ͠.txtͷϦϯΫΛషΔ
    • γϯϘϦοΫϦϯΫ͸ϑΝΠϧͷଘࡏ֬ೝແ͘࡞੒͕Մೳ
    • Ծ૝ϗετํࣜ͸੩తϑΝΠϧͷ৔߹αʔόϓϩηεͷΦʔφͰread
    • ඇϦϯΫ൑ఆޙͰ͋ΔͨΊϗετBͷ.cgiʹॻ͔Εͨid/pass͕ӾཡՄೳ
    ଞϗετͷid/passΛऔಘ͞ΕΔέʔε

    View full-size slide

  75. ϑΝΠϧ͕ϦϯΫ͔ݕࠪ
    ϑΝΠϧͷύεʹϦϯΫ͕
    ؚ·ΕΔ͔ݕࠪ
    ϑΝΠϧΛPQFO
    ͯ͠
    Ϩεϙϯεੜ੒ॲཧ
    8FCαʔόϓϩηεXPSLFS"
    ϑΝΠϧΛϦϯΫʹ
    ஔ͖׵͑
    ϨʔείϯσΟγϣϯͷ
    Մೳੑ
    0,
    0,
    ϦϯΫͷνΣοΫޙʹ
    ผϗετͷϑΝΠϧ
    ʹஔ͖׵͑ΒΕͯ೷͖ݟ
    ͞ΕΔՄೳੑ͋Γ
    8FCαʔόϓϩηεXPSLFS#

    View full-size slide

  76. 81
    • ϗεςΟϯάཁ݅ʹ͓͍ͯ͸ղܾՄೳ
    • ಉҰॴ༗ऀͷϦϯΫ͸࠷ѱݕ஌Ͱ͖ͳͯ͘΋ྑ͍
    • ݕ஌͢΂͖͸ଞϗετɺͭ·Γɺଞͷॴ༗ऀͷϑΝΠϧ΁ͷϦϯΫ͔Ͳ͏͔
    • ϑΝΠϧopen()ޙʹfd͔ΒΦʔφνΣοΫ
    • ͦͷԾ૝ϗετͰઃఆ͍ͯ͠ΔΦʔφͱopen()ͨ͠ϑΝΠϧͷॴ༗ݖΛൺֱ
    mod_fileownercheck [9]
    [9] Ryosuke Matsumotoɼhttps://github.com/matsumotory/mod_fileownercheck.

    View full-size slide

  77. ϑΝΠϧΛPQFO

    GEͷPXOFSͱԾ૝ϗετͷઃ
    ఆͰڐՄ͍ͯ͠ΔPXOFSݕࠪ
    Ϩεϙϯεੜ੒ॲཧ
    ϑΝΠϧΛϦϯΫʹ
    ஔ͖׵͑
    ผϗετͷϦϯΫ
    ʹ͸ஔ͖׵͑ΒΕͳ͍
    8FCαʔόϓϩηεXPSLFS" 8FCαʔόϓϩηεXPSLFS#

    View full-size slide

  78. 83
    • ϦϯΫ࡞੒ͷϨʔείϯσΟγϣϯࣗମ͸๷͛ͳ͍
    • ϗεςΟϯάཁ݅ʹ͓͍ͯผͷॴ༗ऀϑΝΠϧ΁ͷϦϯΫ͸๷͛Δ
    • fdͷownerͱopen()ͨ͠ϑΝΠϧͷownerൺֱͰ͸μϝ
    • ύεʹϦϯΫؚ͕·ΕΔ৔߹Λݕ஌Ͱ͖ͳ͍
    • Ծ૝ϗετͷownerΛ੩తʹอ͓࣋ͯ͘͠
    • υΩϡϝϯτϧʔτͷΦʔφ΍suEXECͷઃఆ͔Βऔಘ͢ΔͳͲ޻෉͕ඞཁ
    ஫ҙ఺

    View full-size slide

  79. 85
    ɾΞϓϦέʔγϣϯΛαʔόʹऩ༰͢ΔࡍͷΞΫηε੍ޚʹ͍ͭͯ
    ɾϋʔυ΢ΣΞϦιʔεΛ׆༻͢ΔͨΊͷ༷ʑͳ޻෉
    ɾOSͷػೳΛ࠷େݶ׆͔ͭͭ͠ੑೳΛ୲อ͢ΔͨΊͷ࢓૊Έ
    ɾΞϓϦέʔγϣϯͷ໨తʹ߹ΘͤͨηΩϡϦςΟϞσϧͷݕ౼
    ɾOSSʹ੬ऑੑ͕͋ͬͨͱ͖ʹͲ͜·ͰӨڹΛ༩͑Δ͔Λݕ౼
    ɾαʔϏεϨϕϧΛఆٛͯͦ͠Εʹִ͋ͬͨ཭ํ๏Λબఆ
    ·ͱΊ

    View full-size slide