iOS Testing Environment

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

Apple Developer Program

A provisioning identity is a collection of public and private keys that are associated an Apple developer account. In order to sign apps you need to pay 99$/year to register in the Apple Developer Program to get your provisioning identity. Without this you won’t be able to run applications from the source code in a physical device. Another option to do this is to use a jailbroken device.

Starting in Xcode 7.2 Apple has provided an option to create a free iOS development provisioning profile that allows to write and test your application on a real iPhone. Go to Xcode –> Preferences –> Accounts –> + (Add new Appli ID you your credentials) –> Click on the Apple ID created –> Manage Certificates –> + (Apple Development) –> Done
__Then, in order to run your application in your iPhone you need first to indicate the iPhone to trust the computer. Then, you can try to run the application in the mobile from Xcode, but and error will appear. So go to Settings –> General –> Profiles and Device Management –> Select the untrusted profile and click “Trust”.

On iOS 16+, Developer Mode must also be enabled on the device before locally installed development-signed applications (or apps re-signed with get-task-allow) will run. This option only appears after pairing the device with Xcode or after installing a development-signed app once. The flow is: pair the device, trigger an install from Xcode, then enable Settings –> Privacy & Security –> Developer Mode, reboot, and confirm the prompt after unlock.

Note that applications signed by the same signing certificate can share resources on a secure manner, like keychain items.

The provisioning profiles are stored inside the phone in /Library/MobileDevice/ProvisioningProfiles

Modern host-side device tooling

For current iOS testing, the host tooling is increasingly split between:

  • xcrun simctl for simulator management
  • xcrun xctrace list devices to enumerate simulators and physical devices
  • xcrun devicectl (Xcode 15+) to interact with paired physical devices from the command line

Useful examples:

# List booted simulators
xcrun simctl list | grep Booted

# List all visible devices/simulators
xcrun xctrace list devices

# List paired physical devices (Xcode 15+)
xcrun devicectl list devices

devicectl は、Xcode を開かずにテストビルドをインストールまたは起動する必要がある自動化パイプラインで特に便利です:

xcrun devicectl device install app --device <udid> <path_to_app_or_ipa>
xcrun devicectl device launch app --terminate-existing --device <udid> <bundle_id>

Keep Xcode updated when testing iOS 17+ devices. Apple moved developer services to the CoreDevice stack and also changed how Developer Disk Images are handled, so outdated host tooling frequently fails with pairing, image-mounting, or app-launch errors.

シミュレータ

Tip

シミュレータはエミュレータと同じではないことに注意してください。シミュレータはデバイスや機能の挙動を模擬するだけで、それらを実際に使用するわけではありません。

シミュレータ

最初に知っておくべきことは、simulator 内での pentest は jailbroken device で行う場合よりもはるかに制限されるという点です。

iOS アプリをビルド・サポートするために必要なすべてのツールは 公式には Mac OS のみでサポートされています。
Apple の事実上の iOS アプリ作成/デバッグ/インストゥルメント用ツールは Xcode です。これは simulators やビルド/test に必要な異なる SDK versions といった他のコンポーネントをダウンロードするためにも使用できます。
Xcode は 公式 app store から download することを強く推奨します。その他のバージョンにはマルウェアが含まれている可能性があります。

The simulator files can be found in /Users/<username>/Library/Developer/CoreSimulator/Devices

シミュレータは依然として、filesystem artifacts, NSUserDefaults, plist parsing, custom URL schemes, および basic runtime instrumentation の簡易テストには非常に有用です。ただし、シミュレータは pentest 中にしばしば重要となるいくつかの物理デバイスのセキュリティ特性(Secure Enclave, baseband, 特定の keychain access-control behaviours, 現実的な biometric flows, および jailbreak 固有の実行条件など)をエミュレートしない点に注意してください。

To open the simulator, run Xcode, then press in the Xcode tab –> Open Developer tools –> Simulator
__In the following image clicking in “iPod touch […]” you can select other device to test in:

シミュレータ内のアプリケーション

Inside /Users/<username>/Library/Developer/CoreSimulator/Devices you may find all the installed simulators. If you want to access the files of an application created inside one of the emulators it might be difficult to know in which one the app is installed. A quick way to find the correct UID is to execute the app in the simulator and execute:

xcrun simctl list | grep Booted
iPhone 8 (BF5DA4F8-6BBE-4EA0-BA16-7E3AFD16C06C) (Booted)

Once you know the UID the apps installed within it can be found in /Users/<username>/Library/Developer/CoreSimulator/Devices/{UID}/data/Containers/Data/Application

However, surprisingly you won’t find the application here. You need to access /Users/<username>/Library/Developer/Xcode/DerivedData/{Application}/Build/Products/Debug-iphonesimulator/

And in this folder you can find the package of the application.

Emulator

Corellium は唯一の公開されている iOS エミュレータです。これは企業向けの SaaS ソリューションで、ユーザー毎のライセンスモデルを採用しており、トライアルライセンスは提供されていません。

No Jailbreak needed

非 jailbroken デバイスで iOS アプリを pentest する方法については、以下のブログ記事を参照してください:

iOS Pentesting withuot Jailbreak

Jailbreaking

Apple は iPhone 上で動作するコードが Apple 発行の証明書で署名されていること を厳格に要求しています。Jailbreaking はこのような制限や OS によるその他のセキュリティ制御を積極的に 回避する(circumventing) プロセスです。したがって、デバイスが jailbroken になると、アプリのインストールを検査する責任を持つ integrity check がパッチされ、bypassed されます。

Tip

Android と違い、iOS では署名されていない/信頼されていないコードをデバイス上で実行するために “Developer Mode” に切り替えることはできません。

Android Rooting vs. iOS Jailbreaking

しばしば比較されますが、Android の rooting と iOS の jailbreaking は根本的に異なるプロセスです。Android デバイスの rooting は su バイナリのインストールrooted なカスタム ROM にシステムを置き換えることを伴う場合があり、ブートローダーがアンロックされていれば必ずしもエクスプロイトを必要としないこともあります。Flashing custom ROMs はブートローダー解除後にデバイスの OS を置き換えるもので、場合によってはエクスプロイトを要することもあります。

これに対して、iOS デバイスはブートローダーが Apple によって署名されたイメージのみを起動するよう制限されているため、カスタム ROM をフラッシュすることはできません。Jailbreaking iOS は Apple のコード署名保護を回避して未署名コードを実行することを目的としており、Apple の継続的なセキュリティ強化によって複雑化しています。

Jailbreaking Challenges

Apple が脆弱性を迅速に修正するため、iOS の jailbreaking はますます難しくなっています。iOS のダウングレードはリリース直後の限られた期間のみ可能であり、jailbreaking は時間的制約のある作業です。セキュリティテストに使用するデバイスは、再度 jailbreak 可能であることが保証されない限りアップデートすべきではありません。

iOS のアップデートは challenge-response 機構(SHSH blobs) によって制御されており、Apple が署名したレスポンスがある場合にのみインストールが許可されます。この仕組みは「signing window」として知られ、OTA ファームウェアパッケージを保管して後で使用する能力を制限します。現在の signing window を確認するためのリソースとしては IPSW Downloads website があります。

Jailbreak Varieties

  • Tethered jailbreaks は再起動するたびにコンピュータ接続が必要です。
  • Semi-tethered jailbreaks はコンピュータなしで非-jailbroken モードで起動できます。
  • Semi-untethered jailbreaks はコンピュータを使わず手動で再度 jailbreak を行う必要があります。
  • Untethered jailbreaks は再適用を必要としない恒久的な jailbreak を提供します。

Jailbreaking Tools and Resources

Jailbreaking ツールは iOS のバージョンやデバイスによって異なります。最新情報を得るためには Can I Jailbreak?The iPhone WikiReddit Jailbreak などのリソースが有用です。例としては:

  • Checkra1n — 古い A7-A11 / iOS 12-14 世代のリサーチデバイス向け。
  • Palera1n — checkm8 対応デバイス(A8-A11)で iOS/iPadOS 15 以降向け。
  • Dopamine — 多くの arm64/arm64e デバイスで iOS 15/16 を対象としたモダンな rootless jailbreak。
  • Unc0ver — 主に古い iOS バージョン(最大 14.8 まで)で有用。

デバイスの改変にはリスクが伴うため、jailbreaking は慎重に行ってください。

Rootless jailbreaks

最近の iOS 15+ の jailbreak は多くの場合 rootless であり、従来の rootful とは異なります。テスターの観点では、古いガイドの多くが jailbreak ファイルが //Library/... に直接存在すると仮定しているため、これは重要な違いです。

  • Rootless jailbreaks はシールドされたシステムボリュームを直接変更することを避けます。
  • palera1n では、jailbreak ファイルは通常 /private/preboot/... 内のランダム化されたパスに保存され、安定したシンボリックリンク /var/jb を介して露出されます。
  • Tweaks、launch daemons、補助バイナリは多くの場合レガシーな rootful ロケーションではなく /var/jb の下に存在する可能性があります。

これは environment validationFrida setup、および jailbreak detection bypass に直接影響します:

  • ツールが正しくインストールされたか確認する際は、旧来のパスと /var/jb の両方を確認してください。
  • アプリの jailbreak 検出ロジックを見直す際は、現代のチェックが Cydia.app のような従来の指標に加えて rootless の痕跡やシンボリックリンクを探していることを忘れないでください。
  • サードパーティのスクリプトや tweak が rootful なファイルシステムレイアウトを前提としている場合、rootless デバイス上で静かに失敗することがあります。

Jailbreaking Benefits and Risks

Jailbreaking は OS によるサンドボックス制約を取り除き、アプリがファイルシステム全体にアクセスできるようにします。この自由により未承認アプリのインストールやより多くの API へのアクセスが可能になります。しかし一般ユーザにとっては、jailbreaking はセキュリティリスクやデバイスの不安定化を引き起こす可能性があるため 推奨されません

After Jailbreaking

iOS Basic Testing Operations

Jailbreak Detection

Several applications will try to detect if the mobile is jailbroken and in that case the application won’t run

  • Jailbreak 後、iOS では通常 files and folders がインストールされます。これらを検索することでデバイスが jailbroken かどうかを判定できます。
  • 現代の rootless jailbreak では、これらのファイルは /var/jb 下に現れるか、/private/preboot/... へのシンボリックリンクを通じて解決されることがあり、従来の rootful な場所だけに存在するわけではありません。
  • Jailbroken デバイスではアプリがサンドボックス外の新しいファイルに read/write access を持つようになります。
  • 一部の API calls挙動が異なる ことがあります。
  • OpenSSH サービスの存在
  • /bin/sh を呼び出すと 0 ではなく 1 を返す ことがある

More information about how to detect jailbreaking here.

You can try to avoid this detections using objection’s ios jailbreak disable

Jailbreak Detection Bypass

  • You can try to avoid this detections using objection’s ios jailbreak disable
  • You could also install the tool Liberty Lite (https://ryleyangus.com/repo/). Once the repo is added, the app should appear in the ‘Search’ tab

References

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする