When downloading from the App store the Executable code is encrypted. Apple uses a custom DRM technology called FairPlay. To decrypt it it needs to be run then dumped from memory.
- The Decryption key is associated with the Apple Id that downloaded the application.
- The Private key is stored on the iOS device when signing into the apple store.
- The decryption keys are in the SC_Info folder.
>>> python2 dump.py -o Test\ App\ 13.19043.32_decrypted.ipa com.test.iphone.app/usr/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.m.add_string(self.Q_C.public_numbers().encode_point())
/usr/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
self.curve, Q_S_bytes
/usr/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
hm.add_string(self.Q_C.public_numbers().encode_point())
Start the target app com.test.iphone.app
Dumping Test App to /tmp
[frida-ios-dump]: IntuneMAMWalledGarden.framework has been loaded.
start dump /var/containers/Bundle/Application/D9187540-72A8-465E-88E5-E86C9ADD6B0D/mscrmapp.app/mscrmapp
mscrmapp.fid: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 6.82M/6.82M [00:00<00:00, 15.9MB/s]
start dump /private/var/containers/Bundle/Application/D9187540-72A8-465E-88E5-E86C9ADD6B0D/mscrmapp.app/Frameworks/IntuneMAMWalledGarden.framework/IntuneMAMWalledGarden
IntuneMAMWalledGarden.fid: 100%|██████████████████████████████████████████████████████████████████████████████████████████| 5.27M/5.27M [00:00<00:00, 20.9MB/s]
Resources.strings: 53.3MB [00:09, 5.73MB/s]
0.00B [00:00, ?B/s]
Generating "13.19043.32_decrypted.ipa"
cd /electra/bfinjectbash ./bfinject -P RubyBrowser.app -l dylibs/bfdecrypt.dylib
Use Netcat to copy the file to an IPA file:
>>> nc 172.20.10.6 31336 > decrypted.ipa>>> ls -l decrypted.ipa-rw-r--r-- 1 carl wheel 14649063 Jan 25 16:57 decrypted.ipa>>> file decrypted.ipadecrypted.ipa: iOS App Zip archive data, at least v2.0 to extract
Drag the target application IPA file (from GUI application, such as Explorer or Finder) into the Impactor window
Enter the throw-away Apple ID credentials when prompted
Navigate (on the iOS device) to Settings > General > Profiles or Profiles & Device Management and tap the profile listed with the email address associated with your Apple ID
Choose “Trust [APPLE ID]” and tap through warnings
Choose “Verify App” and tap through warnings
Changes Signature files which may affect the application
Do it manually - a good white-paper to understand it:
# create a backup of the IPA file - so if something goes wrong you can restartcp<IPA_FILE><IPA_FILE>.bak# unzip the fileunzip<IPA_FILE># download last version of frida-gadgetcurl -Ohttps://build.frida.re/frida/ios/lib/FridaGadget.dylibmv FridaGadget.dylib Payload/<CLIENT_APP>/
# patch the binary to load frida-gadget upon startupinsert_dylib --strip-codesig --inplace @executable_path/FridaGadget.dylib Payload/<CLIENT_APP>/<CLIENT_BIN>zip -r<CLIENT_APP>.ipa Payload
# it overrides your IPA file -> make sure to have a backup of the file first./bin/applesign.js -i<CODE_SIGN_ID>-c -m<MOB_PROVISION_FILE><IPA_FILE>
Get Developer account CODE_SIGN_ID:
# retrieve your signing IDs>>> security find-identity -v -p codesigning1)0A765C06838ED4FD[REMOVED]"Apple Development: <emailaddress> (SHORTHASH)"1 valid identities found
Get MOB_PROVISION_FILE:
<MOB_PROVISION_FILE> - Create a hello-world project in xcode and run it. Grab the mobile provision file using xcode. How to find it’s described in the white-paper above
Get ENTITLMENTS_FILE:
# fetch ents from the unencrypted IPA file unzippedcodesign -d --entitlements :- "Payload/<CLIENT_APP>"> ents.xml# you need to manually update the Team ID value in this ents.xml, according to your mobile# provision file. You can use the ID of the hello-world app you created with xcode# The ID is usually the value in all capital letters/numbers.# use vim# :%s/<CLIENT_APP_ID>/<YOUR_APP_ID>/g
# to launch the app in debug mode/var/root/debugserver 0.0.0.0:6666 -x auto /var/containers/Bundle/Application/4F2E06A0-B1C7-4F08-A00A-55644FEC55FE/DuoMobileApp.app/DuoMobileApp# otherwise just wait for lldb/var/root/debugserver 0.0.0.0:6666
Connect to the iOS Device from a Mac:
(lldb) platform select remote-ios(lldb) process connect connect://<DEVICE_IP>:6666(lldb) process attach --name<CLIENT_APP>--wait-for