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

GolangでSSHサーバを作ってみる

tsurubee
September 06, 2018

 GolangでSSHサーバを作ってみる

ユーザが接続先を意識しないSSHプロキシサーバを作っている話

tsurubee

September 06, 2018
Tweet

More Decks by tsurubee

Other Decks in Technology

Transcript

  1. !UTVSVCFF(.01FQBCP *OD
    %FWFMPQFST4VNNJU'6,60,"
    (PMBOHͰ44)αʔόΛ
    ࡞ͬͯΈΔ

    View full-size slide

  2. ࣗݾ঺հ
    (.0ϖύϘגࣜձࣾ
    ϗεςΟϯάࣄۀ෦
    ΠϯϑϥνʔϜ
    ௽ాതจ !UTVSVCFF

    ୲౰αʔϏε

    View full-size slide

  3. օ͞Μɺ44)࢖ͬͨ͜ͱ
    ͋Γ·͢ΑͶʁ

    View full-size slide

  4. 44)ͱ͸ʁ
    w4FDVSF4IFMMͷུশ
    wΫϥΠΞϯτrαʔόؒʹ͓͚Δ௨৴ͷ҆શੑΛ֬อ͢Δ
    ͨΊͷϓϩτίϧ



    w44)ΫϥΠΞϯταʔόͱ΋ʹ0QFO44)͕σϑΝΫτ
    ελϯμʔυ
    44)$MJFOU
    $ ssh -V
    OpenSSH_7.6p1, LibreSSL 2.6.2
    44)4FSWFS
    &ODSZQU %FDSZQU

    View full-size slide

  5. 44)ΫϥΠΞϯτɾαʔό͸
    (PMBOHͰ؆୯ʹॻ͚·͢

    View full-size slide

  6. (PMBOHͷಛ௃
    wϫϯόΠφϦͰαʔό΁ͷ഑෍͕؆୯
    w04ϨΠϠʔͷػೳ͕ѻ͍΍͍͢ʢγεςϜϓϩάϥϛϯάʣ
    w(PSPVUJOFʹΑΔฒྻॲཧ
    wඪ४ϥΠϒϥϦͷॆ࣮ɺͳͲͳͲ
    ϛυϧ΢ΣΞ࣮૷ʹద͍ͯ͠Δ
    ༻్ʹ͋ͬͨϛυϧ΢ΣΞΛࣗ࡞͢Δͱ͍͏બ୒ࢶ

    View full-size slide

  7. ࢲͷ৔߹ɾɾ
    (PMBOHͰ44)αʔόΛࣗ࡞͢Δ͜ͱͰɺ
    44)Λ΋ͬͱίϯτϩʔϥϒϧʹ͍ͨ͠ʂ

    View full-size slide

  8. Ϧιʔεϓʔϧ
    wֹ݄ԁ͔Βར༻Ͱ͖Δʂ
    w୆ͷ෺ཧαʔόͷϦιʔεΛෳ਺ͷϢʔβʹఏڙ͢Δʢڞ༻αʔόʣ
    UTVSVCFF
    Ϩϯλϧαʔόʔ
    EFW
    ෳ਺ͷϢʔβͷίϯςϯπ͕
    ϩʔΧϧετϨʔδʹ
    ഑ஔ͞Ε͍ͯΔ
    TTI
    TTI
    TTI
    TTI TTI
    TTIUTVSVCFF!TTI
    TTIEFW!TTI
    Ϣʔβ͸࢖༻Ͱ͖Δαʔό͕
    TTIͩͱ஌͍ͬͯΔඞཁ͕͋Δ
    ϢʔβͱͦͷϢʔβ͕࢖༻͢Δαʔόͷඥ෇͚͕ଘࡏ͢Δ

    View full-size slide

  9. αʔόఏڙऀଆͷطଘͷ՝୊
    TTIUTVSVCFF!TTI
    Ϧιʔεϓʔϧ
    44)$MJFOU
    TTI
    TTI
    TTI
    TTI
    TTI
    w࢖༻αʔό͕มΘͬͨࡍʹ͸Ϣʔβʹ௨஌͕ඞཁ
    wαʔό؅ཧऀͷ౎߹Ͱࣗ༝ʹϢʔβ͕࢖͏αʔόΛมߋͰ͖ͳ͍
    Ϣʔβ
    UTVSVCFF͸TTIʹ
    ҙࣝతʹ઀ଓ͍ͯ͠Δ
    UTVSVCFFͷίϯςϯπΛ
    TTIʹҠઃ͍ͨ͠

    View full-size slide

  10. Ϣʔβ͕઀ଓઌΛҙࣝ͠ͳ͍44)ϓϩΩγαʔό
    TTIUTVSVCFF!TTIQSPYZ
    Ϧιʔεϓʔϧ
    44)ΫϥΠΞϯτ
    Ϣʔβ໊ ઀ଓઌϗετ
    TTIQSPYZ
    1MVHHBCMF
    )PPLT
    44)ΛϓϩΩγ
    wϢʔβ໊ϕʔεͰಈతʹ઀ଓઌΛܾఆͰ͖Δ
    wϢʔβͱ઀ଓઌϗετͷඥ෇͚Λ%#౳ͰҰݩ؅ཧͰ͖ΔFUD
    Ϣʔβ

    View full-size slide

  11. Α͠ʂʂ࡞Δͧʂʂ

    View full-size slide

  12. (PMBOHͷTTIύοέʔδΛோΊͯΈΔ
    IUUQTHJUIVCDPNHPMBOHDSZQUPUSFFNBTUFSTTI

    View full-size slide

  13. (PMBOHͷTTIύοέʔδΛோΊͯΈΔ
    Α͘Θ͔ΒΜ
    IUUQTHJUIVCDPNHPMBOHDSZQUPUSFFNBTUFSTTI

    View full-size slide

  14. 44)αʔόΛॻ͘ʹ͸
    44)ϓϩτίϧΛ஌Δ
    ඞཁ͕͋Δ

    View full-size slide

  15. ϓϩτίϧΛ஌ΔͨΊʹ3'$ΛಡΉ
    w3'$ɿ44)"VUIFOUJDBUJPO1SPUPDPM

    Ϣʔβೝূʢύεϫʔυೝূ΍ެ։伴ೝূʣ
    w3'$ɿ44)5SBOTQPSU-BZFS1SPUPDPM

    τϥϯεϙʔτ૚
    w3'$ɿ44)$POOFDUJPO1SPUPDPM

    νϟωϧ੍ޚ΍ϙʔτϑΥϫʔσΟϯά
    44)͸ɺෳ਺ͷಠཱͨ͠ϓϩτίϧͰߏ੒͞ΕΔ

    View full-size slide

  16. 44)ϓϩτίϧͷશମΠϝʔδ
    $MJFOU 4FSWFS
    44)$0// 3'$

    44)"65) 3'$

    44)53"/4 3'$

    ௨৴ͷ҉߸Խ
    ηογϣϯ伴ͷަ׵
    Ϣʔβೝূ
    νϟωϧͷଟॏԽ
    *OUFSOFU
    wϓϩτίϧͷશମ૾ͷ೺Ѳ΍ॲཧͷྲྀΕΛ௫Ή͜ͱ͕େ੾
    w44)ϓϩΩγαʔό͸ΫϥΠΞϯταʔόͷؒʹׂͬͯೖͬͯɺ
    ҉߸Խ͞Εͨτϥϯεϙʔτ૚Λ஥հ͢Δඞཁ͕͋Δ

    View full-size slide

  17. TTISͱ͍͏44)ϓϩΩγαʔόΛ࡞ͬͯ·͢ʂ
    IUUQTCMPHUTVSVCFFUFDIFOUSZ

    View full-size slide

  18. TTISΛ࢖ͬͯΈΔͱʜ
    $ ssh [email protected] -p 2222
    [email protected]'s password:
    [dev@host-developer ~]$
    $ ssh [email protected] -p 2222
    [email protected]'s password:
    [summi@host-summit ~]$
    ࣮ߦ͢ΔίϚϯυ͸ʮϢʔβ໊ʯҎ֎ಉ͕ͩ͡ɺ
    ҧ͏αʔόʹ44)ϩάΠϯ͢Δ

    View full-size slide

  19. ·ͱΊ
    w(PMBOH͸04ϨΠϠʔͷػೳΛ؆ܿͳίʔυͰѻ͑ΔͳͲɺ

    ϛυϧ΢ΣΞͷ࣮૷ʹదͨ͠ಛ௃Λ༗͍ͯ͠Δ
    wϛυϧ΢ΣΞΛࣗ࡞͢Δ͜ͱͰɺࣗ෼͕ͨͪ΍Γ͍ͨ͜ͱʹ
    Ϛονͨ͠΋ͷΛॊೈʹ࡞ΕΔ
    wϛυϧ΢ΣΞͷࣗ࡞ʹ͸࢖༻͢Δϓϩτίϧͷཧղ͕ඞཁ
    wTTIS͸·ͩ։ൃ్্ɻͲ͔͜Ͱ·ͨόʔϯͬͱ͓࿩͠͠·͢ʂ

    View full-size slide

  20. ͝ਗ਼ௌ͋Γ͕ͱ͏
    ͍͟͝·ͨ͠ʂʂ

    View full-size slide