Koraci za instalaciju Frida na Jailbroken uređaju:
Otvorite Cydia/Sileo aplikaciju.
Idite na Manage -> Sources -> Edit -> Add.
Unesite "https://build.frida.re" kao URL.
Idite na novo dodati Frida izvor.
Instalirajte Frida paket.
Ako koristite Corellium, potrebno je da preuzmete Frida verziju sa https://github.com/frida/frida/releases (frida-gadget-[yourversion]-ios-universal.dylib.gz) i raspakujete i kopirate na dylib lokaciju koju Frida traži, npr.: /Users/[youruser]/.cache/frida/gadget-ios.dylib
Nakon instalacije, možete koristiti na vašem PC-u komandu frida-ls-devices i proveriti da li se uređaj pojavljuje (vaš PC treba da može da mu pristupi).
Izvršite takođe frida-ps -Uia da proverite pokrenute procese telefona.
Frida bez Jailbroken uređaja & bez patchovanja aplikacije
Sa instaliranim Frida serverom i uređajem koji radi i je povezan, proverite da li klijent radi:
frida-ls-devices# List devicesfrida-ps-Uia# Get running processes
Frida Trace
# Functions## Trace all functions with the word "log" in their namefrida-trace-U<program>-i"*log*"frida-trace-U<program>-i"*log*"|swiftdemangle# Demangle names# Objective-C## Trace all methods of all classesfrida-trace-U<program>-m"*[* *]"## Trace all methods with the word "authentication" from classes that start with "NE"frida-trace-U<program>-m"*[NE* *authentication*]"# Plug-In## To hook a plugin that is momentarely executed prepare Frida indicating the ID of the Plugin binaryfrida-trace-U-W<if-plugin-bin>-m'*[* *]'
Dobijte sve klase i metode
Automatsko dovršavanje: Samo izvršite frida -U <program>
Dobijte sve dostupne klase (filtrirajte po stringu)
// frida -U <program> -l /tmp/script.jsvar specificClass ="YourClassName";var filterMethod ="filtermethod";if (ObjC.available) {if (ObjC.classes.hasOwnProperty(specificClass)) {var methods =ObjC.classes[specificClass].$ownMethods;for (var i =0; i <methods.length; i++) {if (!filterMethod || methods[i].includes(filterClass)) {console.log(specificClass +': '+ methods[i]);}}} else {console.log("Class not found.");}} else {console.log("Objective-C runtime is not available.");}
Pozovite funkciju
// Find the address of the function to callconstfunc_addr=Module.findExportByName("<Prog Name>","<Func Name>");// Declare the function to callconstfunc=newNativeFunction(func_addr,"void", ["pointer","pointer","pointer"], {});var arg0 =null;// In this case to call this function we need to intercept a call to it to copy arg0Interceptor.attach(wg_log_addr, {onEnter:function(args) {arg0 =newNativePointer(args[0]);}});// Wait untill a call to the func occurswhile (! arg0) {Thread.sleep(1);console.log("waiting for ptr");}var arg1 =Memory.allocUtf8String('arg1');var txt =Memory.allocUtf8String('Some text for arg2');wg_log(arg0, arg1, txt);console.log("loaded");
Frida Fuzzing
Frida Stalker
Iz dokumentacije: Stalker je Fridin motor za praćenje koda. Omogućava praćenje niti, hvatajući svaku funkciju, svaki blok, čak i svaku instrukciju koja se izvršava.
Ovo je još jedan primer kako da se povežete na Frida Stalker svaki put kada se pozove funkcija:
console.log("loading");constwg_log_addr=Module.findExportByName("<Program>","<function_name>");constwg_log=newNativeFunction(wg_log_addr,"void", ["pointer","pointer","pointer"], {});Interceptor.attach(wg_log_addr, {onEnter:function(args) {console.log(`logging the following message: ${args[2].readCString()}`);Stalker.follow({events: {// only collect coverage for newly encountered blockscompile:true,},onReceive:function (events) {constbbs=Stalker.parse(events, {stringify:false,annotate:false});console.log("Stalker trace of write_msg_to_log: \n"+bbs.flat().map(DebugSymbol.fromAddress).join('\n'));}});},onLeave:function(retval) {Stalker.unfollow();Stalker.flush(); // this is important to get all events}});
Ovo je zanimljivo za svrhe debagovanja, ali za fuzzing, konstantno .follow() i .unfollow() je veoma neefikasno.
fpicker je Frida-bazirani fuzzing paket koji nudi razne fuzzing režime za fuzzing unutar procesa, kao što su AFL++ režim ili pasivni režim praćenja. Trebalo bi da radi na svim platformama koje podržava Frida.
# Get fpickergitclonehttps://github.com/ttdennis/fpickercdfpicker# Get Frida core devkit and prepare fpickerwgethttps://github.com/frida/frida/releases/download/16.1.4/frida-core-devkit-16.1.4-[yourOS]-[yourarchitecture].tar.xz# e.g. https://github.com/frida/frida/releases/download/16.1.4/frida-core-devkit-16.1.4-macos-arm64.tar.xztar-xf./*tar.xzcplibfrida-core.alibfrida-core-[yourOS].a#libfrida-core-macos.a# Install fpickermakefpicker-[yourOS]# fpicker-macos# This generates ./fpicker# Install radamsa (fuzzer generator)brewinstallradamsa
Pripremite FS:
# From inside fpicker clonemkdir-pexamples/wg-log# Where the fuzzing script will bemkdir-pexamples/wg-log/out# For code coverage and crashesmkdir-pexamples/wg-log/in# For starting inputs# Create at least 1 input for the fuzzerechoHelloWorld>examples/wg-log/in/0
Fuzzer skripta (examples/wg-log/myfuzzer.js):
examples/wg-log/myfuzzer.js
// Import the fuzzer base classimport { Fuzzer } from"../../harness/fuzzer.js";classWGLogFuzzerextendsFuzzer {constructor() {console.log("WGLogFuzzer constructor called")// Get and declare the function we are going to fuzzvar wg_log_addr =Module.findExportByName("<Program name>","<func name to fuzz>");var wg_log_func =newNativeFunction(wg_log_addr,"void", ["pointer","pointer","pointer"], {});// Initialize the objectsuper("<Program nane>", wg_log_addr, wg_log_func);this.wg_log_addr = wg_log_addr; // We cannot use "this" before calling "super"console.log("WGLogFuzzer in the middle");// Prepare the second argument to pass to the fuzz functionthis.tag =Memory.allocUtf8String("arg2");// Get the first argument we need to pass from a call to the functino we want to fuzzvar wg_log_global_ptr =null;console.log(this.wg_log_addr);Interceptor.attach(this.wg_log_addr, {onEnter:function(args) {console.log("Entering in the function to get the first argument");wg_log_global_ptr =newNativePointer(args[0]);}});while (! wg_log_global_ptr) {Thread.sleep(1)}this.wg_log_global_ptr = wg_log_global_ptr;console.log("WGLogFuzzer prepare ended")}// This function is called by the fuzzer with the first argument being a pointer into memory// where the payload is stored and the second the length of the input.fuzz(payload, len) {// Get a pointer to payload being a valid C string (with a null byte at the end)var payload_cstring =payload.readCString(len);this.payload =Memory.allocUtf8String(payload_cstring);// Debug and fuzzthis.debug_log(this.payload, len);// Pass the 2 first arguments we know the function needs and finally the payload to fuzzthis.target_function(this.wg_log_global_ptr,this.tag,this.payload);}}constf=newWGLogFuzzer();rpc.exports.fuzzer = f;
Kompajlirajte fuzzer:
# From inside fpicker clone## Compile from "myfuzzer.js" to "harness.js"frida-compileexamples/wg-log/myfuzzer.js-oharness.js
Pozovite fuzzer fpicker koristeći radamsa:
# Indicate fpicker to fuzz a program with the harness.js script and which folders to usefpicker-v--fuzzer-modeactive-eattach-p<Programtofuzz>-Dusb-oexamples/wg-log/out/-iexamples/wg-log/in/-fharness.js--standalone-mutatorcmd--mutator-command"radamsa"# You can find code coverage and crashes in examples/wg-log/out/
U ovom slučaju ne ponovo pokrećemo aplikaciju ili obnavljamo stanje nakon svake payload. Dakle, ako Frida pronađe srušavanje, sledeći unosi nakon te payload mogu takođe srušiti aplikaciju (jer je aplikacija u nestabilnom stanju) čak i ako unos ne bi trebao da sruši aplikaciju.
Štaviše, Frida će se povezati na signale izuzetaka iOS-a, tako da kada Frida pronađe srušavanje, verovatno izveštaji o srušavanju iOS-a neće biti generisani.
Da bismo to sprečili, na primer, mogli bismo ponovo pokrenuti aplikaciju nakon svakog Frida srušavanja.
Logs & Crashes
Možete proveriti macOS konzolu ili log cli da biste proverili macOS logove.
Takođe možete proveriti logove sa iOS-a koristeći idevicesyslog.
Neki logovi će izostaviti informacije dodajući <private>. Da biste prikazali sve informacije, potrebno je da instalirate neki profil sa https://developer.apple.com/bug-reporting/profiles-and-logs/ da biste omogućili te privatne informacije.
Produbite svoje znanje u Mobilnoj bezbednosti sa 8kSec Akademijom. Savladajte iOS i Android bezbednost kroz naše kurseve samostalnog učenja i dobijte sertifikat: