Code: Select all
// ContentView.swift
class ContentViewModel: ObservableObject {
@Published var counter: Int = 0
func incrementCounter() {
counter += 1
}
}
Code: Select all
// hook.js
const TARGET_SYMBOL = '$s8TestApp216ContentViewModelC16incrementCounteryyF';
const module = Process.findModuleByName('TestApp2');
const targetAddress = module.findExportByName(TARGET_SYMBOL);
var selfPtr = null
Interceptor.attach(targetAddress, {
onEnter: function(args) {
selfPtr = args[0]; // ContentViewModel instance pointer
console.log(`[+] Self pointer: ${selfPtr}`);
}
});
Code: Select all
frida -U TestApp2 --auto-reload -l hook.js
Code: Select all
[iPhone::TestApp2 ]-> [+] Self pointer: 0x280eb0860
Wie lese und ändere ich den aktuellen Wert des Zählers angesichts dieses Zeigers?
Was ich versucht habe
- Verwendung des Swift.Object-Wrappers:
Code: Select all
[iPhone::TestApp2 ]-> var temp = new Swift.Object(selfPtr, "ContentViewModel");
[iPhone::TestApp2 ]-> temp.counter; // undefined
[iPhone::TestApp2 ]-> temp
{
"handle": "0x280eb0860" // not sure what to do with this handle
}
- Zugriff über Swift.classes:
Code: Select all
[iPhone::TestApp2 ]-> Swift.classes.ContentViewModel
{
"$conformances": [
"ObservableObject"
],
"$fields": [
{
"isVar": true,
"name": "_counter", // the _counter variable name is shown but the value is not
"typeName": "Published"
}
],
"$methods": []
}
- Direktes Lesen des Speichers (verschiedene Offsets ausprobieren):
Code: Select all
[iPhone::TestApp2 ]-> selfPtr.add(0x10).readS64() // not sure of correct offset
"10785265760"
- iOS 15.8.5 (Jailbreak)
- Frida 17.3.2
- Swift-Klasse (nicht @objc verfügbar gemacht)
Die gesamte App besteht nur aus diesen beiden Dateien unten.
ContentView.swift:
Code: Select all
import SwiftUI
import Combine
class ContentViewModel: ObservableObject {
@Published var counter: Int = 0
func incrementCounter() {
counter += 1
}
}
struct ContentView: View {
@StateObject private var viewModel = ContentViewModel()
var body: some View {
VStack(spacing: 20) {
TextField("Counter", value: $viewModel.counter, format: .number)
.textFieldStyle(RoundedBorderTextFieldStyle())
.multilineTextAlignment(.center)
.frame(width: 100)
Button("Increment") {
viewModel.incrementCounter()
}
.buttonStyle(.borderedProminent)
}
.padding()
}
}
#Preview {
ContentView()
}
Code: Select all
import SwiftUI
@main
struct TestApp2App: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Mobile version