SlideShare a Scribd company logo
Reverse Engineering
Swift Apps
Michael Gianarakis
Rootcon X 2016
# whoami
@mgianarakis
Director of SpiderLabs APAC at Trustwave
SecTalks Organiser (@SecTalks_BNE)
Flat Duck Justice Warrior #ducksec
Motivation
• Seeing more and more Swift being used in apps that we test (fan
boys like me tend to adopt new Apple technology quickly)
• Google is even considering using Swift as a first class language
on Android… (http://thenextweb.com/dd/2016/04/07/google-
facebook-uber-swift/)
• Wanted to dive into some of the key differences with Swift and
look at the challenges with respect to Swift app pen testing
• Focus is on “black box” app pen testing - for a deeper dive into
Swift language RE I recommend Ryan Stortz’s talk at Infiltrate
(http://infiltratecon.com/archives/swift_Ryan_Stortz.pdf)
How Does Swift Affect Testing?
• Will dive into the detail in the presentation but the
reality is not much in most areas, quite a bit in others?
• Most issues in iOS and OS X apps are due to poor
design decisions or misconfiguration and incorrect
implementation of Apple and third party frameworks
and libraries.
• The main thing that has changed is how you reverse
engineer the application
Quick Overview of
Swift
What is Swift?
• Compiled language created by Apple
• Released publicly in 2014 at WWDC and has seen
multiple revisions since.
• Open source with official implementations for iOS,
OS X and Linux.
• Intended to replace Objective-C eventually
Syntax (just the basics to follow
along)
Syntax (just the basics to follow
along)
Syntax (just the basics to follow
along)
Syntax (just the basics to follow
along)
Types
• All basic C and Objective-C types -> String, Bool,
Int , Float etc.
• Collection Types -> Array, Set, Dictionary
• Optional Types -> works with all types, no more nil
pointers like Objective-C
• Swift is a type safe language
Objective-C Compatibility
• Objective-C compatibility and interoperability
• Uses the same runtime environment
• Still supports C and C++ in the same app but
can’t be called from Swift like Objective-C
• Can allow for some dynamic features and
runtime manipulation
Other Language Features
• Barely scratched the surface
• Structs, Protocols, Extensions, Closures,
Enumerations, Optionals, Generics, Type Casting,
Access Control, Error Handling, Assertions….
• Automatic Reference Counting
• Unicode…
• var 💩 = 💩 💩 💩 💩 💩 ()
Other Language Features
Challenges Reversing
Swift Apps
Challenges
• Less dynamic than Objective-C
• Less flexible than Objective-C in some areas
• Can make it harder to do some of the standard tasks you
would do on a standard app pen test
• Less of an issue now because most Swift apps will include
be mixed with Objective-C
• Limited tooling
• We will explore this in more detail
Challenges
• Rapidly evolving syntax, APIs and features and Apple doesn’t care
too much about breaking changes.
• v1.0 - September 2014
• v1.1 - October 2014
• v1.2 - April 2015
• v2.0 - September 2015 (Open Sourced, Linux)
• v2.2 - March 2016
• v3.0 - Late 2016
Reversing Swift Apps
• Two primary reverse engineering activities when
conducting a “black box” pen test
• Dumping and analysing class information
from the binary
• Retrieving information at runtime using
debuggers, function hooking, tracing etc.
Retrieving Class
Information
Class Dump?
• The most common and easiest way to retrieve
class data from an Objective-C binary is the class-
dump utility
• class-dump-z retrieves class information and
formats to look like the equivalent of an Objective-
C header file
• Usually one of the first things you do when looking
at an app
Class Dump?
Class Dump?
What next?
• So class-dump-z doesn’t work with Swift binaries :(
• Now what?
• Let’s start diving into the binary
Symbol Table
• What do we get if we dump the symbol table?
Symbol Table
• What if we look for something we know is in the
binary?
• nm -gUj rootcon-demo | grep printDuckType
Symbol Table
• What if we look for something we know is in the
binary?
Name Mangling
• Looks promising but it’s a far cry from the output
of class-dump and is kind of hard to make out
• Swift stores metadata about a function in it’s
symbols in the process “mangling” the name.
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Class name
with length
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Class name
with length
Function name
with length
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Class name
with length
Function name
with length
Function
attribute
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Class name
with length
Function name
with length
Function
attribute
Parameters
Name Mangling
__TFC12rootcon_demo4Duck13printDuckTypefT_T_
Indicates it’s a
Swift method
Indicates it’s a
function
Function of a
class
Module name
with length
Class name
with length
Function name
with length
Function
attribute
Parameters
Return Type
Function Attributes
f Normal function
s Setter
g Getter
d Destructor
D Deallocator
c Constructor
C Allocator
Return Types
a Array
b Boolean
c Unicode Scalar
d Double
f Float
i Integer
u Unsigned Integer
Q Implicitly Unwrapped Optional
S String
swift-demangle
• So now we know roughly the way the names are
mangle you could use this to create a script that
“de-mangles” the names
• Apple has already thought of that and includes a
utility called swift-demangle to do just that
swift-demangle
swift-demangle
• With nm and swift-demangle and some shell
scripting you should be able to easily grab the
function signatures from an app
• Should be all you need to get basically the same
information you would from class-dump to start
assessing the app
class-dump-s
• Hacked together script that demangles names and
formats the output to approximate the output of
class-dump
• Written in Swift
Demo
Stripped Binaries
• CAVEAT: If the developer stripped symbols from
the binary then these techniques obviously won’t
work.
• Reverse engineering stripped binaries is a bit
more complicated
Objective-C Compatibility
• Part of the reason it’s much easier to get class
information from Objective-C binaries is because
it’s necessary for the Objective-C runtime to have
that info
• So what happens when you import Objective-C
frameworks or use Objective-C in your app?
Revisiting Class Dump
• The latest branch of class-dump by Steven Nygard
(the original class-dump utility) has limited support
for Swift.
• Need to download and build from source (no
binary release yet)
• https://github.com/nygard/class-dump
Revisiting Class Dump
Demo
Revisiting Class Dump
Revisiting Class Dump
Revisiting Class Dump
Other Options
Other Options
• classdump-dyld (successor to weakclassdump.cy)
• Disassemblers (i.e. Hopper, IDA Pro)
• Necessary for lower level insight into the app
• To demangle Swift function names https://
github.com/Januzellij/hopperscripts
• cycript? frida?
Function Hooking
Hooking Swift Methods
• Still possible.
• Much easier with in mixed Swift/Objective-C
binaries.
• Can still write tweaks with Mobile Substrate.
Hooking Swift Methods
Hooking Swift Methods
• Hooking getter method (works!)
Hooking Swift Methods
• Hooking setter method (kinda works…)
Hooking Swift Methods
• Certain functions in Swift are inlined and the class
constructor is one of them (which is directly setting
the instance variable)
• So in this case the setter will only be called again
by the top level code.
• If you call from there it works.
Hooking Swift Methods
• Changing the instance variable directly (works but
not a good idea probably)
Wrap Up
Wrap Up
• So not all hope is lost when it comes to your
standard pen test workflows with Swift apps
• A bit more of a pain in the arse if you don’t get
access to the source code
• Most issues in iOS and OS X apps are due to poor
design decisions or misconfiguration and incorrect
implementation of Apple and third party
frameworks and libraries.
Next Steps
• Improve the class-dump-s script :)
• Remove dependency on swift-demagle
• Ivars, stripped binaries?
• Runtime inspection
• cycript works but not as straightforward as with Objective-C
• LLDB works well if you are familiar with it
• Will hopefully write a blog post soon
Q&A?

More Related Content

What's hot (19)

PDF
Be armed to the teeth to maintain a high quality iOS code
Anastasia Kazakova
 
PDF
How to really obfuscate your pdf malware
zynamics GmbH
 
PPTX
Intro To AOP
Donald Belcham
 
PDF
DIC To The Limit – deSymfonyDay, Barcelona 2014
Ronny López
 
PDF
Facilitating Idiomatic Swift with Objective-C
Aaron Taylor
 
PDF
QA / Testing Tools, Automation Testing, Online & Classroom Training
AnanthReddy38
 
PPTX
Tech breakfast 18
James Leone
 
PDF
Introduction to mobile reversing
jduart
 
PPT
Java introduction
logeswarisaravanan
 
ODP
Weaving aspects in PHP with the help of Go! AOP library
Alexander Lisachenko
 
PDF
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
David Buck
 
PDF
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
PDF
Assignment1 B 0
Mahmoud
 
PPTX
Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...
Marco Breveglieri
 
PPTX
TypeScript Overview
Aniruddha Chakrabarti
 
PPTX
Introduction to Core Java Programming
Collaboration Technologies
 
PPTX
Intro to java 8
John Godoi
 
PPTX
Functional Programming In Jdk8
Bansilal Haudakari
 
PDF
Object oriented-programming-in-c-sharp
Abefo
 
Be armed to the teeth to maintain a high quality iOS code
Anastasia Kazakova
 
How to really obfuscate your pdf malware
zynamics GmbH
 
Intro To AOP
Donald Belcham
 
DIC To The Limit – deSymfonyDay, Barcelona 2014
Ronny López
 
Facilitating Idiomatic Swift with Objective-C
Aaron Taylor
 
QA / Testing Tools, Automation Testing, Online & Classroom Training
AnanthReddy38
 
Tech breakfast 18
James Leone
 
Introduction to mobile reversing
jduart
 
Java introduction
logeswarisaravanan
 
Weaving aspects in PHP with the help of Go! AOP library
Alexander Lisachenko
 
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
David Buck
 
Robot framework - Lord of the Rings
Asheesh Mehdiratta
 
Assignment1 B 0
Mahmoud
 
Does The Delphi IDE Narrow You? Extend It! - ITDevConX European Delphi Confer...
Marco Breveglieri
 
TypeScript Overview
Aniruddha Chakrabarti
 
Introduction to Core Java Programming
Collaboration Technologies
 
Intro to java 8
John Godoi
 
Functional Programming In Jdk8
Bansilal Haudakari
 
Object oriented-programming-in-c-sharp
Abefo
 

Similar to Rootcon X - Reverse Engineering Swift Applications (20)

PPTX
iOS Application Exploitation
Positive Hack Days
 
PDF
CrikeyCon 2015 - iOS Runtime Hacking Crash Course
eightbit
 
PDF
Swift, swiftly
Jack Nutting
 
PDF
Swift2 smalltalk osxdev
Jung Kim
 
PDF
Swift - Under the Hood
C4Media
 
PDF
Advanced Swift Updated For Swift 5 Chris Eidhof
jksjzdl5949
 
PDF
Denis Lebedev, Swift
Yandex
 
PDF
iOS Application Security
Egor Tolstoy
 
PDF
Swift for-rubyists
Michael Yagudaev
 
PDF
The Swift Compiler and Standard Library
Santosh Rajan
 
PPTX
Swift Bengaluru Meetup slides
Pushkar Kulkarni
 
PDF
What Makes Objective C Dynamic?
Kyle Oba
 
PDF
Intro toswift1
Jordan Morgan
 
PDF
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
PDF
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
PDF
Open Source Swift Under the Hood
C4Media
 
PDF
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
PPTX
Swift programming language
Nijo Job
 
PDF
SV-ios-objc-to-swift
Randy Scovil
 
PDF
Swift core
Yusuke Kita
 
iOS Application Exploitation
Positive Hack Days
 
CrikeyCon 2015 - iOS Runtime Hacking Crash Course
eightbit
 
Swift, swiftly
Jack Nutting
 
Swift2 smalltalk osxdev
Jung Kim
 
Swift - Under the Hood
C4Media
 
Advanced Swift Updated For Swift 5 Chris Eidhof
jksjzdl5949
 
Denis Lebedev, Swift
Yandex
 
iOS Application Security
Egor Tolstoy
 
Swift for-rubyists
Michael Yagudaev
 
The Swift Compiler and Standard Library
Santosh Rajan
 
Swift Bengaluru Meetup slides
Pushkar Kulkarni
 
What Makes Objective C Dynamic?
Kyle Oba
 
Intro toswift1
Jordan Morgan
 
iOS NSAgora #3: Objective-C vs. Swift
Alex Cristea
 
Ios 12 Programming Fundamentals With Swift Swift Xcode And Cocoa Basics 5th E...
joettealhadi
 
Open Source Swift Under the Hood
C4Media
 
Using Swift for all Apple platforms (iOS, watchOS, tvOS and OS X)
Aniruddha Chakrabarti
 
Swift programming language
Nijo Job
 
SV-ios-objc-to-swift
Randy Scovil
 
Swift core
Yusuke Kita
 
Ad

More from eightbit (7)

PDF
Defcon 25 Packet Hacking Village - Finding Your Way to Domain Access
eightbit
 
PDF
AusCERT - Developing Secure iOS Applications
eightbit
 
PDF
CrikeyCon 2017 - Rumours of our Demise Have Been Greatly Exaggerated
eightbit
 
PDF
Online Retailer's Conference 2013 - Hacking Mobile Applications - Industry Ca...
eightbit
 
PDF
YOW! Connected 2014 - Developing Secure iOS Applications
eightbit
 
PDF
Ruxmon April 2014 - Introduction to iOS Penetration Testing
eightbit
 
PDF
OWASP Melbourne - Introduction to iOS Application Penetration Testing
eightbit
 
Defcon 25 Packet Hacking Village - Finding Your Way to Domain Access
eightbit
 
AusCERT - Developing Secure iOS Applications
eightbit
 
CrikeyCon 2017 - Rumours of our Demise Have Been Greatly Exaggerated
eightbit
 
Online Retailer's Conference 2013 - Hacking Mobile Applications - Industry Ca...
eightbit
 
YOW! Connected 2014 - Developing Secure iOS Applications
eightbit
 
Ruxmon April 2014 - Introduction to iOS Penetration Testing
eightbit
 
OWASP Melbourne - Introduction to iOS Application Penetration Testing
eightbit
 
Ad

Recently uploaded (20)

PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
Q2 Leading a Tableau User Group - Onboarding
lward7
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
July Patch Tuesday
Ivanti
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Q2 Leading a Tableau User Group - Onboarding
lward7
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
July Patch Tuesday
Ivanti
 

Rootcon X - Reverse Engineering Swift Applications

  • 1. Reverse Engineering Swift Apps Michael Gianarakis Rootcon X 2016
  • 2. # whoami @mgianarakis Director of SpiderLabs APAC at Trustwave SecTalks Organiser (@SecTalks_BNE) Flat Duck Justice Warrior #ducksec
  • 3. Motivation • Seeing more and more Swift being used in apps that we test (fan boys like me tend to adopt new Apple technology quickly) • Google is even considering using Swift as a first class language on Android… (http://thenextweb.com/dd/2016/04/07/google- facebook-uber-swift/) • Wanted to dive into some of the key differences with Swift and look at the challenges with respect to Swift app pen testing • Focus is on “black box” app pen testing - for a deeper dive into Swift language RE I recommend Ryan Stortz’s talk at Infiltrate (http://infiltratecon.com/archives/swift_Ryan_Stortz.pdf)
  • 4. How Does Swift Affect Testing? • Will dive into the detail in the presentation but the reality is not much in most areas, quite a bit in others? • Most issues in iOS and OS X apps are due to poor design decisions or misconfiguration and incorrect implementation of Apple and third party frameworks and libraries. • The main thing that has changed is how you reverse engineer the application
  • 6. What is Swift? • Compiled language created by Apple • Released publicly in 2014 at WWDC and has seen multiple revisions since. • Open source with official implementations for iOS, OS X and Linux. • Intended to replace Objective-C eventually
  • 7. Syntax (just the basics to follow along)
  • 8. Syntax (just the basics to follow along)
  • 9. Syntax (just the basics to follow along)
  • 10. Syntax (just the basics to follow along)
  • 11. Types • All basic C and Objective-C types -> String, Bool, Int , Float etc. • Collection Types -> Array, Set, Dictionary • Optional Types -> works with all types, no more nil pointers like Objective-C • Swift is a type safe language
  • 12. Objective-C Compatibility • Objective-C compatibility and interoperability • Uses the same runtime environment • Still supports C and C++ in the same app but can’t be called from Swift like Objective-C • Can allow for some dynamic features and runtime manipulation
  • 13. Other Language Features • Barely scratched the surface • Structs, Protocols, Extensions, Closures, Enumerations, Optionals, Generics, Type Casting, Access Control, Error Handling, Assertions…. • Automatic Reference Counting • Unicode… • var 💩 = 💩 💩 💩 💩 💩 ()
  • 16. Challenges • Less dynamic than Objective-C • Less flexible than Objective-C in some areas • Can make it harder to do some of the standard tasks you would do on a standard app pen test • Less of an issue now because most Swift apps will include be mixed with Objective-C • Limited tooling • We will explore this in more detail
  • 17. Challenges • Rapidly evolving syntax, APIs and features and Apple doesn’t care too much about breaking changes. • v1.0 - September 2014 • v1.1 - October 2014 • v1.2 - April 2015 • v2.0 - September 2015 (Open Sourced, Linux) • v2.2 - March 2016 • v3.0 - Late 2016
  • 18. Reversing Swift Apps • Two primary reverse engineering activities when conducting a “black box” pen test • Dumping and analysing class information from the binary • Retrieving information at runtime using debuggers, function hooking, tracing etc.
  • 20. Class Dump? • The most common and easiest way to retrieve class data from an Objective-C binary is the class- dump utility • class-dump-z retrieves class information and formats to look like the equivalent of an Objective- C header file • Usually one of the first things you do when looking at an app
  • 23. What next? • So class-dump-z doesn’t work with Swift binaries :( • Now what? • Let’s start diving into the binary
  • 24. Symbol Table • What do we get if we dump the symbol table?
  • 25. Symbol Table • What if we look for something we know is in the binary? • nm -gUj rootcon-demo | grep printDuckType
  • 26. Symbol Table • What if we look for something we know is in the binary?
  • 27. Name Mangling • Looks promising but it’s a far cry from the output of class-dump and is kind of hard to make out • Swift stores metadata about a function in it’s symbols in the process “mangling” the name.
  • 30. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class
  • 31. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length
  • 32. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length Class name with length
  • 33. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length Class name with length Function name with length
  • 34. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length Class name with length Function name with length Function attribute
  • 35. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length Class name with length Function name with length Function attribute Parameters
  • 36. Name Mangling __TFC12rootcon_demo4Duck13printDuckTypefT_T_ Indicates it’s a Swift method Indicates it’s a function Function of a class Module name with length Class name with length Function name with length Function attribute Parameters Return Type
  • 37. Function Attributes f Normal function s Setter g Getter d Destructor D Deallocator c Constructor C Allocator
  • 38. Return Types a Array b Boolean c Unicode Scalar d Double f Float i Integer u Unsigned Integer Q Implicitly Unwrapped Optional S String
  • 39. swift-demangle • So now we know roughly the way the names are mangle you could use this to create a script that “de-mangles” the names • Apple has already thought of that and includes a utility called swift-demangle to do just that
  • 41. swift-demangle • With nm and swift-demangle and some shell scripting you should be able to easily grab the function signatures from an app • Should be all you need to get basically the same information you would from class-dump to start assessing the app
  • 42. class-dump-s • Hacked together script that demangles names and formats the output to approximate the output of class-dump • Written in Swift
  • 43. Demo
  • 44. Stripped Binaries • CAVEAT: If the developer stripped symbols from the binary then these techniques obviously won’t work. • Reverse engineering stripped binaries is a bit more complicated
  • 45. Objective-C Compatibility • Part of the reason it’s much easier to get class information from Objective-C binaries is because it’s necessary for the Objective-C runtime to have that info • So what happens when you import Objective-C frameworks or use Objective-C in your app?
  • 46. Revisiting Class Dump • The latest branch of class-dump by Steven Nygard (the original class-dump utility) has limited support for Swift. • Need to download and build from source (no binary release yet) • https://github.com/nygard/class-dump
  • 48. Demo
  • 53. Other Options • classdump-dyld (successor to weakclassdump.cy) • Disassemblers (i.e. Hopper, IDA Pro) • Necessary for lower level insight into the app • To demangle Swift function names https:// github.com/Januzellij/hopperscripts • cycript? frida?
  • 55. Hooking Swift Methods • Still possible. • Much easier with in mixed Swift/Objective-C binaries. • Can still write tweaks with Mobile Substrate.
  • 57. Hooking Swift Methods • Hooking getter method (works!)
  • 58. Hooking Swift Methods • Hooking setter method (kinda works…)
  • 59. Hooking Swift Methods • Certain functions in Swift are inlined and the class constructor is one of them (which is directly setting the instance variable) • So in this case the setter will only be called again by the top level code. • If you call from there it works.
  • 60. Hooking Swift Methods • Changing the instance variable directly (works but not a good idea probably)
  • 62. Wrap Up • So not all hope is lost when it comes to your standard pen test workflows with Swift apps • A bit more of a pain in the arse if you don’t get access to the source code • Most issues in iOS and OS X apps are due to poor design decisions or misconfiguration and incorrect implementation of Apple and third party frameworks and libraries.
  • 63. Next Steps • Improve the class-dump-s script :) • Remove dependency on swift-demagle • Ivars, stripped binaries? • Runtime inspection • cycript works but not as straightforward as with Objective-C • LLDB works well if you are familiar with it • Will hopefully write a blog post soon
  • 64. Q&A?