iOS Frida Configuration

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

Frida की स्थापना

जेलब्रोकन डिवाइस पर Frida स्थापित करने के चरण:

  1. Cydia/Sileo ऐप खोलें।

  2. Manage -> Sources -> Edit -> Add पर जाएं।

  3. URL के रूप में "https://build.frida.re" दर्ज करें।

  4. नए जोड़े गए Frida स्रोत पर जाएं।

  5. Frida पैकेज को स्थापित करें।

यदि आप Corellium का उपयोग कर रहे हैं तो आपको https://github.com/frida/frida/releases से Frida रिलीज डाउनलोड करने की आवश्यकता है (frida-gadget-[yourversion]-ios-universal.dylib.gz) और अनपैक करने और dylib स्थान कॉपी करने के लिए जिस स्थान के लिए Frida से पूछा जाता है, उदा।: /Users/[youruser]/.cache/frida/gadget-ios.dylib

स्थापित होने के बाद, आप अपने PC में उपयोग कर सकते हैं कमांड frida-ls-devices और जांचें कि डिवाइस दिखाई देता है (आपके PC को इसका उपयोग करने की आवश्यकता है)। फोन की चल रही प्रक्रियाओं की जांच के लिए भी frida-ps -Uia का अमल करें।

जेलब्रोकन डिवाइस के बिना और ऐप को पैच किए बिना Frida

जांचें कि कैसे बिना जेलब्रोकन डिवाइस और ऐप को पैच किए बिना फ्रिडा का उपयोग करने के लिए इस ब्लॉग पोस्ट को: https://mrbypass.medium.com/unlocking-potential-exploring-frida-objection-on-non-jailbroken-devices-without-application-ed0367a84f07

Frida Client Installation

frida tools को स्थापित करें:

pip install frida-tools
pip install frida

जब Frida सर्वर इंस्टॉल किया गया है और डिवाइस चल रहा है और कनेक्ट किया गया है, जांचें कि क्लाइंट काम कर रहा है:

frida-ls-devices  # List devices
frida-ps -Uia     # Get running processes

फ्रिडा ट्रेस

# Functions
## Trace all functions with the word "log" in their name
frida-trace -U <program> -i "*log*"
frida-trace -U <program> -i "*log*" | swift demangle # Demangle names

# Objective-C
## Trace all methods of all classes
frida-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 binary
frida-trace -U -W <if-plugin-bin> -m '*[* *]'

प्राप्त करें सभी कक्षाएँ और विधियाँ

  • ऑटो पूर्ण करें: केवल frida -U <प्रोग्राम> को क्रियान्वित करें

  • सभी उपलब्ध कक्षाएँ प्राप्त करें (स्ट्रिंग द्वारा फ़िल्टर करें)

/tmp/script.js
// frida -U <program> -l /tmp/script.js

var filterClass = "filterstring";

if (ObjC.available) {
for (var className in ObjC.classes) {
if (ObjC.classes.hasOwnProperty(className)) {
if (!filterClass || className.includes(filterClass)) {
console.log(className);
}
}
}
} else {
console.log("Objective-C runtime is not available.");
}
  • एक कक्षा के सभी विधियों को प्राप्त करें (स्ट्रिंग द्वारा फ़िल्टर करें)

/tmp/script.js
// frida -U <program> -l /tmp/script.js

var 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.");
}
  • किसी फ़ंक्शन को कॉल करें

// Find the address of the function to call
const func_addr = Module.findExportByName("<Prog Name>", "<Func Name>");
// Declare the function to call
const func = new NativeFunction(
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 arg0
Interceptor.attach(wg_log_addr, {
onEnter: function(args) {
arg0 = new NativePointer(args[0]);
}
});

// Wait untill a call to the func occurs
while (! 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");

फ्रिडा फज़िंग

फ्रिडा स्टॉकर

दस्तावेज़ से: स्टॉकर फ्रिडा कोड ट्रेसिंग इंजन है। यह धागों को फॉलो करने की अनुमति देता है, हर फ़ंक्शन को कैप्चर करता है, हर ब्लॉक, हर निर्देश को भी जो कि निष्पादित किया जाता है।

आपके पास एक उदाहरण है जो फ्रिडा स्टॉकर को https://github.com/poxyran/misc/blob/master/frida-stalker-example.py में लागू करता है।

यह एक और उदाहरण है जो हर बार फ़ंक्शन को कॉल करने पर फ्रिडा स्टॉकर को जोड़ता है:

console.log("loading");
const wg_log_addr = Module.findExportByName("<Program>", "<function_name>");
const wg_log = new NativeFunction(
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 blocks
compile: true,
},
onReceive: function (events) {
const bbs = 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
}
});

यह डीबगिंग उद्देश्यों के लिए दिलचस्प है, लेकिन फजिंग के लिए, निरंतर .follow() और .unfollow() करना बहुत अप्रभावी है।

fpicker एक Frida-आधारित फजिंग सुइट है जो इन-प्रोसेस फजिंग के लिए विभिन्न फजिंग मोड प्रदान करता है, जैसे AFL++ मोड या एक पैसिव ट्रेसिंग मोड। यह फ्रिडा द्वारा समर्थित सभी प्लेटफॉर्मों पर चलना चाहिए।

# Get fpicker
git clone https://github.com/ttdennis/fpicker
cd fpicker

# Get Frida core devkit and prepare fpicker
wget https://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.xz
tar -xf ./*tar.xz
cp libfrida-core.a libfrida-core-[yourOS].a #libfrida-core-macos.a

# Install fpicker
make fpicker-[yourOS] # fpicker-macos
# This generates ./fpicker

# Install radamsa (fuzzer generator)
brew install radamsa
  • एफएस की तैयारी करें:

# From inside fpicker clone
mkdir -p examples/wg-log # Where the fuzzing script will be
mkdir -p examples/wg-log/out # For code coverage and crashes
mkdir -p examples/wg-log/in # For starting inputs

# Create at least 1 input for the fuzzer
echo Hello World > examples/wg-log/in/0
  • फज़र स्क्रिप्ट (examples/wg-log/myfuzzer.js):

examples/wg-log/myfuzzer.js
// Import the fuzzer base class
import { Fuzzer } from "../../harness/fuzzer.js";

class WGLogFuzzer extends Fuzzer {

constructor() {
console.log("WGLogFuzzer constructor called")

// Get and declare the function we are going to fuzz
var wg_log_addr = Module.findExportByName("<Program name>", "<func name to fuzz>");
var wg_log_func = new NativeFunction(
wg_log_addr,
"void", ["pointer", "pointer", "pointer"], {
});

// Initialize the object
super("<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 function
this.tag = Memory.allocUtf8String("arg2");

// Get the first argument we need to pass from a call to the functino we want to fuzz
var 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 = new NativePointer(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 fuzz
this.debug_log(this.payload, len);
// Pass the 2 first arguments we know the function needs and finally the payload to fuzz
this.target_function(this.wg_log_global_ptr, this.tag, this.payload);
}
}

const f = new WGLogFuzzer();
rpc.exports.fuzzer = f;
  • फज़र को कंपाइल करें:

# From inside fpicker clone
## Compile from "myfuzzer.js" to "harness.js"
frida-compile examples/wg-log/myfuzzer.js -o harness.js
  • radamsa का उपयोग करके fpicker को बुलाएं:

# Indicate fpicker to fuzz a program with the harness.js script and which folders to use
fpicker -v --fuzzer-mode active -e attach -p <Program to fuzz> -D usb -o examples/wg-log/out/ -i examples/wg-log/in/ -f harness.js --standalone-mutator cmd --mutator-command "radamsa"
# You can find code coverage and crashes in examples/wg-log/out/

इस मामले में हम ऐप्लिकेशन को रीस्टार्ट नहीं कर रहे हैं या स्थिति को पुनर्स्थापित नहीं कर रहे हैं प्रत्येक पेलोड के बाद। इसलिए, अगर Frida एक क्रैश ढूंढता है तो उस पेलोड के बाद के अगले इनपुट भी ऐप्लिकेशन को क्रैश कर सकते हैं (क्योंकि ऐप्लिकेशन अस्थिर स्थिति में है) भले ही इनपुट ऐप्लिकेशन को क्रैश नहीं करना चाहिए

इसके अतिरिक्त, Frida iOS के अपशिष्ट संकेतों में हुक करेगा, इसलिए जब Frida एक क्रैश ढूंढता है, शायद iOS क्रैश रिपोर्ट उत्पन्न नहीं होंगे

इसे रोकने के लिए, उदाहरण के लिए, हम हर Frida क्रैश के बाद ऐप्लिकेशन को रीस्टार्ट कर सकते हैं।

लॉग और क्रैश

आप macOS कंसोल या log cli का उपयोग करके macOS लॉग की जांच कर सकते हैं। आप idevicesyslog का उपयोग करके iOS से भी लॉग की जांच कर सकते हैं। कुछ लॉग जानकारी को छोड़कर <private> जोड़ सकते हैं। सभी जानकारी दिखाने के लिए आपको https://developer.apple.com/bug-reporting/profiles-and-logs/ से कुछ प्रोफ़ाइल इंस्टॉल करने की आवश्यकता है जो उस निजी जानकारी को सक्षम करने के लिए है।

अगर आपको नहीं पता क्या करना है:

vim /Library/Preferences/Logging/com.apple.system.logging.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Enable-Private-Data</key>
<true/>
</dict>
</plist>

killall -9 logd

आप निम्नलिखित स्थानों पर क्रैश की जांच कर सकते हैं:

  • iOS

  • सेटिंग्स → गोपनीयता → विश्लेषण और सुधार → विश्लेषण डेटा

  • /private/var/mobile/Library/Logs/CrashReporter/

  • macOS:

  • /Library/Logs/DiagnosticReports/

  • ~/Library/Logs/DiagnosticReports

iOS केवल एक ही ऐप के 25 क्रैश को संग्रहित करता है, इसलिए आपको उसे साफ करना होगा या फिर iOS क्रैश बनाना बंद कर देगा।

Frida Android Tutorials

pageFrida Tutorial

संदर्भ

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert)!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated