Cycript 도구

경로 및 정보 2022. 10. 11. 23:55

https://iphonedevwiki.net/index.php/Cycript_Tricks

 

Cycript Tricks - iPhone Development Wiki

Getting objects Objective-C objects using choose() The function choose(), introduced in version 0.9.502[citation needed] and documented here, allows us to get an array of existing objects of a certain class. Objective-C objects from addresses Use #0xdeadba

iphonedevwiki.net

https://bachs.tistory.com/entry/iOS-Hooking3Cycript

 

iOS Hooking#3(Cycript)

1. Cycript Cycript는 iOS에서 실행되고 있는 애플리케이션을 동적으로 수정하고 분석을 할 수 있게 해주는 SDK이다. 문법은 기본적으로 Objective-C / JavaScript를 혼합하여 사용 가능하다. 2. Cycript Hooking..

bachs.tistory.com

https://hackcatml.tistory.com/52

 

Cycript(iOS 12.4)

cyrun을 이용하면 ios 12에서도 cycript 사용이 가능. - Cycript 및 Cyrun 설치 및 구동 wget http://apt.saurik.com/debs/cycript_0.9.594_iphoneos-arm.deb wget http://www.tateu.net/repo/files/net.tateu.cyc..

hackcatml.tistory.com

 

 

1. Cycript

Cycript는 iOS에서 실행되고 있는 애플리케이션을 동적으로 수정하고 분석을 할 수 있게 해주는 SDK이다.문법은 기본적으로 Objective-C / JavaScript를 혼합하여 사용 가능하다. 

2. Cycript Hooking

 

2-1) view계층 확인하기

ex) UIApp.keyWindow.recursiveDescription()

 

view의 계층을 출력하여준다. NSLog로 출력하여 큰 화면으로 보면 아래와 같이 이쁘게 보인다.

 

 

2-2) subviews()

ex) UIApp.keyWindow.subviews()[index]

 

window는 하나 이상의 view를 가지며, view 역시 하나 이상의 view의 집합이다. 각 하위 view들의 접근은 subviews()[index]의 형태로 접근 가능하고, 2-1에서 확인한 계층을 참조하여 각 요소들을 찾을 수 있다.

 

 

2-3) _viewDelegate()

ex) UIApp.keyWindow.subviews()[2].subviews()[0]._viewDelegate()

 

_viewDelegate를 이용하여 해당 view의 controller에 접근 가능하다.

 

2-4) replacing existing objective-C methods

ex) Game2ViewController.prototype['recognizeAnswer'] 

= function() { NSLog(@"[JSACH]HOOKED"); return 1;}

 
target ViewController를 찾아 prototype배열에 후킹할 method에 접근하여 위와 같이 재정의해줌으로써 replacing가능함

 

 

참고) Cycript에서 사용하는 API나 문법, Trick들이 정리되어있는 링크

 

 - iOS Tricks

     http://iphonedevwiki.net/index.php/Cycript_Tricks

 

 - Cycript공식 홈페이지

http://www.cycript.org/

 

참고로 이 글은 Cycript 0.9.594버전을 기준으로 작성을 하였다.

 

 

3. 결과

 

3-1) 메서드 재정의

 

1
Game2ViewController.prototype['recognizeAnswer'= function() { NSLog(@"[JSBACH]HOOKED"); NSLog(@"[JSBACH] return SUCCESSED"); return 1;}
 

 

 

 

3-2) 메서드 후킹 로그

 

3-3) 후킹 성공 결과

 

 

------------------

 

cyrun을 이용하면 ios 12에서도 cycript 사용이 가능.

 

- Cycript 및 Cyrun 설치 및 구동

wget http://apt.saurik.com/debs/cycript_0.9.594_iphoneos-arm.deb

wget http://www.tateu.net/repo/files/net.tateu.cycriptlistenertweak_1.0.0_iphoneos-arm.deb

wget http://www.tateu.net/repo/files/net.tateu.cyrun_1.0.5_iphoneos-arm.deb

dpkg -i cycript_0.9.594_iphoneos-arm.deb

dpkg -i net.tateu.cycriptlistenertweak_1.0.0_iphoneos-arm.deb net.tateu.cyrun_1.0.5_iphoneos-arm.deb

 

cyrun -n <AppName on home icon> -e -d 또는

cyrun -b <AppBundleID> -e -d

 

- Bundle ID, Bundle DisplayName, Bundle ExecutableName 확인

NSBundle.mainBundle.infoDictionary.allKeys()

NSBundle.mainBundle.infoDictionary.CFBundleName

NSBundle.mainBundle.infoDictionary.CFBundleIdentifier

NSBundle.mainBundle.infoDictionary.CFBundleDisplayName

 

 

- View 계층 확인

UIApp.keyWindow.rootViewController    // root view controller 확인

UIApp.keyWindow.rootViewController._printHierachy().toString()

UIApp.keyWindow.recursiveDescription().toString()

UIApp.keyWindow._autolayoutTrace.toString()    // simplified recursiveDescription

 

 

- subviews 확인

UIApp.keyWindow.subviews()    // keyWindow의 subviews 확인. 아래 예시는 #으로 구분되는 2개의 subviews를 가지고 있음

#주소.subviews()    // 특정 주소값을 가지는 view의 subviews 확인. 아래 예시는 #으로 구분되는 1개의 subview를 가지고 있음

UIApp.keyWindow.subvies()[index]._viewDelegate()    // 해당 뷰를 담당하는 controller 출력. 아래 예시는 keyWindow의 첫번째 subview를 담당하는 controller가 UIApplicationRotationFollowingController 임을 나타냄.

 

 

- 상태표시줄 숨기기 / 표시하기(안되는 경우가 많음)

[[UIApplication SharedApplication] setStatusBarHidden:YES]

[[UIApplication SharedApplication] setStatusBarHidden:NO]

 

 

- 아이콘 badge number 조작(안되는 경우가 많음)

var a = [UIApplication sharedApplication]

[a setApplicationIconBadgeNumber:100];

 

 

- Print Methods

(1) printMethods 함수 만들어서 수행

// Usage:
// for InstanceMethods: printMethods('className')
// for ClassMethods: printMethods('className', true)
function printMethods(className, isa) {
  var count = new new Type("I");
  var classObj = (isa != undefined) ? objc_getClass(className)->isa :
  objc_getClass(className);
  var methods = class_copyMethodList(classObj, count);
  var methodsArray = [];
  for(var i = 0; i < *count; i++) {
  var method = methods[i];
  methodsArray.push({selector:method_getName(method),
  implementation:method_getImplementation(method)});
  }
  free(methods);
  return methodsArray;
}

==> 실행결과(DVIA-v2 앱에 대해서 test)

출력된 결과는 보기 힘드니, Online Javascript Beautifier를 활용(ex.  https://beautifier.io/).

 

(2) _methodDescription() 메서드 활용

UIApp.keyWindow.rootViewController._printHierachy() 명령어로 뷰 계층 확인 후 관심 클래스의 주소값에 대하여 다음 명령어 수행

#<주소값>._methodDescription().toString()    // 이 방법의 경우 알고자 하는 클래스의 method 뿐만 아니라 다른 클래스의 메서드들도 출력해주다보니 쓸모없는 정보들이 너무 많이 출력됨

 

 

- Print Current ViewController

function currentVC() {
  var app = [UIApplication sharedApplication]
  var keyWindow = app.keyWindow
  var rootController = keyWindow.rootViewController
  var visibleController = rootController.visibleViewController
  if (!visibleController){
  return rootController
  }
  return visibleController.childViewControllers[0]
}

==> 실행결과

 

※ 출처

https://bachs.tistory.com/entry/iOS-Hooking3Cycript

https://sevencho.github.io/archives/c12f47b1.html

https://gist.github.com/laprasdrum/667213ab364ef2536a30f3bdb79c77bb

http://nullgirl.com/blog/2018/03/20/iOS%E9%80%86%E5%90%91%E4%B8%8E%E5%AE%89%E5%85%A8-Cycript%E8%84%9A%E6%9C%AC%E4%BD%BF%E7%94%A8/

https://ileeyj.tistory.com/257

 

 

'경로 및 정보' 카테고리의 다른 글

DNS Cache Poisoning 공격  (0) 2022.10.14
chromium-browser  (0) 2022.10.12
Docker 2375/2376  (0) 2022.10.07
jenkins RCE  (0) 2022.10.07
Cisco Smart Install Client 취약점  (0) 2022.10.06
블로그 이미지

wtdsoul

,