본문 바로가기
HACKING/mobile_IOS

iOS setting for Pentesting#1 jailbreak, frida

by asdf12345 2020. 6. 10.

1. jailbreak

환경 

iOS version :  9.3.2

3utool 도구를 이용하여 탈옥하자! 

jailbreak iOS through 3utools

 

다운로드 경로

http://www.3u.com/

 

 

iOS 내 파일 접근을 위해, 3utools를 통해서 AFC tweak 설치

For accessing to files, I have to install AFC through 3utools

http://www.3u.com/tutorial/articles/how-to-install-appsync-afc2-service

 

 

2. Frida Setting

0)편리한 원격 명령 전달을 위해, Cydia(3utool를이용해서 탈옥 시, 설치되는 Application)을 통해서 Open SSH tweak을 설치한다. 컴퓨터에서 pip install frida-tools, pip install frida명령어를 입력하여 frida client 설정을 완료한다.

0) After install Open ssh through Cydia, and input commnad for frida on the computer

 

 

1) 3utools를 통해 SSH Tunnel을 열고, terminal access user명, 비밀번호 획득

1) open SSH Tunnel though 3utools & Get information to get teminal access

 

 

2) iOS를 위해 frida-server를 다운로드하고, 3utools를 통해 frida-server file을 다운로드

2) Download frida-server for iOS & Input frida-server file through 3utools

 

 

3) Xshell 프로그램을 이용해 컴퓨터에서 원격으로 frida-server 실행

컴퓨터 cmd를 통해 frida-ps 명령어를 통해 연결 확인 

3) remote Run frida-server on window by using Xshell or putty

& After setting frida on window, Check the connect on window through frida-ps

 

 

연결시, 결과를 확인 가능

then, we can check the result

 

 

앱 실행 시부터 frida 코드 hooking을 진행하고 싶다면, frida.get_usb_device().spawn("package_name")을 이용한 후, 후킹 코드 전달 명령어 작성 필요 

If you want to spawn an app on iOS by using python, you can use functions which is frida.get_usb_device().spawn("package_name").

한국어 인코딩방식 대신 -Uai 옵션을 이용한 Identifier결과를 통해 쉽게 spawn가능

You can check package_name with this command. 

 

 

 

파일 관련 API 후킹 코드 

python & frida Code

#!/usr/local/bin/python3
#-*- coding:utf-8 -*-

import sys
import os
import base64
import frida
def on_message(message, data):
    try:
        if message:
            print("[LOG] {0}".format(message["payload"]))
    except Exception as e:
        print(message)
        print(e)
 

def main():
    host = frida.get_usb_device()
    package_name=""
    pid=host.spawn([package_name])
    session = host.attach(pid)
    host.resume(pid)
    script = session.create_script('''

    var hooked_method=ObjC.classes.NSData["- writeToFile:atomically:"];
    Interceptor.attach(hooked_method.implementation, {
        onEnter: function(args) {
            console.log("[+] NSData - writeToFile:atomically ARG[0]");
            var data = new ObjC.Object(args[0]);
            var buffer = Memory.readByteArray(data.bytes(), data.length());
	        console.log(hexdump(buffer));
        }
    });

    Interceptor.attach(Module.findExportByName("dyld", "_NSGetExecutablePath"), {
        onLeave: function(retVal) {
            console.log("[+] _NSGetExecutablePath onLeave");
            var path1 = retVal.readUtf8String();
            console.log("   _NSGetExecutablePath RETURN VALUE : " + path1);
        }
    });
    
    Interceptor.attach(Module.findExportByName(null, "fopen"), {
        onEnter: function(args) {
            if (args[0].isNull()) return;
            var path = args[0].readUtf8String();
            console.log("[+] fopen ARG[0] : " + path);
        }
    });

    Interceptor.attach(Module.findExportByName(null, "realpath$DARWIN_EXTSN"), {
        onEnter: function(args) {
            if (args[0].isNull()) return;
            var path = args[0].readUtf8String();
            console.log("[+] realpath$DARWIN_EXTSN ARG[0] : " + path);
        },
        onLeave: function(retVal) {
            var path =retVal.readUtf8String();
            console.log("[+] realpath$DARWIN_EXTSN RETURN VALUE : " + path);
            if(path.match("")){
                console.log("Change It!!");
                retVal.writeUtf8String("");
            }
            console.log("[+] Change PATH : "+retVal.readUtf8String());
            return retVal;
        }
    });

    Interceptor.attach(Module.findExportByName(null, "open"), {
        onEnter: function(args) {
            if (args[0].isNull()) return;
            var path = Memory.readUtf8String(args[0]);
            console.log("[+] open ARG[0] : " + path);
        }
    })

    ''')
    script.on('message', on_message)
    script.load()
    sys.stdin.read()



        
if __name__ == '__main__':
    main()

 

주의

iOS 환경에서 최고권한(root)를 얻은 후의 이점으로는 인가되지 않은 앱 설치, 환경설정 커스터마이징 등이 가능하다. 이를 위해 Setting(jailbreak, 플랫폼 해킹)을 했다고 가정하자. 금융권 앱을 설치하고자 했으나, 기업과 국가가 마련한 보안방지 기법들로 인해 앱 실행이 불가하다. 그러므로 인터넷에서 돌아다니는 "jailbreak bypass" 문자열과 함께 업로드된 third-party App을 설치를 한다. 기존 앱과 화면, 문구 모든게 일치하지만 jailbreak는 우회 가능하다. 아이디, 비밀번호를 입력 한다. 해당 정보는 블랙해커에게로 전송된다. 

 jailbreak 우회가 가능하다는 말은, 앱에 jailbreak 탐지 로직이 변경됐다는 말이며, 이는 앱의 모든 정보를 조작 가능한다는 말과 동일하다. 내가 보낼 정보의 URL이 다른 URL로 변경될수도, 내가 전송할 돈의 계좌가 다른 계좌로 전송될수도 있다.