Tutoriel Frida
Reading time: 8 minutes
tip
Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)
Apprenez et pratiquez le hacking Azure :
HackTricks Training Azure Red Team Expert (AzRTE)
Soutenir HackTricks
- Vérifiez les plans d'abonnement !
- Rejoignez le đŹ groupe Discord ou le groupe telegram ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PR au HackTricks et HackTricks Cloud dépÎts github.
Installation
Installer frida tools:
pip install frida-tools
pip install frida
Téléchargez et installez sur l'appareil Android le frida server (Download the latest release).
Commande en une seule ligne pour redémarrer adb en mode root, s'y connecter, téléverser frida-server, lui donner les permissions d'exécution et l'exécuter en arriÚre-plan :
adb root; adb connect localhost:6000; sleep 1; adb push frida-server /data/local/tmp/; adb shell "chmod 755 /data/local/tmp/frida-server"; adb shell "/data/local/tmp/frida-server &"
Vérifiez si cela fonctionne:
frida-ps -U #List packages and processes
frida-ps -U | grep -i <part_of_the_package_name> #Get all the package name
Frida server vs. Gadget (root vs. no-root)
Deux façons courantes d'instrumenter des apps Android avec Frida :
- Frida server (rooted devices): Transférer et exécuter un démon natif qui vous permet de vous attacher à n'importe quel processus.
- Frida Gadget (no root): Intégrer Frida en tant que bibliothÚque partagée dans l'APK et la charger automatiquement dans le processus cible.
Frida server (rooted)
# Download the matching frida-server binary for your device's arch
# https://github.com/frida/frida/releases
adb root
adb push frida-server-<ver>-android-<arch> /data/local/tmp/frida-server
adb shell chmod 755 /data/local/tmp/frida-server
adb shell /data/local/tmp/frida-server & # run at boot via init/magisk if desired
# From host, list processes and attach
frida-ps -Uai
frida -U -n com.example.app
Frida Gadget (no-root)
- Décompressez l'APK, ajoutez le gadget .so et la config :
- Placez libfrida-gadget.so dans lib/
/ (e.g., lib/arm64-v8a/) - Créez assets/frida-gadget.config avec vos script loading settings
Exemple frida-gadget.config
{
"interaction": { "type": "script", "path": "/sdcard/ssl-bypass.js" },
"runtime": { "logFile": "/sdcard/frida-gadget.log" }
}
- Référencez/chargez le gadget pour qu'il soit initialisé tÎt:
- Le plus simple : ajoutez un petit stub Java appelant System.loadLibrary("frida-gadget") dans Application.onCreate(), ou utilisez le chargement natif de librairie déjà présent.
- Réemballez et signez l'APK, puis installez:
apktool d app.apk -o app_m
# ... add gadget .so and config ...
apktool b app_m -o app_gadget.apk
uber-apk-signer -a app_gadget.apk -o out_signed
adb install -r out_signed/app_gadget-aligned-debugSigned.apk
- Attacher depuis l'hĂŽte au processus gadget :
frida-ps -Uai
frida -U -n com.example.app
Remarques
- Gadget est détecté par certaines protections ; laissez les noms/chemins discrets et chargez-le tardivement/conditionnellement si nécessaire.
- Sur les applications durcies, privilégiez des tests sur appareil rooté avec server + late attach, ou combinez avec le masquage Magisk/Zygisk.
Tutoriels
Tutorial 1
Source: https://medium.com/infosec-adventures/introduction-to-frida-5a3f51595ca1
APK: https://github.com/t0thkr1s/frida-demo/releases
Code source: https://github.com/t0thkr1s/frida-demo
Suivez le link to read it.
Tutorial 2
Source: https://11x256.github.io/Frida-hooking-android-part-2/ (Parts 2, 3 & 4)
APKs and Source code: https://github.com/11x256/frida-android-examples
Suivez le link to read it.
Tutorial 3
Source: https://joshspicer.com/android-frida-1
APK: https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk
Suivez le link to read it.
Vous pouvez trouver plus d'excellents scripts Frida ici : https://codeshare.frida.re/
Exemples rapides
Calling Frida from command line
frida-ps -U
#Basic frida hooking
frida -l disableRoot.js -f owasp.mstg.uncrackable1
#Hooking before starting the app
frida -U --no-pause -l disableRoot.js -f owasp.mstg.uncrackable1
#The --no-pause and -f options allow the app to be spawned automatically,
#frozen so that the instrumentation can occur, and the automatically
#continue execution with our modified code.
Script Python de base
import frida, sys
jscode = open(sys.argv[0]).read()
process = frida.get_usb_device().attach('infosecadventures.fridademo')
script = process.create_script(jscode)
print('[ * ] Running Frida Demo application')
script.load()
sys.stdin.read()
Hooking des fonctions sans paramĂštres
Hook la fonction a()
de la classe sg.vantagepoint.a.c
Java.perform(function () {
; rootcheck1.a.overload().implementation = function() {
rootcheck1.a.overload().implementation = function() {
send("sg.vantagepoint.a.c.a()Z Root check 1 HIT! su.exists()");
return false;
};
});
Hook java exit()
var sysexit = Java.use("java.lang.System")
sysexit.exit.overload("int").implementation = function (var_0) {
send("java.lang.System.exit(I)V // We avoid exiting the application :)")
}
Hook MainActivity .onStart()
& .onCreate()
var mainactivity = Java.use("sg.vantagepoint.uncrackable1.MainActivity")
mainactivity.onStart.overload().implementation = function () {
send("MainActivity.onStart() HIT!!!")
var ret = this.onStart.overload().call(this)
}
mainactivity.onCreate.overload("android.os.Bundle").implementation = function (
var_0
) {
send("MainActivity.onCreate() HIT!!!")
var ret = this.onCreate.overload("android.os.Bundle").call(this, var_0)
}
Hook android .onCreate()
var activity = Java.use("android.app.Activity")
activity.onCreate.overload("android.os.Bundle").implementation = function (
var_0
) {
send("Activity HIT!!!")
var ret = this.onCreate.overload("android.os.Bundle").call(this, var_0)
}
Hooking de fonctions avec paramÚtres et récupération de la valeur
Hooking d'une fonction de déchiffrement. Affichez l'entrée, appelez la fonction originale pour déchiffrer l'entrée et enfin, affichez les données en clair:
function getString(data) {
var ret = ""
for (var i = 0; i < data.length; i++) {
ret += data[i].toString()
}
return ret
}
var aes_decrypt = Java.use("sg.vantagepoint.a.a")
aes_decrypt.a.overload("[B", "[B").implementation = function (var_0, var_1) {
send("sg.vantagepoint.a.a.a([B[B)[B doFinal(enc) // AES/ECB/PKCS7Padding")
send("Key : " + getString(var_0))
send("Encrypted : " + getString(var_1))
var ret = this.a.overload("[B", "[B").call(this, var_0, var_1)
send("Decrypted : " + ret)
var flag = ""
for (var i = 0; i < ret.length; i++) {
flag += String.fromCharCode(ret[i])
}
send("Decrypted flag: " + flag)
return ret //[B
}
Hooking functions et les appeler avec notre input
Hook a function qui reçoit un string et l'appeler avec un autre string (d'aprÚs here)
var string_class = Java.use("java.lang.String") // get a JS wrapper for java's String class
my_class.fun.overload("java.lang.String").implementation = function (x) {
//hooking the new function
var my_string = string_class.$new("My TeSt String#####") //creating a new String by using `new` operator
console.log("Original arg: " + x)
var ret = this.fun(my_string) // calling the original function with the new String, and putting its return value in ret variable
console.log("Return value: " + ret)
return ret
}
Récupérer un objet déjà créé d'une classe
Si vous voulez extraire un attribut d'un objet déjà créé, vous pouvez utiliser ceci.
Dans cet exemple, vous allez voir comment récupérer l'objet de la classe my_activity et comment appeler la fonction .secret() qui affichera un attribut privé de l'objet :
Java.choose("com.example.a11x256.frida_test.my_activity", {
onMatch: function (instance) {
//This function will be called for every instance found by frida
console.log("Found instance: " + instance)
console.log("Result of secret func: " + instance.secret())
},
onComplete: function () {},
})
Autres tutoriels Frida
- https://github.com/DERE-ad2001/Frida-Labs
- Partie 1 de la série de blogs "Advanced Frida Usage" : bibliothÚques de chiffrement iOS
Références
- Construire un laboratoire Android Bug Bounty reproductible : Emulator vs Magisk, Burp, Frida, et Medusa
- Documentation de Frida Gadget
- Frida releases (binaires serveur)
tip
Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)
Apprenez et pratiquez le hacking Azure :
HackTricks Training Azure Red Team Expert (AzRTE)
Soutenir HackTricks
- Vérifiez les plans d'abonnement !
- Rejoignez le đŹ groupe Discord ou le groupe telegram ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des astuces de hacking en soumettant des PR au HackTricks et HackTricks Cloud dépÎts github.