반응형

frida ui dump를 뜨게 되면 탈옥 알림창 관련 ViewController를 알 수 있음

// UI Dump
var window = ObjC.classes.UIWindow.keyWindow();
var rootControl = window.rootViewController();

var ui = window.recursiveDescription().toString();
var control = rootControl['- _printHierarchy']().toString();

// 전체 UI 계층 출력하고 싶은 경우    
// console.log(ui); 

// 현재 화면에 보여지는 UIController를 알고 싶은 경우
console.log(control);  

 

 

DVIA_v2.JailbreakDetectionViewController 클래스의 모든 메서드 출력

// Find All Methods of a Specific Class
if (ObjC.available) {
  try {
      var className = "DVIA_v2.JailbreakDetectionViewController";    // 찾고 싶은 class 이름으로 변경
      var methods = ObjC.classes[className].$ownMethods;

      console.warn("\n[*] Started: Find All Methods of a class " + '"' + className + '"');
      
      for (var i = 0; i < methods.length; i++) {
          try { console.log("\x1b[32m"+methods[i] + "\x1b[0m"); }
          catch(err) { console.log("[!] Exception1: " + err.message); }
      }}
  catch(err) { console.log("[!] Exception2: " + err.message); } }

else { console.log("Objective-C Runtime is not available!"); }

console.warn("[*] Completed: Find All Methods of a Class " + '"' + className + '"');

 

 

Hopper Disassembler를 사용하여 binary 분석 진행

-[DVIA_v2.JailbreakDetectionViewController jailbreakTest2Tapped:] 로 접근하여 살펴보면

__T07DVIA_v232JailbreakDetectionViewControllerC20jailbreakTest2TappedyypF 로 브랜치 되고 있음

 

 

브랜치된 함수로 진입하여 살펴보면, selector로 "isJailbroken" 메서드를 호출

 

 

"isJailbroken" 메서드를 클릭하여 따라 들어가면 JailbreakDetection 클래스의 클래스 메서드임을 확인 가능

 

 

Pseudo Objective-C 코드로 변환하면 다음과 같음

 

 

return type이 boolean이므로 frida로 hooking하여 return값 관찰

// Hook Specific Methods of Specific Class
if (ObjC.available)
{
    try
    {
        //Your class name here
        var className = "JailbreakDetection";
        //Your function name here. 메서드 이름은 '+,-,띄어쓰기,:'을 정확하게 명시해줘야 함
        var funcName = "+ isJailbroken";
        var hook = ObjC.classes[className][funcName];
        Interceptor.attach(hook.implementation, {
            onEnter: function(args) {
                // args[0] is self
                // args[1] is selector (SEL "sendMessageWithText:")
                // args[2] holds the first function argument, an NSString
                console.warn("\n[+] Detected call to: " + className + " -> " + funcName);
                console.log("\t[*] \x1b[31mArgument Value:\x1b[0m \x1b[34m"+args[2] + "\x1b[0m");
                //your new argument value here
                // var newargval = ptr("0x0")
                // args[2] = newargval
                // console.log("\t[*] \x1b[31mNew Argument Value:\x1b[0m \x1b[34m" + args[2] + "\x1b[0m")
            },
            onLeave: function(retval) {
                //For viewing and manipulating arguments
                // console.log("\t[*] \x1b[31mType of return value:\x1b[0m \x1b[34m" + typeof retval + "\x1b[0m");
                console.log("\t[*] \x1b[31mOriginal Return Value:\x1b[0m \x1b[34m" + retval + "\x1b[0m");;
                //modify original return value
                // var newretval = ptr("0x0"); 
                // retval.replace(newretval); 
                // console.log("\t[*] \x1b[31mNew Return Value:\x1b[0m \x1b[34m" + retval + "\x1b[0m");
                console.warn("[-] Exiting")
            }
        });
    }
    catch(err)
    {
        console.log("[!] Exception2: " + err.message);
    }
}
else
{
    console.log("Objective-C Runtime is not available!");
}

 

 

위 Frida Code에서 다음 부분 주석 제거하여, Return 값을 0x1에서 0x0으로 변경

// var newretval = ptr("0x0"); 
// retval.replace(newretval); 
// console.log("\t[*] \x1b[31mNew Return Value:\x1b[0m \x1b[34m" + retval + "\x1b[0m");

 

 

반응형

'Information Security > iOS' 카테고리의 다른 글

DVIA-v2 Jailbreak Detection Test3  (0) 2020.07.14
Cycript(iOS 12.4)  (1) 2020.07.10
Frida iOS Method Trace  (1) 2020.07.09
Clutch(iOS 12.4)  (2) 2020.07.08
DVIA-v2 Jailbreak Detection Test1 Using LLDB  (0) 2020.06.27

+ Recent posts