프리다란 Ole가 개발한 DBI 프레임워크로서 앱이 실행 중인 상태에서 코드 명령어를 삽입해 프로세스를 추적, 분석, 디버깅하는 도구이다.
Ross Marks가 개발한 안드로이드 앱으로 Frida를 연습할 수 있는 앱 어플리케이션이다.
1번부터 8번까지의 챌린지 문제가 제공된다.
chall01 변수 값을 1로 변경해야 한다.
APK 파일을 jadx-gui로 디컴파일 결과, chall01 변수가 존재한다.
chall01 변수를 getChall01Int 함수가 리턴한다.
프리다를 사용해 함수의 리턴 값을 변경하거나 변수 값을 변경하면 문제를 풀 수 있다.
우선 chall01 변수 값을 1로 변경하는 프리다 코드이다.
import frida
import sys
jscode = """
setImmediate(() => {
Java.perform(function() {
var challenge01 = Java.use("uk.rossmarks.fridalab.challenge_01");
challenge01.chall01.value = 1; // chall01 값을 1로 변경함
console.log("chall01.value set to 1");
});
});
"""
process = frida.get_usb_device().attach("FridaLab")
script = process.create_script(jscode)
script.load()
sys.stdin.read()
파이썬 코드 실행 결과, chall01 변수 값이 1로 변경되어 1번 문제에 초록불이 들어왔다.
이번에는 getChall01Int 메서드를 오버라이딩 즉, 재정의하는 코드로 문제를 풀어보겠다.
import frida
import sys
jscode = """
setImmediate(() => {
Java.perform(function() {
var challenge01 = Java.use("uk.rossmarks.fridalab.challenge_01"); challenge01.getChall01Int.implementation = function() {
console.log("getChall01Int return to 1");
return 1; // chall01 변수 대신 1을 리턴하는 코드로 오버라이딩
}
});
});
"""
process = frida.get_usb_device().attach("FridaLab")
script = process.create_script(jscode)
script.load()
sys.stdin.read()
위 코드에서 getChall01Int 메서드를 implementation
으로 리턴하는 값을 chall01에서 1로 오버라이딩했다.
challenge01.getChall01Int.implementation = function() {
console.log("getChall01Int return to 1");
return 1;
}
파이썬 코드 실행 결과, 1을 리턴해 문제가 해결되었다.