SlideShare a Scribd company logo
iOS and OS X ABI
(Hacking in context)
Mikhail Sosonkin
Security Researcher at SYNACK
Working on low level emulation with QEMU and iPhone automation.
Graduate of Polytechnic University
a.k.a Polytechnic Institute of New York University
a.k.a New York University Polytechnic School of Engineering
a.k.a New York University Tandon School of Engineering
СССР 1986
Intel 8080 Clone
1.78MHz CPU
32KB RAM
2KB ROM
450 Rubles
Wikipedia-RU
What’s a vulnerability
Just crashes
Bugs Vulnerabilities
What we are used to
Logic errors
Amazon Apple
“In short, the very four digits that Amazon considers
unimportant enough to display in the clear on the web are
precisely the same ones that Apple considers secure enough
to perform identity verification.”
- http://www.wired.com/2012/08/apple-amazon-mat-
honan-hacking/all/
It is not enough to just be careful with your interfaces. You
must also have have mitigations and continuous analysis that
includes “outsiders”.
Security considerations and reviews should be part of every
step of development lifecycle.
Where are the vulns?!
Memory corruption - just won’t go away!
That’s what a lot of CTFs seem to be focusing on.
History thereof
Memory Errors
“Special feature”
Backdooring yourself.
Someone will eventually discover it.
Network
man on the side
http://www.wired.com/2015/04/researchers-uncover-method-detect-nsa-quantum-insert-hacks/
web
where did I leave that session key again?
https://www.owasp.org/index.php/Top_10_2013-Table_of_Contents
Miscommunications
The root of all bugs.
Don’t be too paranoid
It’s not healthy, but always ask:
“what do you do if someone compromises
this component?”
Targeting
Classic:
Browser, Remote, Phishing
A little more advanced:
Via AWS - managed services (Exploiting external relationships)
USB - https://srlabs.de/badusb/ i.e. Stuxnet
Beg, borrow and steal
Finding vulnerabilities
Fuzzing (AFL, Many frameworks)
Code reading (SourceInsight, Understand)
Dynamic/Static analysis (Qira, Panda)
Exploit
Control EIP
Doesn’t have to be 100%
Gain execution
Binary protections like ASLR and DEP
Infect
Run shell code
Might have some ROPing to do
And, stack pivoting
Find the egg
Bigger shellcode.
Download implant
Gain persistence i.e. launch daemon
No Disclosure
Private Communities
Full disclosure
Responsible Disclosure
Coordinated Disclosure
Private Bug bounties: Google, Microsoft, Facebook
Managed Bug Bounties: Bugcrowd, HackerOne, SYNACK
Black Market Bug Bounties:
Zerodium, Vupen
Cosinc (link)
HackingTeam (Probably defunct)
MitnickSecurity
Lots of secretive companies (link)
A few not so secretive (link)
SYNACK
Private Targets
Think easy targets
Fortune 500 Companies
Several Categories
Host, Web, Mobile
Average payout: $690
We provide a cyber platform, Hydra!
https://www.synack.com/red-team/
Requires passing an assessment
SYNACK Red Team entry
If unable to pass try
BugCrowd or HackerOne
Let’s say you gained execution
Goals
Build shellcode that
Downloads a dylib.
Injects the dylib into process.
Target OS X and iOS
Get initial info - OSX
Get initial info - iOS
Partial source
XNU kernel
https://opensource.apple.com/tarballs/xnu/
Dyld source
https://opensource.apple.com/tarballs/dyld/
Can be compiled
ARM64 Registers
31 General purpose registers
X0 … X30 or W0 … W30
X31 - (zr) The Zero register
X30 - (lr) Procedure Link Register (RIP)
X29 - (fp) Frame pointer (RBP)
X18 - Reserved on iOS
ARM64 Instructions
Conditional Branches
B.EQ, B.NE, TBNZ (Test bit and Branch if Nonzero), etc.
Unconditional Branches
B, RET, SVC
Conditional Select
CSEL W9, W9, W10, EQ
“W9 = EQ?W9:W10”
Introducing: IDARef https://github.com/nologic/idaref
Introducing: HopperRef https://github.com/zbuc/hopperref
Making system calls
Calling Convention
On ARM64:
X0 … X8 Contain function parameters
X16 has the system call number
Positive for Posix
Negative for Mach Ports
0x80000000 for thread_set_self
SVC 0x80; jumps to kernel
Let’s make a system call
NYU Hacknight: iOS and OSX ABI
Syscall numbers
OSX:
0x01000000 - mach ports
0x02000000 - Posix
0x03000003 - pthread_set_self
IOS
0x00000000 and below - mach ports
0x00000000 and above - Posix
0x80000000 - pthread_set_self
Loading Mach-O’s
Who does what?
- Kernel:
- Maps the main executable
- Maps the loader
- Passes control to the loader
- DYLD:
- “Maps” itself and the main executable
- Maps and links dependency libraries.
File Structure: Header
/usr/include/mach-o/loader.h
File Structure: Commands
- Follow the header
- ‘cmdsize’ is a multiple of 8 bytes.
Mach-O commands
- LC_SEGMENT and LC_SEGMENT_64
- From file to virtual memory: __DATA, __TEXT, etc.
- LC_UNIXTHREAD
- Sets up initial registers and stack
- Entry point
- LC_LOAD_DYLINKER
- Specifies the loader i.e. /usr/lib/dyld
- LC_MAIN
- Sets up the stack
- etc
NYU Hacknight: iOS and OSX ABI
Setting up the stack
OSX
Arguments
Environment variables
Apple variable
Generated by the kernel
(LC_UNIXTHREAD)
Setting up the stack
iOS
Arguments
Environment variables
Apple variable
Generated by the kernel
(LC_UNIXTHREAD)
Segments
Let’s build some shellcode.
(live exercise)
Recorded session
`xcrun --sdk iphoneos --find gcc` -Os -fno-stack-protector -
fomit-frame-pointer -fno-exceptions -Wimplicit -isysroot
`xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk
iphoneos --show-sdk-path`/System/Library/Frameworks -
F`xcrun --sdk iphoneos --show-sdk-
path`/System/Library/PrivateFrameworks -arch arm64
test_syscall.c -o test_syscall
otool -t -v test_syscall
Build it using GCC
- Easy to represent complex logic
- Excellent way to learn assembly skills
- Assist with reverse engineering
- Port to different architectures
- Optimization hints
- Does 90% of the work for you
Cons of using GCC
- Can get hard to make GCC avoid outputting certain bytes.
- Give up a level of control
- Can get into dependency hell
- All the usual problems with C.
- Optimizer could get too aggressive
The Challenge
ShellCC
- https://github.com/nologic/shellcc
- shellcode
- extractshell.py: Gets the bytecodes from the macho as raw shellcode
- Makefile has build commands for shellcode ARM/x86_64
- shellharness
- reads a file and executes the buffer.
The challenge
- Understand injectdyld_file.c
- Figure out how to dynamically load a dylib
- Can use injectdyld_file.c as a base
- Hint: you will need to read the DYLD sourcecode.
Where to learn about security?
- https://seccasts.com/
- http://www.opensecuritytraining.info/
- https://www.corelan.be
- youtube for conference
- Security meetups
- Just practice
- Read/follow walkthroughs
- follow the reddits:
- netsec
- reverseengineering
- malware
- lowlevel
- blackhat
- securityCTF
- rootkit
- vrd
Getting started with iOS
- Get iPhone 5s
- Swappa
- Apply Jailbreak
- Install OpenSSH via Cydia
- Use tcprelay to SSH over USB
- Start exploring
- debugserver
- https://github.com/iosre/iOSAppReverseEngineering
- https://nabla-c0d3.github.io/blog/2014/12/30/tcprelay-multiple-devices/
Thank you!
Mikhail Sosonkin
mikhail@synack.com
Google+

More Related Content

PDF
From printed circuit boards to exploits
PPTX
Dissecting Android APK
PDF
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
PPTX
Nullbyte 6ed. 2019
PPTX
Terminal share of FlashAir W-04
PDF
How security broken? - Android internals and malware infection possibilities
ODP
Tarea 4 – uso de cinahl
PPTX
Distribucion binomial
From printed circuit boards to exploits
Dissecting Android APK
Cyber Analysts: who they are, what they do, where they are - Marco Ramilli - ...
Nullbyte 6ed. 2019
Terminal share of FlashAir W-04
How security broken? - Android internals and malware infection possibilities
Tarea 4 – uso de cinahl
Distribucion binomial

Viewers also liked (19)

PDF
ECE 505 Final project
PDF
We in the European union
PPTX
ciclo del azufre
PDF
Owasp orlando, april 13, 2016
PDF
CV-022516-Linkedin
PPT
Strategic Planning Class
PPTX
Photography planning
PPTX
Question 7
PPTX
Database management system
PPTX
Portfolio 2017
PDF
Catalogo crv
PPTX
Media institutions powerpoint 1
DOCX
Proyecto de-informatica grupo 4
PDF
CV_Vitor_Silva
PDF
Spartireklama Prezentacija
DOC
TIVRA TARUN -Commercial & Contract
PDF
Bonfim studio-7-dicas-imbativeis-logo
TXT
Cvv222222
ECE 505 Final project
We in the European union
ciclo del azufre
Owasp orlando, april 13, 2016
CV-022516-Linkedin
Strategic Planning Class
Photography planning
Question 7
Database management system
Portfolio 2017
Catalogo crv
Media institutions powerpoint 1
Proyecto de-informatica grupo 4
CV_Vitor_Silva
Spartireklama Prezentacija
TIVRA TARUN -Commercial & Contract
Bonfim studio-7-dicas-imbativeis-logo
Cvv222222

Similar to NYU Hacknight: iOS and OSX ABI (20)

PDF
OWASP: iOS Spelunking
PDF
Find your own iOS kernel bug
PDF
Porting your favourite cmdline tool to Android
PDF
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
PPTX
Lab Handson: Power your Creations with Intel Edison!
PDF
Synack at AppSec California with Patrick Wardle
PPTX
EkoParty 2010: iPhone Rootkit? There's an App for that.
PPTX
Android sandbox
PPTX
Pentesting iOS Applications
PDF
Android OS Porting: Introduction
PDF
Os Selbak
PDF
Understand study
PDF
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
PDF
Falco meetup OpenShift
PDF
Debuging tech
PDF
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
PPT
Security & ethical hacking p2
PDF
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
PPT
Security & ethical hacking
PPTX
Raising the Bar on Robotics Code Quality
OWASP: iOS Spelunking
Find your own iOS kernel bug
Porting your favourite cmdline tool to Android
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
Lab Handson: Power your Creations with Intel Edison!
Synack at AppSec California with Patrick Wardle
EkoParty 2010: iPhone Rootkit? There's an App for that.
Android sandbox
Pentesting iOS Applications
Android OS Porting: Introduction
Os Selbak
Understand study
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
Falco meetup OpenShift
Debuging tech
DEF CON 27 - workshop ANTHONY ROSE - introduction to amsi bypasses and sandbo...
Security & ethical hacking p2
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
Security & ethical hacking
Raising the Bar on Robotics Code Quality

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
top salesforce developer skills in 2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Essential Infomation Tech presentation.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Upgrade and Innovation Strategies for SAP ERP Customers
top salesforce developer skills in 2025.pdf
Digital Strategies for Manufacturing Companies
How Creative Agencies Leverage Project Management Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
Essential Infomation Tech presentation.pptx
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
How to Choose the Right IT Partner for Your Business in Malaysia
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Which alternative to Crystal Reports is best for small or large businesses.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
PTS Company Brochure 2025 (1).pdf.......
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
2025 Textile ERP Trends: SAP, Odoo & Oracle

NYU Hacknight: iOS and OSX ABI

  • 1. iOS and OS X ABI (Hacking in context) Mikhail Sosonkin
  • 2. Security Researcher at SYNACK Working on low level emulation with QEMU and iPhone automation. Graduate of Polytechnic University a.k.a Polytechnic Institute of New York University a.k.a New York University Polytechnic School of Engineering a.k.a New York University Tandon School of Engineering
  • 3. СССР 1986 Intel 8080 Clone 1.78MHz CPU 32KB RAM 2KB ROM 450 Rubles Wikipedia-RU
  • 4. What’s a vulnerability Just crashes Bugs Vulnerabilities What we are used to Logic errors
  • 5. Amazon Apple “In short, the very four digits that Amazon considers unimportant enough to display in the clear on the web are precisely the same ones that Apple considers secure enough to perform identity verification.” - http://www.wired.com/2012/08/apple-amazon-mat- honan-hacking/all/
  • 6. It is not enough to just be careful with your interfaces. You must also have have mitigations and continuous analysis that includes “outsiders”. Security considerations and reviews should be part of every step of development lifecycle.
  • 7. Where are the vulns?! Memory corruption - just won’t go away! That’s what a lot of CTFs seem to be focusing on. History thereof Memory Errors “Special feature” Backdooring yourself. Someone will eventually discover it.
  • 8. Network man on the side http://www.wired.com/2015/04/researchers-uncover-method-detect-nsa-quantum-insert-hacks/ web where did I leave that session key again? https://www.owasp.org/index.php/Top_10_2013-Table_of_Contents
  • 9. Miscommunications The root of all bugs. Don’t be too paranoid It’s not healthy, but always ask: “what do you do if someone compromises this component?”
  • 10. Targeting Classic: Browser, Remote, Phishing A little more advanced: Via AWS - managed services (Exploiting external relationships) USB - https://srlabs.de/badusb/ i.e. Stuxnet
  • 11. Beg, borrow and steal Finding vulnerabilities Fuzzing (AFL, Many frameworks) Code reading (SourceInsight, Understand) Dynamic/Static analysis (Qira, Panda)
  • 12. Exploit Control EIP Doesn’t have to be 100% Gain execution Binary protections like ASLR and DEP
  • 13. Infect Run shell code Might have some ROPing to do And, stack pivoting Find the egg Bigger shellcode. Download implant Gain persistence i.e. launch daemon
  • 14. No Disclosure Private Communities Full disclosure Responsible Disclosure Coordinated Disclosure Private Bug bounties: Google, Microsoft, Facebook Managed Bug Bounties: Bugcrowd, HackerOne, SYNACK
  • 15. Black Market Bug Bounties: Zerodium, Vupen Cosinc (link) HackingTeam (Probably defunct) MitnickSecurity Lots of secretive companies (link) A few not so secretive (link)
  • 16. SYNACK Private Targets Think easy targets Fortune 500 Companies Several Categories Host, Web, Mobile Average payout: $690 We provide a cyber platform, Hydra! https://www.synack.com/red-team/
  • 17. Requires passing an assessment SYNACK Red Team entry If unable to pass try BugCrowd or HackerOne
  • 18. Let’s say you gained execution
  • 19. Goals Build shellcode that Downloads a dylib. Injects the dylib into process. Target OS X and iOS
  • 22. Partial source XNU kernel https://opensource.apple.com/tarballs/xnu/ Dyld source https://opensource.apple.com/tarballs/dyld/ Can be compiled
  • 23. ARM64 Registers 31 General purpose registers X0 … X30 or W0 … W30 X31 - (zr) The Zero register X30 - (lr) Procedure Link Register (RIP) X29 - (fp) Frame pointer (RBP) X18 - Reserved on iOS
  • 24. ARM64 Instructions Conditional Branches B.EQ, B.NE, TBNZ (Test bit and Branch if Nonzero), etc. Unconditional Branches B, RET, SVC Conditional Select CSEL W9, W9, W10, EQ “W9 = EQ?W9:W10”
  • 28. Calling Convention On ARM64: X0 … X8 Contain function parameters X16 has the system call number Positive for Posix Negative for Mach Ports 0x80000000 for thread_set_self SVC 0x80; jumps to kernel
  • 29. Let’s make a system call
  • 31. Syscall numbers OSX: 0x01000000 - mach ports 0x02000000 - Posix 0x03000003 - pthread_set_self IOS 0x00000000 and below - mach ports 0x00000000 and above - Posix 0x80000000 - pthread_set_self
  • 33. Who does what? - Kernel: - Maps the main executable - Maps the loader - Passes control to the loader - DYLD: - “Maps” itself and the main executable - Maps and links dependency libraries.
  • 35. File Structure: Commands - Follow the header - ‘cmdsize’ is a multiple of 8 bytes.
  • 36. Mach-O commands - LC_SEGMENT and LC_SEGMENT_64 - From file to virtual memory: __DATA, __TEXT, etc. - LC_UNIXTHREAD - Sets up initial registers and stack - Entry point - LC_LOAD_DYLINKER - Specifies the loader i.e. /usr/lib/dyld - LC_MAIN - Sets up the stack - etc
  • 38. Setting up the stack OSX Arguments Environment variables Apple variable Generated by the kernel (LC_UNIXTHREAD)
  • 39. Setting up the stack iOS Arguments Environment variables Apple variable Generated by the kernel (LC_UNIXTHREAD)
  • 41. Let’s build some shellcode. (live exercise) Recorded session
  • 42. `xcrun --sdk iphoneos --find gcc` -Os -fno-stack-protector - fomit-frame-pointer -fno-exceptions -Wimplicit -isysroot `xcrun --sdk iphoneos --show-sdk-path` -F`xcrun --sdk iphoneos --show-sdk-path`/System/Library/Frameworks - F`xcrun --sdk iphoneos --show-sdk- path`/System/Library/PrivateFrameworks -arch arm64 test_syscall.c -o test_syscall otool -t -v test_syscall
  • 43. Build it using GCC - Easy to represent complex logic - Excellent way to learn assembly skills - Assist with reverse engineering - Port to different architectures - Optimization hints - Does 90% of the work for you
  • 44. Cons of using GCC - Can get hard to make GCC avoid outputting certain bytes. - Give up a level of control - Can get into dependency hell - All the usual problems with C. - Optimizer could get too aggressive
  • 46. ShellCC - https://github.com/nologic/shellcc - shellcode - extractshell.py: Gets the bytecodes from the macho as raw shellcode - Makefile has build commands for shellcode ARM/x86_64 - shellharness - reads a file and executes the buffer.
  • 47. The challenge - Understand injectdyld_file.c - Figure out how to dynamically load a dylib - Can use injectdyld_file.c as a base - Hint: you will need to read the DYLD sourcecode.
  • 48. Where to learn about security? - https://seccasts.com/ - http://www.opensecuritytraining.info/ - https://www.corelan.be - youtube for conference - Security meetups - Just practice - Read/follow walkthroughs - follow the reddits: - netsec - reverseengineering - malware - lowlevel - blackhat - securityCTF - rootkit - vrd
  • 49. Getting started with iOS - Get iPhone 5s - Swappa - Apply Jailbreak - Install OpenSSH via Cydia - Use tcprelay to SSH over USB - Start exploring - debugserver - https://github.com/iosre/iOSAppReverseEngineering - https://nabla-c0d3.github.io/blog/2014/12/30/tcprelay-multiple-devices/