[JAVA] 오픈소스 난독화 도구 JObf

HyeJin Jeon·2022년 4월 8일
1

난독화

목록 보기
3/3
post-thumbnail

오픈소스 난독화툴 중에 지원하는 기능이 많고 사용성이 좋아 추천한다.

official github

https://github.com/superblaubeere27/obfuscator

JObf 가 지원하는 난독화 기능

  • Flow Obfuscation
  • Line Number Removal
  • Number Obfuscation
  • [Unstable] Name Obfuscation (Classes, methods and fields) with custom dictionaries
  • Deobfuscator crasher
  • String Encryption
  • Inner Class Removal
  • HWID Locking
  • Invoke Dynamic
  • Reference Proxy
  • Member Shuffling & Hiding

난독화 샘플

적용 전

package com.test.package;
public class Test {

	private String str = "Hello world!";

	public Test() {
		super();
	}

	public void run() {
		System.out.println(str);
		for (int i = 0; i < 10; ++i) {
			System.out.println(i);
		}
	}
}

적용 후

public class Ill extends lIl {
	private static final int[] IlIIIIl;

	private static void IlIlll() {
		(IlIIIIl = new int[5])[0] = (-" ".length() & (-1 & 0xFFFC));
		Ill.IlIIIIl[1] = (-" ".length() & (-1 & 0xFFFB));
		Ill.IlIIIIl[2] = (-1 & 0xFFFE);
		Ill.IlIIIIl[3] = (-" ".length() & (0xFFFFFFFD & 0xFFFF));
		Ill.IlIIIIl[4] = (0xFFFFFFFA & 0xFFFF);
	}

	public Ill(final String lIllIlIIlllllll) {
		super(lIllIlIIlllllll);
	}

	public Ill(final int lIlIIlIIlllllll) {
		super(lIlIIlIIlllllll);
	}

	static {
		IlIlll();
		IllIIl = Ill.IlIIIIl[0];
		lllIIl = Ill.IlIIIIl[1];
		IIlIIl = Ill.IlIIIIl[2];
		lIlIIl = Ill.IlIIIIl[3];
		IIIlIl = Ill.IlIIIIl[4];
	}

	public Ill(final int llIllIIIlllllll, final String IllllIIIlllllll) {
		super(llIllIIIlllllll, IllllIIIlllllll);
	}
}

flow obfuscation, string encryption, name obfuscation, invoke dynamic 가 적용된 형상

기본적인 사용법은 github README 를 참고. 아래에는 README 에 기재되지 않은 주의사항을 작성하겠다.


NameObfuscation Excluded 작성

rule 간의 구분은 \n 으로 한다.

"NameObfuscation": {
  "Enabled": true,
  "Excluded classes": "com.test.exclude.package.**\ncom.test.ExcludeClass",
  "Excluded methods": "",
  "Excluded fields": ""
}

⚠ classpath 로드 문제

현재 1.9.3 버전까지 릴리즈 되어있지만, classpath 로드하는 과정에서 이슈가 있어 수정된 latest 버전을 사용해야한다.

관련 issue
https://github.com/superblaubeere27/obfuscator/issues/52
수정된 버전
https://jitpack.io/com/github/superblaubeere27/obfuscator/obfuscator-core/8fb0fc2e37/obfuscator-core-8fb0fc2e37.jar

⚠ 메서드/필드 exclusion 버그

문제 상황

클래스 내 특정 메서드/필드를 exclude 하는 룰이 적용되지 않는 버그가 있음.
com.test.ExcludedClass.someMethod, com.test.ExcludedClass.someField 추가시 someMethod와 someField는 name obfuscation에서 제외되어야 맞지만 제외되지 않음.

원인

소스 코드 확인 결과 compileExcludePattern 에서 . 문자를 / 문자로 변환하는데 isMethodExcludedisFieldExcluded 에서는 . 문자를 기준으로 method 명과 field 명을 구분하기 때문에 발생하는 문제

해결방안

https://github.com/superblaubeere27/obfuscator/pull/62#discussion_r368368509 가 해당 문제에 대해 언급하였으나 이후 업데이트 없음.

https://github.com/superblaubeere27/obfuscator/issues/139
이슈 등록함.

업데이트 전까지는 클래스 뒤에 ** 패턴을 추가해 클래스 내 필드/메서드를 전부 exclude 하는 방식으로 사용

"NameObfuscation": {
  "Enabled": true,
  "Excluded classes": "com.test.exclude.package.**\ncom.test.ExcludeClass",
  "Excluded methods": "com.test.ExcludeClass**",
  "Excluded fields": "com.test.ExcludeClass**"
}

그 외 난독화 도구 비교가 잘 되어있는 글
https://github.com/GenericException/SkidSuite/blob/master/obfuscation.md

profile
Backend Developer

0개의 댓글