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

Charles でネットワークデバッギング

kumamotone
September 01, 2018

Charles でネットワークデバッギング

iOSDC Japan 2018
2018/09/01 13:30〜 Track C レギュラートーク(15分)

Charles Proxy
http://charlesproxy.com/

iOSアプリ内で不正なSSL証明書を検知する / SSL Pinning for iOS apps - Speaker Deck
https://speakerdeck.com/kobakei/ssl-pinning-for-ios-apps

kumamotone

September 01, 2018
Tweet

More Decks by kumamotone

Other Decks in Programming

Transcript

  1. ෆ۩߹ͷݪҼ͸ͨ͘͞Μ͋Δ Ҿ༻: Introducing Charles for iOS, HUNTING THE NETWORKING FAULT@try!

    Swift Tokyo 2018 ϦΫΤετ͸ ૹ৴͞Ε͍ͯΔ͔ʁ ਖ਼͍͠ ϦΫΤετ͔ͩͬͨʁ αʔό͸ Ԡ౴͍ͯ͠Δͷ͔ʁ ωοτϫʔΫ͸ ௨͍ͯ͡Δ͔ʁ ΫϥΠΞϯτͷॲཧ͸ ਖ਼͍͔͠ʁ Ϩεϙϯε͸ ਖ਼͔ͬͨ͠ͷ͔ʁ
  2. Ͳ͏΍ͬͯௐ΂Α͏ʁ • print / σόοΨͰ Breakpoint / LLDB ίϚϯυ •

    extension ΍ϥΠϒϥϦΛ༻ҙͯ͠ɺϩάΛు͘ Codable ͷϚοϐϯάʹࣦഊ͍ͯ͠Δ৔߹΍ɺ
 ϨεϙϯεϔομͳͲɺσόοΨͰ͸ͨͲΓ͖ͭʹ͍͘෦෼͸ʁ Ͳͷํ๏Ͱ΋Ͱ͖Δ͕ɺ৭ʑͳํ๏Λ஌ͬͯ
 ͍ΔͱɺॊೈʹରԠͰ͖Δέʔε͕૿͑ΔΜ͡Ό ౰ͨΓલͷ͜ͱΛ ݴ͏ത࢜ → XcodeΛ࢖Θͣʹௐ΂Δํ΋͋Δ
  3. Ͳ͏΍ͬͯௐ΂Α͏ʁ • print / σόοΨͰ Breakpoint / LLDB ίϚϯυ •

    extension ΍ϥΠϒϥϦΛ༻ҙͯ͠ɺϩάΛు͘ Codable ͷϚοϐϯάʹࣦഊ͍ͯ͠Δ৔߹΍ɺ
 ϨεϙϯεϔομͳͲɺσόοΨͰ͸ͨͲΓ͖ͭʹ͍͘෦෼͸ʁ Ͳͷํ๏Ͱ΋Ͱ͖Δ͕ɺ৭ʑͳํ๏Λ஌ͬͯ
 ͍ΔͱɺॊೈʹରԠͰ͖Δέʔε͕૿͑ΔΜ͡Ό ౰ͨΓલͷ͜ͱΛ ݴ͏ത࢜ → XcodeΛ࢖Θͣʹௐ΂Δํ΋͋Δ
  4. • ΫϩεϓϥοτϑΥʔϜ (mac OS / Windows / Linux) • HTTPϓϩΩγ

    • ༗ঈ (ࢼ༻൛͋Γ) Charles Web Debugging Proxy Charles ʹ
 ϦΫΤετ ୺຤ͷ୅ΘΓʹ
 Charles͕ϦΫΤετ ௨৴Λ$IBSMFT1SPYZΛܦ༝ͤ͞Δ͜ͱͰɺ
 $IBSMFTΛ௨ͬͨ௨৴ͷ಺༰ΛӾཡͨ͠Γɺ
 ॻ͖׵͑ͨΓͰ͖Δ
  5. ػೳ • Throttle • 3GճઢͷγϛϡϨʔτ • Map Remote • ಛఆͷHost,

    Path, Query
 ʹରԠ͢ΔϦΫΤετΛɺ
 ผͷHost, Path, Queryʹసૹ͢Δ • DNS Spooling • DNS ͕ղܾ͢ΔIPΞυϨεΛมߋ • ηογϣϯͷอଘ/࠶ੜ(Auto Save Մ) • BlackList/WhiteList • ௨৴Λ௨͢/௨͞ͳ͍υϝΠϯΛࢦఆ • Port Forwarding • ผͷϙʔτΛࢦఆ • Protocol Buffers αϙʔτ • HTTP 2αϙʔτ
  6. ͓΋͠Ζʢʁʣػೳ • Mirror • ϨεϙϯεΛϩʔΧϧʹอଘ • ൒खಈΫϩʔϦϯάʹศར • Flash •

    AMFαϙʔτ • Command-line Tools • ϔουϨεϞʔυ • Web Interface • http://control.charles/ Ͱ
 ઃఆͷΦϯΦϑͳͲͷૢ࡞͕Մೳ
 Ϩεϙϯε͕ݟΕΔΘ͚Ͱ͸ͳ͍
  7. ͦͷ΄͔ͷબ୒ࢶ • mitmproxy • Charles ͱಉ͘͡
 Man-In-The-Middle ܕ ϓϩΩγ •

    Python ੡ OSS (brew/pipͰೖΔ) • CUI / Web ΠϯλϑΣʔε(β) • Python εΫϦϓςΟϯά API Charles ͷັྗ͸ɺݟ΍͢͞ɺ࢖͍΍͢͞
  8. Charles for iOS • ݕূ୺຤ͷΈͰ௨৴಺༰ͷ֬ೝ͕Ͱ͖Δ • ࢖͍Ͳ͜Ζ • ݕূ୺຤ͱmacͷωοτϫʔΫ͕ҧ͏ •

    ΑΓखܰʹʢग़ઌͱ͔ʣ • ηογϣϯͷอଘ • Airdrop Ͱ mac ͱڞ༗ • Cellular ճઢͰͷσόοά
  9. Πϯετʔϧɾઃఆํ๏ 1. Homebrew ͔ dmg ͔ΒΠϯετʔϧ (macOS ͷ৔߹) 2. Proxy

    > SSL Proxy Settings ͔Β༗ޮʹ͢ΔυϝΠϯΛઃఆ 3. ূ໌ॻΛΠϯετʔϧ 4. ূ໌ॻΛ৴པʢmacOS, iOS ͸ಛʹ 10.3ʙʣ • ৄ͘͠͸εϥΠυ຤ඌͷ෇࿥Λ͝ཡ͍ͩ͘͞
  10. Case.1 ݪҼௐࠪ • Ϩεϙϯεͷ಺༰͸૝ఆͱ߹͍ͬͯΔ͔ʁ • Contents -> JSON • JSON

    Λݟ΍͘͢දࣔ • Contents -> JSON Text • JSON Λ੔ܗͯ͠දࣔ
  11. Case.2 ಈ࡞֬ೝ • Ϩεϙϯεॻ͖׵͑ํ๏ 3छྨ • Map Local • Break

    Points / Edit Response • Rewrite ผͷαʔόΛࢀর͍ͤͨ͞ͱ͖͸ɺ Map Remote ΍ DNS SpoolingͰ ผͷυϝΠϯ/IPʹࢀরͤ͞Δͷ΋ΞϦ͡Ό
  12. Case.2 ಈ࡞֬ೝ • Map Local • ϩʔΧϧͷϑΝΠϧΛࢀরͤ͞Δ • ྫ: https://hoge.jp/user/1


    ΁ͷϦΫΤετͷͱ͖͸
 /Users/kumamoto/user1.json
 Λฦ͢ ӈΫϦοΫϝχϡʔ͔Β Map Local Λબ୒
  13. Case.2 ಈ࡞֬ೝ • APIͷ୲౰ऀ͕ผͷ৔߹͸ɺ
 ରԠΛ଴ͨͣʹਐΊΒΕΔ • Մมͷ UILabel ͷදࣔ͸่Ε͕ͪ •

    վߦ͸ͨͩ͘͠͞Ε͍ͯΔ͔ʁ • ຤ඌ͸ʮ…ʯʹͳ͍ͬͯΔ͔ʁ • ࣗಈςετ΍UnitςετͳͲ
 Ͱ΋୲อͰ͖Δͱ˓ ίʔυϨϏϡʔ༻ͷΩϟϓνϟ
  14. ·ͱΊ • Charles Proxy ͷ঺հ • ͍Ζ͍Ζͳػೳ͕͋Δ • ΞϓϦ։ൃͰಛʹศརͳػೳ •

    ௨৴಺༰Λݟ΍͘͢දࣔ • ௨৴಺༰ͷࠩସ͑ • Map Local / Break Points / Rewrite • ҟৗܥ΍ɺUIͷදࣔ֬ೝʹศར
  15. SSL ϓϩΩγઃఆ • Enable SSL Proxying ʹνΣοΫ͕ೖ͍ͬͯΔ͜ͱΛ֬ೝ • Proxy >

    SSL Proxy Settings ͔Β༗ޮʹ͢ΔυϝΠϯΛઃఆʢ* Ͱશ෦ʣ
  16. ূ໌ॻΛొ࿥ • Help > SSL Proxying > Install Charles Root

    Certificate • ূ໌ॻΛʮৗʹ৴པʯ ݕࡧ૭Λ࢖͏ͱ͍͍͍ͧ
  17. iOS࣮ػͷઃఆ • ઃఆ > Wi-Fi > (઀ଓதͷSSID) > ϓϩΩγΛߏ੒ >

    खಈ • Charles ͷ IPΞυϨεͱϙʔτ(8888)ΛೖΕΔ IPΞυϨεΛௐ΂ͯiPhoneʹೖྗ͍ͨ͠ͱ͖͸ɺ ͯ͠ɺϢχόʔαϧΫϦοϓϘʔυ΁௥Ճ͢Δͱศར͡Ό ศརͳ͜ͱΛ ڭ͑ͯ͘ΕΔത࢜ • Charles ͷ Help > Local IP Address ϝχϡʔͰίϐʔ ifconfig΍MacͷWiFiϚʔΫΛopt+ΫϦοΫͰ΋OK
  18. iOS࣮ػͷઃఆ • Charles ʹܨ͍ͰΔঢ় ଶͰ Safari Ͱ https:// chls.pro/ssl ʹΞΫηε

    ͯ͠ূ໌ॻΛΠϯετʔ ϧ • Ұൠ > ৘ใ > ৴པॻઃ ఆ > Charles Proxy CA Λ Φϯ(iOS10.3ʙ)
  19. iOS Simulator ͷઃఆ • Help > SSL Proxying > Install

    Charles Root Certificate in iOS Simulator • iOS Simulator ͕͢Ͱʹ্ཱ͕͍ͪͬͯΔ৔߹͸ɺ
 Charles → iOS Simulator ͷॱʹ্ཱͪ͛௚͢
  20. EOP