How to bypass the Root Detection (debug android using JDWP) – Insecure Bank

บทนำ (Overview)

บทความนี้กล่าวถึงวิธี “Debug” บน “Android” โดยมีหลักการคือ เลือกหน้าจอหรือเป้าหมายที่จะต้องการเปลี่ยนแปลงใด ๆ หรือต้องการหาข้อมูล Sensitive จากตัวแปรใด ๆ (เราสามารถตัวแปรบางส่วนได้จาก Reverse engineering) จากนั้นสืบค้นหา “Class” และ “Method” ที่จะเกี่ยวข้อง จากนั้นทำการ “Debug” ที่ละขั้น ๆ จนพบจุดที่ต้องการ และทำการเปลี่ยนแปลงค่า หรือนำข้อมูลสำคัญไปใช้ เช่น Key สำหรับการทำ Encryption และ Decryption ต่าง ๆ จากบทความนี้จะทำการเปลี่ยนแปลงค่าให้โปรแกรมไม่สามารถตรวจสอบได้ว่าเครื่องที่นำมาติดตั้งได้ Root ไปแล้ว

ขั้นตอน (Steps)

  1. ติดตั้งโปรแกรมช่องโหว่ “Insecure Bank” (ติดตามได้ที่บทความ How to install InsecureBank)
  2. ทดลอง “Login” จะพบว่า โปรแกรมสามารถตรวจจับได้ว่าโปรแกรมได้ติดตั้งบนเครื่องที่โดน “Root” แล้ว android-debug-04
  3. ติดตั้งโปรแกรม Drozer (How to set Drozer)
  4. เรียกใช้ “Drozer console” ผ่าน Appie
    C:\Users\wsunpachit\Desktop
    $ adb devices
    List of devices attached
    127.0.0.1:26944 device
    
    C:\Users\wsunpachit\Desktop
    $ adb forward tcp:31415 tcp:31415
    
    C:\Users\wsunpachit\Desktop
    $ drozer console connect
    
  5. ตรวจสอบรายชื่อ “Package” โดยใช้คำสั่ง “run app.package.list”
    dz> run app.package.list -f insecure
    com.android.insecurebankv2 (InsecureBankv2)
    
  6. ใช้คำสั่งเปิดโปรแกรม “Insecure Bank” และ ใช้คำสั่ง “adb jdwp” เพื่อตรวจสอบหมายเลข “Process”
    adb jdwp
    

    android-debug-01

  7. แล้วใช้คำสั่งตามข้างล่างเพื่อตรวจสอบหมายเลขข้างล่าง มีชื่อเดียวกับ “Package” ที่เราได้ค้นหาหรือไม่
    C:\Users\wsunpachit\Desktop
    $ adb shell ps | grep "3428\|3305\|3289"
    u0_a39    3289  149   913912 44272 ffffffff b7580a27 S com.android.insecurebankv2
    u0_a13    3305  149   902104 32312 ffffffff b7580a27 S com.android.inputmethod.latin
    
  8. จากตัวอย่างข้างต้นพบว่า “Insecureฺ Bank” คือหมายเลข “3289”  เราจะเชื่อมต่อ “Process” ดังกล่าวโดยใชคำสั่งดังนี้
    C:\Users\wsunpachit\Desktop
    $ adb forward tcp:54321 jdwp:3289
    
    C:\Users\wsunpachit\Desktop
    $ jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=54321
    Set uncaught java.lang.Throwable
    Set deferred uncaught java.lang.Throwable
    Initializing jdb ...
    >
    
  9. ตอนนี้เราพร้อมที่จะ “Debug” โปรแกรม “Insecure Bank” กันแล้ว แต่เราจะต้องทราบชื่อ “Class” เสียก่อน เราสามารถดึงชื่อ “Class” ได้จากคำสั่ง
    classes
    

    android-debug-02

  10. แต่จะเห็นได้ว่า “list” รายชื่อ “Class” อาจยาวเกินไป เราอาจใช้วิธีการ How to reverse engineer .apk – Insecure Bank เพื่อตรวจสอบร่วมกันไปได้ android-debug-03
  11. จาก “Class” ที่ตรวจสอบเรา ทำให้เราสามารถทราบ “Method” ของ “Class” โดยใช้คำสั่งดังนี้
    methods com.android.insecurebankv2.PostLogin
    methods com.android.insecurebankv2.PostLogin$1
    

    android-debug-06

  12. แต่เราสามารถใช้ “Source-code” ที่เรา “Convert” มาในการตรวจสอบ “Method” ได้เช่นกัน android-debug-05
  13. จากตัวอย่างเราสนใจเกี่ยวกับการ “Root Device Detection” พบว่ามี Method ที่น่าสนใจคือ “showRootStatus()”  เราจะทดลอง “Debug” กัน โดยการให้โปรแกรมหยุด หรือ “Set breakpoint” เมื่อมีการเรียกใช้ “Method” ดังกล่าว
    > stop in com.android.insecurebankv2.PostLogin.showRootStatus()
    Set breakpoint com.android.insecurebankv2.PostLogin.showRootStatus()
    >
    
  14. ให้ไปที่โปรแกรม “Insecure Bank” จากนั้น “Login” android-debug-07
  15. กลับที่ไป “Debug” จะพบ “Console” ดังนี้
    Breakpoint hit: "thread=<1> main", com.android.insecurebankv2.PostLogin.showRootStatus(), line=86 bci=1
    > main[1]
    
  16. ใช้คำสั่ง “local” เพื่อตรวจสอบตรวจแปลใน “Break Point” นั้น และใช้คำสั่ง “next” หรือ “step” สำหรับ “Debug” ในคำสั่งถัดไป (next instruction) android-debug-08
  17. เราพบตัวแปร “isrooted = true” จากขั้นตอนนี้เราสามารถเปลี่ยนค่าของตัวแปรได้ โดยใช้คำสั่ง “Set”
    > main[1] locals
    Method arguments:
    Local variables:
    isrooted = true
    > main[1] set isrooted = false
     isrooted = false = false
    
  18. จากนั้นใช้คำสั่ง “run” เพื่อให้โปรแกรม “run” จนเสร็จสิ้นandroid-debug-09

ใส่ความเห็น