[Game][AOS][FRIDA] frida-il2cpp-bridge

koo00·2022년 5월 20일
0

frida-il2cpp-bridge는 global-metadata.dat 파일 없이도 런타임 시 il2cpp 애플리케이션을 덤프, 추적 또는 하이재킹하는 frida 모듈이다.

유니티 게임을 분석할 때 도움을 많이 받을 수 있다.

https://github.com/vfsfitvnm/frida-il2cpp-bridge 에서 frida-il2cpp-bridge 에 대한 자세한 내용을 확인할 수 있다.

frida-compile 을 통해 해당 모듈을 설치하고 활용하는 방법에 대해 알아보자.

먼저 node.js 설치 후 환경 변수를 설정해준다.

이후 playground 라는 폴더를 하나 만들고 파워쉘에서 아래의 명령어 입력을 통해 모듈을 설치한다.

> npm install frida-compile
> npm install --save-dev frida-il2cpp-bridge

다음 package.json 파일의 내용을 변경시켜주고 tsconfig.json 파일을 하나 만들어서 내용을 추가해준다.

// package.json
{
  "name": "playground",
  "main": "index.ts",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "build": "frida-compile index.ts -o _.js -c",
    "watch": "frida-compile index.ts -o _.js -w",
    "attach": "frida -U -l _.js",
    "spawn": "frida -U -l _.js -f"

  },
  "devDependencies": {
    "@types/frida-gum": "^18.0.0",
    "@types/node": "^17.0.35",
    "frida-compile": "^10.2.5",
    "frida-il2cpp-bridge": "^0.7.13"
  }
}
// tsconfig.json
{
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "es2020"
    ],
    "experimentalDecorators": true,
    "module": "commonjs",
    "allowJs": true,
    "noEmit": true,
    "esModuleInterop": true,
    "strict": true
  }
}


이제 index.ts 파일을 하나 생성해서 스크립트를 작성해준다. 일단은 console.error 부분을 주석 처리해준다.

import "frida-il2cpp-bridge";

Il2Cpp.perform(() => {
	// code here
	// console.error('\n[!] Let\'s Koo00 !\n');
});


npm 으로 frida-compile 명령어를 실행시켜준다.

> npm install
> npm run build

명령어가 정상적으로 실행되면 _.js 파일이 떨어진다.

frida 를 사용할 수 있지만 npm 으로도 attach 또는 spawn 이 가능하다.

> npm run attach PID			# frida -U PID -l _.js
> npm run spawn PackageName		# frida -U -f PackageName -l _.js --no-pause


$1ApplicationName 으로 세팅해주고 아래의 명령어를 입력하면 해당 앱에 쉽게 spawn 이 가능하다.

> $1='blahblah'
> $ps=frida-ps -Uai | select-string $1; $ps=$ps.toString().Split(' ')[-1]; frida -U -f $ps -l _.js --no-pause


index.ts 파일이 실시간으로 업데이트될 때 실시간으로 반영하고 싶다면 아래의 명령어를 입력하면 된다.

> npm run watch

이제 https://github.com/vfsfitvnm/frida-il2cpp-bridge/wiki/Snippets 을 보고 쓸만한 코드를 정리하는 것으로 포스팅을 마무리하겠다.

import "frida-il2cpp-bridge";

console.error('\n[!] Let\'s Koo00 !\n');

Il2Cpp.perform(() => {
  	// 모든 dll 파일 덤프 > dump.cs 파일로 추출
	Il2Cpp.dump();
	
  	// Assembly-CSharp.dll 내 모든 함수 추적
  	Il2Cpp.trace()
    	  .assemblies(Il2Cpp.Domain.assembly("Assembly-CSharp"))
    	  .and()
    	  .attach("detailed");	// full or detail
  	
  	// Assembly-CSharp.dll 파일 내 특정 클래스의 메소드 추적
  	const CSharp = Il2Cpp.Domain.assembly("Assembly-CSharp").image;
    const Singleton = CSharp.class("Singleton`1");

    Il2Cpp.trace()
     	  .classes(Singleton)
  		  // 메소드 필터링, javascript 문법 사용 가능 (ex, toLowerCase, endsWith, etc.)
     	  .filterMethods(method => method.name.toLowerCase().includes("instance"))
     	  .and()
     	  .attach("detailed");

	// UnityEngine.CoreModule.dll 파일 내 특정 클래스의 메소드 추적
    const CoreModule = Il2Cpp.Domain.assembly("UnityEngine.CoreModule").image;
    const Component = CoreModule.class("UnityEngine.Component");

    Il2Cpp.trace()
    	  .classes(Component)
    	  .filterMethods(method => method.name.toLowerCase().endsWith("component"))
    	  .and()
    	  .attach("full");
});
profile
JFDI !

2개의 댓글

comment-user-thumbnail
2022년 5월 26일

네이버 포스팅 글부터 쭈욱 ~ 항상 좋은 자료 감사드립니다. 엄청난 도움이 되고 있습니다.~!!
이번에도 좋은 자료 감사드립니다~!

1개의 답글