exploiting common vulnerabilities on ios apps · agenda • reverse engineering an ios app. •...

82
Common Vulnerabilities on iOS Apps by ivan r QconSF @ivRodriguezCA

Upload: others

Post on 11-Jan-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Common Vulnerabilities on iOS Appsby ivan rQconSF

@ivRodriguezCA

@ivRodriguezCA

DISCLAIMER

the views and opinions expressed on this talk are solely my own and do not reflect the views or

opinions of my employer.

@ivRodriguezCA

ivan_rodriguez.me• security researcher and software engineer

• focused on iOS reverse engineering and mobile bug bounty programs

• i blog at ivrodriguez.com

• find me on twitter : @ivRodriguezCA

• find me on github: /ivRodriguezCA

@ivRodriguezCA

agenda• reverse engineering an iOS app.

• tools and methods.

• common iOS vulnerabilities (all found on real world applications).

• how to fix and prevent these vulnerabilities.

• resources / conclusions.

• questions.

@ivRodriguezCA

reverse engineering an iOS app• iOS apps are encrypted with an algorithm called FairPlay.

• we need a jailbroken device.

• we don’t “decrypt” the apps, we just dump them from memory.

• transfer them to a desktop where we do the reverse engineering.

@ivRodriguezCA

reverse engineering an iOS app• how we dump the app from memory?

> dump memory <filename> <start_address> <end_address>

@ivRodriguezCA

reverse engineering an iOS app• how we dump the app from memory?

> dump memory <filename> <start_address> <end_address>

• we can use tools to automate this.

@ivRodriguezCA

reverse engineering an iOS app• some of the tools we can use:

- dumpdecrypted: https://github.com/stefanesser/dumpdecrypted

- bfinject: https://github.com/BishopFox/bfinject

- frida-ios-dump: https://github.com/AloneMonkey/frida-ios-dump

@ivRodriguezCA

reverse engineering an iOS app

@ivRodriguezCA

reverse engineering an iOS app

@ivRodriguezCA

reverse engineering an iOS app

@ivRodriguezCA

reverse engineering an iOS app• dynamic and static analysis

@ivRodriguezCA

reverse engineering an iOS app• dynamic and static analysis

@ivRodriguezCA

reverse engineering an iOS app• dynamic and static analysis

@ivRodriguezCA

vulnerability # 1• searching through embedded files within the app

@ivRodriguezCA

vulnerability # 1

@ivRodriguezCA

vulnerability # 1private_key

@ivRodriguezCA

vulnerability # 1private_key

yes, PRIVATE key

@ivRodriguezCA

vulnerability # 1cloud server

@ivRodriguezCA

vulnerability # 1cloud server

@ivRodriguezCA

vulnerability # 1cloud server

@ivRodriguezCA

vulnerability # 1cloud server

ssh

@ivRodriguezCA

vulnerability # 1cloud server

ssh!

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

public api

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

ssh

@ivRodriguezCA

how to fix vulnerability # 1cloud server own server

ssh

@ivRodriguezCA

vulnerability # 2

@ivRodriguezCA

vulnerability # 2

@ivRodriguezCA

vulnerability # 2

@ivRodriguezCA

vulnerability # 2

@ivRodriguezCA

vulnerability # 2

@ivRodriguezCA

@ivRodriguezCA

vulnerability # 2• coinza://news/<trusted-html>

@ivRodriguezCA

vulnerability # 2• coinza://news/<trusted-html>

- <html><body><script>document.location = ‘https://en.wikipedia.org/wiki/URL_redirection’;</script></body></html>

@ivRodriguezCA

vulnerability # 2• coinza://news/<trusted-html>

- <html><body><script>document.location = ‘https://en.wikipedia.org/wiki/URL_redirection’;</script></body></html>

coinza://news/%3Chtml%3E%3Cbody%3E%3Cscript%3Edocument.location%20%3D%20%27https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FURL_redirection%27%3B%3C%2Fscript%3E%3C%2Fbody%3E%3C%2Fhtml%3E

@ivRodriguezCA

how to fix vulnerability # 2

@ivRodriguezCA

how to fix vulnerability # 2

!

@ivRodriguezCA

how to fix vulnerability # 2• URL Schemes + WebViews are dangerous and you should be careful

when you pair them.

• don’t load HTML code from user-controlled content.

• if you need to dynamically react to URL Schemes have a set of whitelisted actions.

@ivRodriguezCA

@ivRodriguezCA

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

== ?

@ivRodriguezCA

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

🛑

@ivRodriguezCA

vulnerability # 3

🛑

🚫

@ivRodriguezCA

vulnerability # 3

🛑

@ivRodriguezCA

vulnerability # 3

🛑

website.com

@ivRodriguezCA

vulnerability # 3

🛑

username/password

@ivRodriguezCA

vulnerability # 3

🛑

@ivRodriguezCA

@ivRodriguezCA

vulnerability # 3

@ivRodriguezCA

vulnerability # 3

detected connection to a website

@ivRodriguezCA

vulnerability # 3

creates fake TLS certificate

@ivRodriguezCA

vulnerability # 3

sniffs client traffic

@ivRodriguezCA

how to fix vulnerability # 3• vet and test your 3rd party frameworks, specially if they handle your

network requests.

• be careful when implementing your own certificate validation logic.

• if you want to implement HPKP you can use TrustKit:

- https://github.com/datatheorem/TrustKit

@ivRodriguezCA

how to fix vulnerability # 3

@ivRodriguezCA

source: https://cheatsheetseries.owasp.org/cheatsheets/Pinning_Cheat_Sheet.html

vulnerability # 4

@ivRodriguezCA

vulnerability # 4

@ivRodriguezCA

vulnerability # 4

@ivRodriguezCA

vulnerability # 4

@ivRodriguezCA

vulnerability # 4

@ivRodriguezCA

vulnerability # 4• these methods are equivalent for local files

@ivRodriguezCA

vulnerability # 4

@ivRodriguezCA

vulnerability # 4

file: sqlcipher.dbpath: Documents/

@ivRodriguezCA

vulnerability # 4

send file to aremote location.

@ivRodriguezCA

vulnerability # 4• coinza://news/

%3Chtml%3E%0A%20%20%20%3Cbody%3E%0A%20%20%20%20%20%20%3Cscript%3E%0A%20%20%20%20%20%20%20%20%20function%20loadFile%28%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20xmlhttp%20%3D%20new%20XMLHttpRequest%28%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20documentsPath%20%3D%20document.URL.split%28%27%2F%27%29.slice%280%2C%20-1%29.join%28%27%2F%27%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20filePath%20%3D%20documentsPath%20%2B%20%27%2F%27%20%2B%20%27sqlcipher.db%27%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20xmlhttp.onreadystatechange%20%3D%20function%28%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20%28xmlhttp.readyState%20%3D%3D%204%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20%28xmlhttp.responseText.length%20%3E%200%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert%28%27Got%20file%20%5C%27sqlcipher.db%5C%27%2C%20size%3A%20%27%20%2B%20xmlhttp.responseText.length%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20xmlhttp.onerror%20%3D%20function%28%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alert%28%27Error%21%20%27%20%2B%20filePath%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20xmlhttp.open%28%27GET%27%2C%20filePath%2C%20true%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20xmlhttp.send%28%29%3B%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20window.onload%20%3D%20loadFile%3B%0A%20%20%20%20%20%20%3C%2Fscript%3E%0A%20%20%20%20%20%20%3Cp%3E%0A%20%20%20%20%20%20%20%20%20Hello%20World%0A%20%20%20%20%20%20%3C%2Fp%3E%0A%20%20%20%3C%2Fbody%3E%0A%3C%2Fhtml%3E

@ivRodriguezCA

@ivRodriguezCA

how to fix vulnerability # 4• do not use UIWebView anymore, use WKWebView instead.

• if you absolutely have to use UIWebView:

- do not use - (void)loadRequest:(NSURLRequest *)request for local files.

- Use - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL with an URL object created with [URLWithString:@“about:blank”].

-

@ivRodriguezCA

conclusions• add security assessments to your release cycles.

• keep your 3rd party libraries up to date.

• be careful copy-pasting code from online sources.

• have a public bounty program or at least public channels for responsible disclosures.

@ivRodriguezCA

resources• OWASP - Mobile Application Security Verification Standard

https://github.com/OWASP/owasp-masvs

• OWASP - The Mobile Security Testing Guide https://github.com/OWASP/owasp-mstg

• Resources Page of my course https://github.com/ivRodriguezCA/RE-iOS-Apps/blob/master/Resources.md

@ivRodriguezCA

resources• for a more detailed guide visit:https://github.com/ivRodriguezCA/RE-iOS-Apps

@ivRodriguezCA

@ivRodriguezCA

@ivRodriguezCA

questions?

@ivRodriguezCA

thank you!

@ivRodriguezCA