IOS Appsec
IOS Appsec
• GitHub: https://github.com/prateekg147
• GitHub: https://github.com/dineshshetty/
Victim App
Remote Web Server
Remote
Other APPS Datastores
Other Devices
© 2020 Prateek Gianchandani & Dinesh Shetty
Mobile Security Introduction Mobile
Avenues of Attack
• Sensitive information stored in the APK/IPA client Binary
• Spywares (1-click or 0-click attacks)
• Vulnerabilities between APP <-> Server
• Vulnerabilities in Mobile Browsers
• Vulnerabilities related to data stored in application sandbox
• Vulnerabilities in the APP during runtime
• Vulnerabilities between APP <-> APP (IPC)
• Vulnerabilities in the Web Server
• Vulnerabilities in the Remote Datastores (AWS etc)
Bootrom `````
LLB iBoot Kernel
EL0 UserSpace
Source: https://siguza.github.io/psychicpaper/
• Used by Apple for iOS/OSX and also Cocoa , Cocoa Touch etc
• Methods starting with + are class methods and those starting with - are
instance or object methods.
Calling Methods
[self doSomething];
[MainViewController performTaskWithID:[NSNumber numberWithInt:1]];
• This list is a dictionary, where the keys are the method name and the
value is a pointer to the methods implementation in memory
• This connection is determined at runtime rather than compile time
developer.apple.com/xcode/
• Pages that are writable cannot be marked executable at the same time
• To repackage the binary, just compress the Payload folder and rename
it from Payload.zip to AppName.ipa. Depending on the JB device you
install, you might need to sign the app before installing.
• Data protected using Secure Enclave, and never leaves the device
apt-get -y update
apt-get -y install unzip
apt-get -y install mobilesubstrate
apt-get -y install python3
wget http://damnvulnerableiosapp.com/t.zip
unzip t.zip
cd iOS-Device-Tools/
cp jtool2 /usr/bin/ && cp keychain_dumper /usr/bin/ && cp debugserver /usr/bin/ && cp binbag /usr/bin/ && chmod +x /usr/bin/binbag && cp rop /usr/bin/ && cp vuln /usr/bi
chmod +x /usr/bin/keychain_dumper
appinst DamnVulnerableiOSApp.ipa
appinst DVIA-v2-swift.ipa
killall -9 backboardd
https://developer.apple.com/documentation/code_diagnostics/address_sanitizer/enabling_the_address_sanitizer
Source: https://blog.elcomsoft.com/2019/11/
ios-device-acquisition-with-checkra1n-jailbreak/
Source: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/
FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW
© 2020 Prateek Gianchandani & Dinesh Shetty
iOS partitions
• NEEDLE – https://github.com/mwrlabs/needle
• APPMon - https://github.com/dpnishant/appmon
• Objection - https://github.com/sensepost/objection
if (ObjC.available){
var classname = "LoginValidate";
var methodname= "isLoginValidated";
var hook = ObjC.classes[classname][methodname];
Interceptor.attach(hook.implementation,
{ onLeave: function(retvalue)
{
newretvalue = ptr("0x1");
retvalue.replace(newretvalue);
console.log("\nNewReturnValue:" + retvalue + "\"]"); } });
}
© 2020 Prateek Gianchandani & Dinesh Shetty
Bypass Login Check in DVIA-v2
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
© 2020 Prateek Gianchandani & Dinesh Shetty
Frida – Logging iOS Method Arguments
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
© 2020 Prateek Gianchandani & Dinesh Shetty
Frida – Logging iOS Method Arguments
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
© 2020 Prateek Gianchandani & Dinesh Shetty
Frida – Logging iOS Method Arguments
Source - http://www.mopsled.com/2015/log-ios-method-arguments-with-frida/
• https://github.com/Nightbringer21/fridump
Interceptor.attach(servertrusthook.implementation, {
onLeave: function(returnvalue) {
returnvalue.replace(ptr(1));
}
});
• Make sure to set the specific architecture for which the binary is compiled
typedef int (*ptrace_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
#if !defined(PT_DENY_ATTACH)
#define PT_DENY_ATTACH 31
#endif
void disable_debugger() {
void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
ptrace_ptr_t ptrace_ptr = dlsym(handle, "ptrace");
ptrace_ptr(PT_DENY_ATTACH, 0, 0, 0);
dlclose(handle);
}
• Location in file system is /private/var/mobile/Containers/Data/Application/
<APP ID>/Documents/userInfo.plist
Source: https://developer.apple.com/documentation/security/keychain_services/keychain_items/
item_attribute_keys_and_values#1679100
© 2020 Prateek Gianchandani & Dinesh Shetty
Touch ID to fetch Keychain items
Can be implemented by using LocalAuthentication or Security framework
Even though keychain is one of the most secure places to store information,
consider adding an extra layer of encryption before saving data in the
application to make the job for the attacker more difficult.
© 2020 Prateek Gianchandani & Dinesh Shetty
Keychain dumper in iOS 13
Need to sign with the following entitlements.xml file
• Device logs should only be enabled for DEBUG mode in the application, this
will ensure that the logs are disabled when the application is downloaded
from the App store and run on a user’s device.
© 2020 Prateek Gianchandani & Dinesh Shetty
Disabling Device Logs
Add the following code in the Precompiled header file , usually with the name
PrefixHeader.pch
#ifdef DEBUG
# define NSLog (...) NSLog(__VA_ARGS__)
#else
# define NSLog (...)
#endif
• Use pasteboard with specific identifiers, this makes it difficult for other
applications to fetch data from this pasteboard item.
Source: https://www.macrumors.com/2020/07/06/reddit-app-
clipboard-snooping-fix-coming/
Source: https://www.infoq.com/news/2020/07/ios-clipboard-bug/
• https://support.apple.com/en-ae/HT204477
https://medium.com/ios-os-x-development/security-flaw-with-uiwebview-95bbd8508e3c
Source: https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller
#if !(TARGET_IPHONE_SIMULATOR)
return YES;
return YES;
return YES;
return YES;
return YES;
}
NSError *error;
encoding:NSUTF8StringEncoding error:&error];
if(error==nil){
//Device is jailbroken
return YES;
} else {
//Device is jailbroken
return YES;
#endif
//All checks have failed. Most probably, the device is not jailbroken
r2 -Aw DVIA-v2 - Open with write mode and analyse (takes some time)
i - Show info of current file
iz - Print strings in the data section
izz - Print strings in the whole binary
s main - Seek to the main function
pdf - Print disassembled version of the main function
Source: https://github.com/MobSF/Mobile-Security-Framework-MobSF
© 2020 Prateek Gianchandani & Dinesh Shetty
Objection