-
iOS Syscall Instruction and Hooking#1 - Security/iOS 2022. 12. 12. 15:07
예전에 올린 글 중 iOS Exit 후킹 코드를 사용하다가
syscall 사용하여 exit 시키는 경우도 있어 찾아보게 되었다.
일단 iOS Syscall Table이다.
https://www.theiphonewiki.com/wiki/Kernel_Syscalls
그 다음 iOS Syscall Instruction을 보면 이렇다.
- The immediate passed to svc is ignored, but the standard library uses svc 0x80.
- x16 holds the syscall number
- x0 through x8 hold up to 9 arguments*
- There are no arguments on the stack
- x0 and x1 hold up to 2 return values (e.g. in the case of fork)
- The carry bit is used to report an error, in which case x0 holds the error code
x16 레지스터에 Syscall 번호
x0 ~ x8엔 인자값 (Table 검색하면 자세히 나옴)
x0, x1 이 리턴값
iOS의 경우 svc 호출 시 svc 0x80 으로 사용
syscall exit 실행한다고 가정하면
opcode는 이렇게 될 것이다.
300080D2 -> mov x16, #1
011000D4 -> svc #0x80
Frida 메모리 스캔 후
011000D4 를 1F2003D5 (NOP) 으로
덮어쓰면 우회
var module = Process.findModuleByName('module_name'); var exit = '30 00 80 D2 01 10 00 D4' Memory.scan(module.base,module.size,exit, { onMatch: function(address, size) { Memory.protect(address, size, 'rwx'); Memory.writeByteArray(address.add(4), [0x1F, 0x20, 0x03, 0xD5]); }, onComplete: function () { console.log(Memory.readByteArray(address, size)); } })
exit 말고 다른 syscall 후킹하고 싶으면 Arm to Hex 이용해서 값만 바꿔주면 된다.
'#1 - Security > iOS' 카테고리의 다른 글
[iOS] Exit Function Hook (0) 2020.11.25 iOS 설치 파일 추출(IPA) (0) 2020.05.26 iOS Anti-Reversing Defenses (0) 2020.05.22 .deb Installation, SpringBoard Restart (0) 2020.05.20 [iOS] User Function Frida Hooking (0) 2019.11.21