ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [์•ˆ๋“œ๋กœ์ด๋“œ ๋ฆฌ๋ฒ„์‹ฑ] Firda, Frida-Server ๋ฅผ ์•ˆ๋“œ๋กœ์ด๋“œ์— ์„ค์น˜ํ•˜๊ธฐ
    SECURITY/Android Reversing 2022. 2. 24. 20:21

     

    Frida ๋Š” python ๊ธฐ๋ฐ˜์˜, JS Injection์„ ์ด์šฉํ•˜์—ฌ Windows, macOS, Linux, iOS, Android, and QNX ๊ธฐ๋ฐ˜์˜ ๋„ค์ดํ‹ฐ์•ฑ์— ๋Œ€ํ•ด ํ›„ํ‚น์ด ๊ฐ€๋Šฅํ•œ ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

     

    Frida ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Frida (ํ›„ํ‚น ์ฝ”๋“œ ์ž‘์„ฑ) ์™€ Frida-Server (Android ์—์„œ ์‹คํ–‰) ๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

    1) ๋””๋ฐ”์ด์Šค์—์„œ frida-server ์‹คํ–‰ 2) python ์œผ๋กœ ์ž‘์„ฑํ•œ hooking ์ฝ”๋“œ ์‹คํ–‰ ์˜ ๊ฐ„๋‹จํ•œ ๊ณผ์ •์œผ๋กœ Frida ๋กœ ํ›„ํ‚น์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

     

    ๊ทธ๋Ÿผ ์ด ๋‘˜์„ ์–ด๋–ป๊ฒŒ ์„ค์น˜ํ•˜๋Š”์ง€๋ฅผ ์•Œ์•„๋ณด๊ฒ ๋‹ค.

     

     

    Frida ์„ค์น˜

    ํ›„ํ‚น์„ ํ•˜๋ ค๋Š” PC ์—์„œ Frida ๋ฅผ ์„ค์น˜ํ•˜๊ณ  python ์œผ๋กœ ํ›„ํ‚น ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์„œ ์‹คํ–‰์‹œํ‚ค๋ฉด ๋œ๋‹ค.

    Frida ๋Š” pip ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

    $ pip install frida

     

     

     

    Frida-Server ๋ฅผ emulator ์— ์„ค์น˜

    frida-server ๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์€ ๊ฝค๋‚˜ ๊ณผ์ •์ด ๋ณต์žกํ•˜๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ž์‹ ์˜ ํ™˜๊ฒฝ์— ํ•„์š”ํ•œ ์ž‘์—…๋“ค์„ ์ž˜ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

     

    1. frida-server ํŒŒ์ผ ๋‹ค์šด

    Frida server ๋Š”, Frida Release ์— ๊ฐ€์„œ ๋Œ€์ƒ Android ์— ๋งž๋Š” ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์œผ๋ฉด ๋œ๋‹ค.

    Frida Release: github.com/frida/frida/releases

    ์ด ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„์„œ ์—๋ฎฌ๋ ˆ์ดํ„ฐ์— ์˜ฎ๊ฒจ์ค„ ๊ฒƒ์ด๋‹ค.

     

    ๋“ค์–ด๊ฐ€๋ณด๋ฉด release ์— ๋งŽ์€ ํŒŒ์ผ์ด ์žˆ๋‹ค. ๊ทธ ์ค‘ android ์—์„œ ์ž์‹ ์˜ ์—๋ฎฌ๋ ˆ์ดํ„ฐ์™€ ๋งž๋Š” ์นœ๊ตฌ๋ฅผ ์ฐพ์•„์•ผ ํ•œ๋‹ค.

     

     

    Android ์ •๋ณด๋Š” adb ๋กœ ์‰ฝ๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

    $ adb shell getprop | find "cpu" // windows
    $ adb shell getprop | grep cpu // unix

    ๋‚˜์˜ ๊ฒฝ์šฐ, x86 ์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.

     

     

    ๊ทธ๋ž˜์„œ frida-server ์ค‘ android-x86 ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•˜๋‹ค.

     

     

     

    2. frida-server ํŒŒ์ผ ์••์ถ• ํ’€๊ธฐ

    frida-server ๋Š” ๋””๋ฐ”์ด์Šค์—์„œ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋ฏ€๋กœ, adb ๋ฅผ ์‚ฌ์šฉํ•ด์„œ frida server ๋ฅผ emulator ์— ์˜ฌ๋ ค์ฃผ์–ด์•ผ ํ•œ๋‹ค.

    .xz ๋กœ ์••์ถ•๋œ ํŒŒ์ผ์„ ํ•ด์ œํ•˜๊ณ  (๋ณธ์ธ ์•Œ์ง‘ ์‚ฌ์šฉ) ์˜ฎ๊ธธ ๋•Œ ํŽธํ•˜๊ฒŒ frida-server ๋กœ ์ด๋ฆ„์„ ๋ฐ”๊ฟ”์ฃผ์—ˆ๋‹ค.

     

     

     

    3. adb ๋กœ frida-server ๋ฅผ emulator ๋กœ ์˜ฎ๊ธฐ๊ณ  ์‹คํ–‰ํ•˜๊ธฐ

    ์ด์ œ adb ๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž.

    ์ด๋•Œ, emulator ๋Š” ์‹คํ–‰์ค‘์ด์–ด์•ผ ํ•œ๋‹ค. (์•„๋‹ˆ๋ฉด adb ๊ฐ€ ์–ด๋–ค ๋””๋ฐ”์ด์Šค์— ํ•ด์•ผํ• ์ง€ ๋ชจ๋ฅธ๋‹ค.)

     

    ๊ทผ๋ฐ ํŒŒ์ผ ์˜ฎ๊ธฐ๊ณ  system ์— ๋„ฃ์œผ๋ ค๋ฉด su, ์ฆ‰ ๋ฃจํŠธ ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๋‹ค.

    ํ•˜์ง€๋งŒ ๋ณ„๋„๋กœ ๋ฃจํŒ…์„ ํ•˜์ง€ ์•Š์•„๋„, adb ๋ฅผ root ๋กœ ์‹คํ–‰์‹œ์ผœ์ฃผ๋ฉด ๋œ๋‹ค.

    ๋‚˜์˜ ๊ฒฝ์šฐ, emulator ๊ฐ€ root ๊ถŒํ•œ์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฑฐ๋ผ์„œ ์ƒˆ๋กœ ๊น”์•„์ฃผ์—ˆ๋‹ค. ๋‹ค์Œ ์ฐธ์กฐ

    https://stackoverflow.com/questions/43923996/adb-root-is-not-working-on-emulator-cannot-run-as-root-in-production-builds

     

    ADB root is not working on emulator (cannot run as root in production builds)

    I have just updated emulator 26.0.3, now I cannot run adb root command for new created emulator. the error shown is below: adbd cannot run as root in production builds I have killed and restart ...

    stackoverflow.com

    ๋˜๋Š” ๊ทธ๋ƒฅ adb shell ์—์„œ su ๋ฅผ ํ•˜๋ฉด root ๊ถŒํ•œ์œผ๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋˜๋ฐ, ๋‚˜์˜ ๊ฒฝ์šฐ ๋งŽ์€ ์‚ฝ์งˆ ๋์— ์œ„์™€ ๊ฐ™์€ ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ  ์ƒˆ๋กœ์šด ๋””๋ฐ”์ด์Šค๋ฅผ ์„ค์น˜ํ•ด์„œ root ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

     

     

    adb ๋ฅผ root ๊ถŒํ•œ์œผ๋กœ ๋‹ค์‹œ ์‹คํ–‰์‹œ์ผœ๋ณด๊ฒ ๋‹ค.

    $ adb root
    $ adb remount # ์œ„ ๋ช…๋ น์–ด ํ›„ restarting adbd as root ๊ฐ™์€ log ๊ฐ€ ๋œจ์ง€ ์•Š์€ ๊ฒฝ์šฐ
    $ adb shell
    :/ #

    (๋ณดํ†ต์€ adb root ๋ฅผ ํ•˜๋ฉด ์ž๋™์œผ๋กœ remount ๊ฐ€ ๋˜๋˜๋ฐ, ๋‚˜์˜ ๊ฒฝ์šฐ ์•„๋ฌด๋Ÿฐ ๋กœ๊ทธ๊ฐ€ ์•ˆ๋– ์„œ ์ง์ ‘ remount ๋ฅผ ํ•ด์ฃผ์—ˆ๋‹ค..)

     

    ๋ฃจํŠธ ๊ถŒํ•œ

     

    ์„ฑ๊ณต!

    adb shell ์„ ํ–ˆ์„ ๋•Œ # ๋กœ ๋˜๋ฉด ์„ฑ๊ณต์ด๋‹ค. ($ ๋Š” ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž, # ๋Š” ๋ฃจํŠธ)

     

    ๊ทธ๋ฆฌ๊ณ  adb ๋กœ frida-server ํŒŒ์ผ์„ ์˜ฎ๊ฒจ์ค€๋‹ค.

    adb push ๋กœ frida-server ํŒŒ์ผ์„ /data/local/tmp ํด๋”๋กœ ์˜ฎ๊ฒจ์ฃผ๋Š” ๊ฒƒ์„ ์‹คํ–‰ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

    ์ด๋•Œ tmp ํด๋”๋งŒ ์žˆ์–ด์„œ temp ๋ผ๊ณ  ํ•˜๋ฉด ์•ˆ๋  ์ˆ˜๋„ ์žˆ๋‹ค. ์ด๊ฒƒ ์—ญ์‹œ ๊ฐœ์ธ๋ณ„๋กœ ํ™•์ธ์ด ํ•„์š”ํ•˜๋‹ค.

    (์•„๋‹ˆ๋ฉด adb shell ์—์„œ ์›ํ•˜๋Š” ํด๋”๋ฅผ ๋งŒ๋“ค์–ด๋„ ๋œ๋‹ค)

    > adb push frida-server /data/local/tmp
    > adb shell
    # cd data/local/tmp
    # chmod 755 frida-server # // frida-server ํŒŒ์ผ์— ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ
    # ./frida-server & // background ๋กœ ์‹คํ–‰

     

     

    frida-server ๋ฅผ ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋กœ ์‹คํ–‰์‹œํ‚ค๊ณ , ํ”„๋กœ์„ธ์Šค๋ฅผ ํ™•์ธํ•˜๋‹ˆ ์ž˜ ๋™์ž‘ํ•˜๊ณ  ์žˆ์Œ์„ ํ™•์ธํ–ˆ๋‹ค!

     

     

    Frida ๋ฅผ ์ด์šฉํ•ด์„œ ํ›„ํ‚น ์‹ค์Šต์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ๋Š” ์˜ˆ์ œ๋“ค์ด ์žˆ๋‹ค.

    • UnCrackable: OWASP ์—์„œ ๋งŒ๋“  ์•ˆ๋“œ๋กœ์ด๋“œ ๋ฆฌ๋ฒ„์‹ฑ์„ ์œ„ํ•œ ์•ฑ
      github.com/OWASP/owasp-mstg/tree/master/Crackmes/Android
    • HousePlant2020 CTF ์•ˆ๋“œ๋กœ์ด๋“œ ๋ฆฌ๋ฒ„์‹ฑ ๋ฌธ์ œ
      ctftime.org/task/11358

     

    ๊ธฐํšŒ๊ฐ€ ๋˜๋ฉด ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค.

    ๋Œ“๊ธ€

Designed by Tistory.