Frida Tutorial 1

Support HackTricks

Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $100,000!

This is a summary of the post: https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1 APK: https://github.com/t0thkr1s/frida-demo/releases Source Code: https://github.com/t0thkr1s/frida-demo

Python

Frida는 실행 중인 애플리케이션의 함수 내에 JavaScript 코드삽입할 수 있게 해줍니다. 하지만 python을 사용하여 hooks호출하고 hooks상호작용할 수 있습니다.

이것은 이 튜토리얼의 모든 제안된 예제와 함께 사용할 수 있는 간단한 python 스크립트입니다:

#hooking.py
import frida, sys

with open(sys.argv[1], 'r') as f:
jscode = f.read()
process = frida.get_usb_device().attach('infosecadventures.fridademo')
script = process.create_script(jscode)
print('[ * ] Running Frida Demo application')
script.load()
sys.stdin.read()

스크립트를 호출하세요:

python hooking.py <hookN.js>

python을 frida와 함께 사용하는 방법을 아는 것은 유용하지만, 이 예제에서는 명령줄 frida 도구를 사용하여 직접 Frida를 호출할 수도 있습니다:

frida -U --no-pause -l hookN.js -f infosecadventures.fridademo

Hook 1 - Boolean Bypass

여기에서 클래스 _infosecadventures.fridademo.utils.PinUtil_의 boolean 메서드 (checkPin)를 hook하는 방법을 볼 수 있습니다.

//hook1.js
Java.perform(function() {
console.log("[ * ] Starting implementation override...")
var MainActivity = Java.use("infosecadventures.fridademo.utils.PinUtil");
MainActivity.checkPin.implementation = function(pin){
console.log("[ + ] PIN check successfully bypassed!")
return true;
}
});
python hooking.py hook1.js

보세요: 함수는 매개변수로 String을 받습니다. 오버로드가 필요하지 않나요?

Hook 2 - Function Bruteforce

비정적 함수

클래스의 비정적 함수를 호출하려면 먼저 해당 클래스의 인스턴스가 필요합니다. 그런 다음, 그 인스턴스를 사용하여 함수를 호출할 수 있습니다. 이를 위해 기존 인스턴스를 찾아서 사용할 수 있습니다:

Java.perform(function() {
console.log("[ * ] Starting PIN Brute-force, please wait...");
Java.choose("infosecadventures.fridademo.utils.PinUtil", {
onMatch: function(instance) {
console.log("[ * ] Instance found in memory: " + instance);
for(var i = 1000; i < 9999; i++){
if(instance.checkPin(i + "") == true){
console.log("[ + ] Found correct PIN: " + i);
break;
}
}
},
onComplete: function() { }
});
});

이 경우 인스턴스가 없고 함수가 정적이기 때문에 작동하지 않습니다.

정적 함수

함수가 정적이라면, 그냥 호출할 수 있습니다:

//hook2.js
Java.perform(function () {
console.log("[ * ] Starting PIN Brute-force, please wait...")
var PinUtil = Java.use("infosecadventures.fridademo.utils.PinUtil");

for(var i=1000; i < 9999; i++)
{
if(PinUtil.checkPin(i+"") == true){
console.log("[ + ] Found correct PIN: " + i);
}
}
});

Hook 3 - 인수 및 반환 값 가져오기

함수를 후킹하여 전달된 인수의 값과 반환 값의 값을 출력하도록 만들 수 있습니다:

//hook3.js
Java.perform(function() {
console.log("[ * ] Starting implementation override...")

var EncryptionUtil = Java.use("infosecadventures.fridademo.utils.EncryptionUtil");
EncryptionUtil.encrypt.implementation = function(key, value){
console.log("Key: " + key);
console.log("Value: " + value);
var encrypted_ret = this.encrypt(key, value); //Call the original function
console.log("Encrypted value: " + encrypted_ret);
return encrypted_ret;
}
});

중요

이 튜토리얼에서는 메서드 이름과 _.implementation_을 사용하여 메서드를 후킹했습니다. 그러나 같은 이름을 가진 메서드가 여러 개 있을 경우, 인수의 유형을 지정하여 후킹할 메서드를 명시해야 합니다.

다음 튜토리얼에서 확인할 수 있습니다 the next tutorial.

버그 바운티 팁: 해커를 위해 해커가 만든 프리미엄 버그 바운티 플랫폼인 Intigriti가입하세요! 오늘 https://go.intigriti.com/hacktricks에서 저희와 함께하고 최대 $100,000의 보상을 받기 시작하세요!

HackTricks 지원하기

Last updated