SlideShare a Scribd company logo
CNIT 128
Hacking Mobile Devices
3. Attacking iOS Apps
Part 2 Updated 12-12-22
Topics: Part 1
• Introduction to Transport Security
• Identifying Insecure Storage
• Patching iOS Applications with Hopper
Topics: Part 2
• Attacking the iOS Runtime
• Understanding Interprocess Communication
• Attacking Using Injection
Attacking the iOS
Runtime
The Runtime
• Objective-C and Swift defer many decisions
• From compile-and-link time
• To runtime
• By using re
fl
ection
• Apps modify their own behavior at runtime
• Dynamically load new classes
• Change method implementations
Understanding Objective-C
and Swift
• Object-oriented languages
• Objects encapsulate data in the form of
classes
• Classes contain
• Instance variables
• Methods
• Properties
Interface File
• De
fi
nes a class structure
• Image from https://blog.teamtreehouse.com/an-introduction-to-objective-c
Methods
• Instance methods can only be invoked
• After creating an instance of the class
• Class methods can be invoked
• Without actually creating an instance of
the class
Swift Class
Instrumenting the iOS
Runtime
• Tracing, debugging, or otherwise pro
fi
ling the execution of an
app at runtime
• Examples:
• Bypassing jailbreak detection
• Stealing encryption keys
• Force-loading view controllers
• Attacking local authentication
• Pivoting to internal networks
• Demonstrating the risks of malware
• Inspecting a custom encryption protocol
Instrumenting Objective-C
• Objective-C is by far easiest to instrument
• To invoke a function
• Pass it a message
• Through the runtime's objc_msgSend()
function
• To instrument it, simulate calls to
objc_msgSend()
Method Swizzling
• Replace the implementation of a method at
runtime
• A class maintains a dispatch table
• With a map of selectors to
implementations
• Selector: name of method
• Implementation: pointer to function
• Replacing pointers achieves swizzling
Instrumenting Swift
• Swift uses direct function calls and vtable
lookups
• Requires more e
ff
ort to instrument
Cydia Substrate
• Runtime manipulation framework
• Created by saurik
• Can instrument apps on iOS
• Inherent in most jailbreaks
• Pre-installed with Cydia
Tweaks
• Also called substrate extensions
• Developed using the Cydia Substrate C API
• Compiled as dynamic libraries
• Placed in /Library/MobileSubstrate/
DynamicLibraries
• Loaded into an app by MobileLoader
Filters
• Prevent your extension being loaded into
every new process
• Filters are plist
fi
les
• In binary plist, XML, or JSON format
• Name is same as your tweak, with .plist
fi
le extension
mdsectweak.
plist
Filters by
bundle
identi
fi
er
<?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>Filter</key>
<dict>
<key>Bundles</key>
<array>
<string>com.mdsec.lab1-1a</string>
</array>
</dict>
</dict>
</plist>
Tweak Development
Environments
• iOSOpenDev
• Limited to OS X
• Theos
• Works on iOS, OS X, and Linux
• Recommended
• Captain Hook
• Dated, limited to OS X
Key Functions
in Substrate API
• MSHookFunction
• MSFindSymbol
• MSGetImageByName
• MSHookMessageEx
Key Functions
• MSHookFunction
• Hooks native C or C++ code functions
• Uses a trampoline to divert the execution
fl
ow to a replacement function
• MSFindSymbol
• Finds symbols by name
• Not possible with stripped apps
Key Functions
• MSGetImageByName
• Loads a dynamic library
• If it's not already loaded
• MSHookMessageEx
• Implements method swizzling for
functions that inherit from NSObject
Example
• Line 4: oldStat points to original stat()
function, which shows a
fi
le's status
• Lines 6-13: Replacement stat
• If path argument is /bin/bash, print an error
message
Example
• Line 15: MSInitialize loads its contents
fi
rst
when the app loads
• Line 16: MSHookFunction has three
arguments
• Symbol to replace, new function, old
function
Cycript
• A runtime instrumentation tool for iOS apps
• Blends JavaScript and Objective-C
• Can access and manipulate objects in a
running app
• Able to
• Brute-force local authentication
• Steal encryption keys from populated objects
• Force loading of view containers
Pivoting to Internal
Networks
• BYOD (Bring Your Own Device)
• MDM (Mobile Device Management)
• Apps that let you connect to company
resources from a phone
• If vulnerable, allow an attacker into the
internal network
Kaseya BYOD
Attacking Kaseya BYOD
• Kaseya gateway provides service to internal
resources
• Can be accessed by Kaseya Secure
Browser
• With no further authentication
• Compromise of mobile device exposes
internal resources
Instrumentation with Frida
• Frida is a standalone instrumentation
framework
• Does not use Substrate
• No modi
fi
cation to the device required
• Other than running the frida-server binary
• Controlled by a client over USB or the
network
Dynamic Linker
• In Linux, the LD_PRELOAD environment
variable
• Dynamically loads a library into a process
• In Mac OS or iOS, use
DLYD_INSERT_LIBRARIES
Understanding Interprocess
Communication
Sandbox
• iOS apps run in an isolated sandbox
• Interprocess communication is prohibited
• Exceptions
• Pasteboard
• Registered protocol handlers
• Application extensions
Attacking Protocol Handlers
• To open the App Store app, use
• itms-apps://itunes.apple.com/app/
id<num>
• You can de
fi
ne a custom URL scheme in
your app's Info.plist
fi
le, such as
• myvoip://dialer/?call=123
• In an iframe on a web page
• <iframe src="myvoip://dialer/?
call=0044906123123 "></iframe>
• This happened with Skype
Automatic Loading
Application Extensions
• Some are pre-de
fi
ned by Apple
• Today -- extend the Today view of the
noti
fi
cation center
• Share -- to share content with other apps
• Custom Keyboard
Application Extensions
1Password
• Uses an extension so other apps can query
credentials, such as Twitteri
fi
c
• A malicious app could request credentials
for any domain
• But user must manually approve the use
of the credential, which o
ff
ers some
protection from abuse
Attacking Using Injection
iOS Entry Points
• Input enters through:
• Web applications
• URL schemes
• File types
• AirDrop
• iBeacons
• Bluetooth
• Wi-Fi
• Pasteboards
• Application extensions
Injecting into UIWebViews
• UIWebView renders web content from
• HTML
• PDF
• RTF
• O
ffi
ce documents
• iWork documents
• Built on WebKit, like Safari and MobileSafari
UIWebViews
• Supports JavaScript
• Cannot be disabled
• XSS attacks are possible
• Can steal content, such as the Address
Book
Skype XSS
• Skype iOS app allowed script injection into
a user's full name
• Could access the local
fi
le system
• And upload the address book
Injecting into Client-Side
Data Stores
• SQLite databases
• Vulnerable to SQL injection
• Exposes data, but not usually command
injection
Injecting into XML
• "Billion Laughs" DoS attack
• Multiple nested XML entities
• Expanding them uses excessive
resources
• If parsing of external entities is allowed
• Could be used to attack web apps on the
local network
Injection into File-Handling
Routines
• Less common, but some apps have this injection
vulnerability
• User controls a
fi
lename
• Directory traversal attacks
• Example:
• Joe can upload a pro
fi
le pic to Documents/joe/
joepic.png
• Joe can change the
fi
lename to
• ../jane/janepic.png to read or write to another
user's folder
 3. Attacking iOS Applications (Part 2)

More Related Content

Similar to 3. Attacking iOS Applications (Part 2) (20)

PDF
ASFWS 2012 - Audit d’applications iOS par Julien Bachmann
Cyber Security Alliance
 
PDF
iOS Application Penetation Test
JongWon Kim
 
PPT
Mobile Security Assessment: 101
wireharbor
 
PDF
David Thiel - Secure Development On iOS
Source Conference
 
PPT
iOS Application Pentesting
n|u - The Open Security Community
 
PDF
Introduction to iOS Penetration Testing
OWASP
 
PDF
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
PROIDEA
 
PDF
Wahckon[2] - iOS Runtime Hacking Crash Course
eightbit
 
PDF
CrikeyCon 2015 - iOS Runtime Hacking Crash Course
eightbit
 
PPT
iOS Application Penetration Testing for Beginners
RyanISI
 
PDF
OWASP for iOS
Phineas Huang
 
PPTX
iOS application (in)security
iphonepentest
 
PPTX
Hacking & Securing of iOS Apps by Saurabh Mishra
OWASP Delhi
 
PDF
Find your own iOS kernel bug
Gustavo Martinez
 
PPTX
Runtime Analysis on Mobile Applications (February 2017)
Sandeep Jayashankar
 
PPTX
Mobile security part 2
Romansh Yadav
 
PPT
I phone app develoment ppt
sagaroceanic11
 
PPT
I phone app develoment ppt
sagaroceanic11
 
PDF
Dark Side of iOS [SmartDevCon 2013]
Kuba Břečka
 
PPTX
iOS-Application-Security-iAmPr3m
Prem Kumar (OSCP)
 
ASFWS 2012 - Audit d’applications iOS par Julien Bachmann
Cyber Security Alliance
 
iOS Application Penetation Test
JongWon Kim
 
Mobile Security Assessment: 101
wireharbor
 
David Thiel - Secure Development On iOS
Source Conference
 
iOS Application Pentesting
n|u - The Open Security Community
 
Introduction to iOS Penetration Testing
OWASP
 
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
PROIDEA
 
Wahckon[2] - iOS Runtime Hacking Crash Course
eightbit
 
CrikeyCon 2015 - iOS Runtime Hacking Crash Course
eightbit
 
iOS Application Penetration Testing for Beginners
RyanISI
 
OWASP for iOS
Phineas Huang
 
iOS application (in)security
iphonepentest
 
Hacking & Securing of iOS Apps by Saurabh Mishra
OWASP Delhi
 
Find your own iOS kernel bug
Gustavo Martinez
 
Runtime Analysis on Mobile Applications (February 2017)
Sandeep Jayashankar
 
Mobile security part 2
Romansh Yadav
 
I phone app develoment ppt
sagaroceanic11
 
I phone app develoment ppt
sagaroceanic11
 
Dark Side of iOS [SmartDevCon 2013]
Kuba Břečka
 
iOS-Application-Security-iAmPr3m
Prem Kumar (OSCP)
 

More from Sam Bowne (20)

PDF
Introduction to the Class & CISSP Certification
Sam Bowne
 
PDF
Cyberwar
Sam Bowne
 
PDF
3: DNS vulnerabilities
Sam Bowne
 
PDF
8. Software Development Security
Sam Bowne
 
PDF
4 Mapping the Application
Sam Bowne
 
PDF
12 Elliptic Curves
Sam Bowne
 
PDF
11. Diffie-Hellman
Sam Bowne
 
PDF
2a Analyzing iOS Apps Part 1
Sam Bowne
 
PDF
9 Writing Secure Android Applications
Sam Bowne
 
PDF
12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
PDF
10 RSA
Sam Bowne
 
PDF
12 Investigating Windows Systems (Part 1 of 3
Sam Bowne
 
PDF
9. Hard Problems
Sam Bowne
 
PDF
8 Android Implementation Issues (Part 1)
Sam Bowne
 
PDF
11 Analysis Methodology
Sam Bowne
 
PDF
8. Authenticated Encryption
Sam Bowne
 
PDF
7. Attacking Android Applications (Part 2)
Sam Bowne
 
PDF
7. Attacking Android Applications (Part 1)
Sam Bowne
 
PDF
5. Stream Ciphers
Sam Bowne
 
PDF
6 Scope & 7 Live Data Collection
Sam Bowne
 
Introduction to the Class & CISSP Certification
Sam Bowne
 
Cyberwar
Sam Bowne
 
3: DNS vulnerabilities
Sam Bowne
 
8. Software Development Security
Sam Bowne
 
4 Mapping the Application
Sam Bowne
 
12 Elliptic Curves
Sam Bowne
 
11. Diffie-Hellman
Sam Bowne
 
2a Analyzing iOS Apps Part 1
Sam Bowne
 
9 Writing Secure Android Applications
Sam Bowne
 
12 Investigating Windows Systems (Part 2 of 3)
Sam Bowne
 
10 RSA
Sam Bowne
 
12 Investigating Windows Systems (Part 1 of 3
Sam Bowne
 
9. Hard Problems
Sam Bowne
 
8 Android Implementation Issues (Part 1)
Sam Bowne
 
11 Analysis Methodology
Sam Bowne
 
8. Authenticated Encryption
Sam Bowne
 
7. Attacking Android Applications (Part 2)
Sam Bowne
 
7. Attacking Android Applications (Part 1)
Sam Bowne
 
5. Stream Ciphers
Sam Bowne
 
6 Scope & 7 Live Data Collection
Sam Bowne
 
Ad

Recently uploaded (20)

PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Ad

3. Attacking iOS Applications (Part 2)

  • 1. CNIT 128 Hacking Mobile Devices 3. Attacking iOS Apps Part 2 Updated 12-12-22
  • 2. Topics: Part 1 • Introduction to Transport Security • Identifying Insecure Storage • Patching iOS Applications with Hopper
  • 3. Topics: Part 2 • Attacking the iOS Runtime • Understanding Interprocess Communication • Attacking Using Injection
  • 5. The Runtime • Objective-C and Swift defer many decisions • From compile-and-link time • To runtime • By using re fl ection • Apps modify their own behavior at runtime • Dynamically load new classes • Change method implementations
  • 6. Understanding Objective-C and Swift • Object-oriented languages • Objects encapsulate data in the form of classes • Classes contain • Instance variables • Methods • Properties
  • 7. Interface File • De fi nes a class structure • Image from https://blog.teamtreehouse.com/an-introduction-to-objective-c
  • 8. Methods • Instance methods can only be invoked • After creating an instance of the class • Class methods can be invoked • Without actually creating an instance of the class
  • 10. Instrumenting the iOS Runtime • Tracing, debugging, or otherwise pro fi ling the execution of an app at runtime • Examples: • Bypassing jailbreak detection • Stealing encryption keys • Force-loading view controllers • Attacking local authentication • Pivoting to internal networks • Demonstrating the risks of malware • Inspecting a custom encryption protocol
  • 11. Instrumenting Objective-C • Objective-C is by far easiest to instrument • To invoke a function • Pass it a message • Through the runtime's objc_msgSend() function • To instrument it, simulate calls to objc_msgSend()
  • 12. Method Swizzling • Replace the implementation of a method at runtime • A class maintains a dispatch table • With a map of selectors to implementations • Selector: name of method • Implementation: pointer to function • Replacing pointers achieves swizzling
  • 13. Instrumenting Swift • Swift uses direct function calls and vtable lookups • Requires more e ff ort to instrument
  • 14. Cydia Substrate • Runtime manipulation framework • Created by saurik • Can instrument apps on iOS • Inherent in most jailbreaks • Pre-installed with Cydia
  • 15. Tweaks • Also called substrate extensions • Developed using the Cydia Substrate C API • Compiled as dynamic libraries • Placed in /Library/MobileSubstrate/ DynamicLibraries • Loaded into an app by MobileLoader
  • 16. Filters • Prevent your extension being loaded into every new process • Filters are plist fi les • In binary plist, XML, or JSON format • Name is same as your tweak, with .plist fi le extension
  • 17. mdsectweak. plist Filters by bundle identi fi er <?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>Filter</key> <dict> <key>Bundles</key> <array> <string>com.mdsec.lab1-1a</string> </array> </dict> </dict> </plist>
  • 18. Tweak Development Environments • iOSOpenDev • Limited to OS X • Theos • Works on iOS, OS X, and Linux • Recommended • Captain Hook • Dated, limited to OS X
  • 19. Key Functions in Substrate API • MSHookFunction • MSFindSymbol • MSGetImageByName • MSHookMessageEx
  • 20. Key Functions • MSHookFunction • Hooks native C or C++ code functions • Uses a trampoline to divert the execution fl ow to a replacement function • MSFindSymbol • Finds symbols by name • Not possible with stripped apps
  • 21. Key Functions • MSGetImageByName • Loads a dynamic library • If it's not already loaded • MSHookMessageEx • Implements method swizzling for functions that inherit from NSObject
  • 22. Example • Line 4: oldStat points to original stat() function, which shows a fi le's status • Lines 6-13: Replacement stat • If path argument is /bin/bash, print an error message
  • 23. Example • Line 15: MSInitialize loads its contents fi rst when the app loads • Line 16: MSHookFunction has three arguments • Symbol to replace, new function, old function
  • 24. Cycript • A runtime instrumentation tool for iOS apps • Blends JavaScript and Objective-C • Can access and manipulate objects in a running app • Able to • Brute-force local authentication • Steal encryption keys from populated objects • Force loading of view containers
  • 25. Pivoting to Internal Networks • BYOD (Bring Your Own Device) • MDM (Mobile Device Management) • Apps that let you connect to company resources from a phone • If vulnerable, allow an attacker into the internal network
  • 27. Attacking Kaseya BYOD • Kaseya gateway provides service to internal resources • Can be accessed by Kaseya Secure Browser • With no further authentication • Compromise of mobile device exposes internal resources
  • 28. Instrumentation with Frida • Frida is a standalone instrumentation framework • Does not use Substrate • No modi fi cation to the device required • Other than running the frida-server binary • Controlled by a client over USB or the network
  • 29. Dynamic Linker • In Linux, the LD_PRELOAD environment variable • Dynamically loads a library into a process • In Mac OS or iOS, use DLYD_INSERT_LIBRARIES
  • 31. Sandbox • iOS apps run in an isolated sandbox • Interprocess communication is prohibited • Exceptions • Pasteboard • Registered protocol handlers • Application extensions
  • 32. Attacking Protocol Handlers • To open the App Store app, use • itms-apps://itunes.apple.com/app/ id<num> • You can de fi ne a custom URL scheme in your app's Info.plist fi le, such as • myvoip://dialer/?call=123
  • 33. • In an iframe on a web page • <iframe src="myvoip://dialer/? call=0044906123123 "></iframe> • This happened with Skype Automatic Loading
  • 34. Application Extensions • Some are pre-de fi ned by Apple • Today -- extend the Today view of the noti fi cation center • Share -- to share content with other apps • Custom Keyboard
  • 36. 1Password • Uses an extension so other apps can query credentials, such as Twitteri fi c • A malicious app could request credentials for any domain • But user must manually approve the use of the credential, which o ff ers some protection from abuse
  • 38. iOS Entry Points • Input enters through: • Web applications • URL schemes • File types • AirDrop • iBeacons • Bluetooth • Wi-Fi • Pasteboards • Application extensions
  • 39. Injecting into UIWebViews • UIWebView renders web content from • HTML • PDF • RTF • O ffi ce documents • iWork documents • Built on WebKit, like Safari and MobileSafari
  • 40. UIWebViews • Supports JavaScript • Cannot be disabled • XSS attacks are possible • Can steal content, such as the Address Book
  • 41. Skype XSS • Skype iOS app allowed script injection into a user's full name • Could access the local fi le system • And upload the address book
  • 42. Injecting into Client-Side Data Stores • SQLite databases • Vulnerable to SQL injection • Exposes data, but not usually command injection
  • 43. Injecting into XML • "Billion Laughs" DoS attack • Multiple nested XML entities • Expanding them uses excessive resources • If parsing of external entities is allowed • Could be used to attack web apps on the local network
  • 44. Injection into File-Handling Routines • Less common, but some apps have this injection vulnerability • User controls a fi lename • Directory traversal attacks • Example: • Joe can upload a pro fi le pic to Documents/joe/ joepic.png • Joe can change the fi lename to • ../jane/janepic.png to read or write to another user's folder