DevTeam如何攻克iPhone

Fabien Sanglard 新闻

摘要

一篇关于iPhone Dev Team在2007年夏季越狱和解锁初代iPhone的详细回顾,记录了每一个里程碑及所涉及的技术挑战。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/05/16 03:36

# DevTeam 如何征服 iPhone 来源:https://fabiensanglard.net/iSummer/index.html 2024 年 1 月 31 日 DevTeam 如何征服 iPhone --- 2007 年夏天对于手机爱好者来说是个多事之秋。一切始于 6 月 29 日,苹果发布了 iPhone。如果你还没完整看过那次主题演讲,我强烈推荐你去看看。 您的浏览器不支持视频标签。对发布会的反应褒贬不一。有些人对其不屑一顾,另一些人则跃跃欲试。 我属于后者。不过我住在加拿大,当时 iPhone 的发布日期遥遥无期。事实上,iPhone 从未在加拿大正式发售[\[1\]](https://fabiensanglard.net/iSummer/index.html#footnote_1)。直到一年后,2008 年 7 月 11 日,苹果才与 Rogers 达成协议,推出了 3G 版[\[2\]](https://fabiensanglard.net/iSummer/index.html#footnote_2)。 iPhone Dev Team --- 对于那些被遗忘的国家来说,希望犹存。一群人聚集在一起,目标是通过纯软件手段让 iPhone 能在任何运营商网络下运行[\[3\]](https://fabiensanglard.net/iSummer/index.html#footnote_3)。他们自称“iPhone Dev Team”。 他们通过在 **iphone.fiveforty.net** 上开设博客,定期汇报进展。内容丰富的日子,更新频率甚至达到每小时一次(7 月 3 日从午夜到晚上 9 点发布了八次更新[\[4\]](https://fabiensanglard.net/iSummer/index.html#footnote_4))。 不用说,那个 2007 年的夏天,我的浏览器一直盯着他们的网站。但我并不具备完全理解他们所做工作的技能。参与者都是高手,专业术语满天飞,我一直不敢提问。 没能理解这样一个历史时刻的技术细节,一直让我耿耿于怀。今天我决定借助 Wayback Machine 回到过去,把它弄明白。或许你也愿意跟我一起看看。 iphone.fiveforty.net 状态栏 --- 为了跟踪进展,**iphone.fiveforty.net** 在主页上设置了一个状态栏,列出了 DevTeam 为实现目标而确定的全部里程碑。共有三个完成等级,颜色从红色变为绿色。 我不记得见过它全红,也不确定是否曾全红过。Wayback Machine 抓取到的最早日期是 2007 年 7 月 6 日 (https://web.archive.org/web/20070706064445/http://iphone.fiveforty.net/wiki/index.php?title=Main_Page),当时六个里程碑已完成两个。 破解 DMG 密码绕过激活获取写入权限获取可工作工具链解锁手机启用第三方应用 旅程于 9 月 12 日完成,但 Wayback Machine 直到十三年后的 9 月 25 日 (https://web.archive.org/web/20070925035357/http://iphone.fiveforty.net:80/wiki/index.php?title=Main_Page)才抓取到。 解密固件绕过激活获取写入权限获取可工作工具链启用第三方应用解锁手机 我们将按顺序研究每个阶段。 预期用途 --- 在进入每个里程碑之前,我们先回顾一下 iPhone 的预期使用方式。 1. 用户可从 Apple Store 购买设备,价格分别为 499 美元(4GB 版本)和 599 美元(8GB 版本)[\[5\]](https://fabiensanglard.net/iSummer/index.html#footnote_5)。 2. 开箱后,iPhone 显示一个不可用 (https://fabiensanglard.net/iSummer/activate.jpeg) 的屏幕,提示“连接到 iTunes” (https://fabiensanglard.net/iSummer/itunes.jpg)。 3. 用户必须打开 iTunes 并订阅 ATT 会员 (https://fabiensanglard.net/iSummer/activationtips.pdf)(视频 (https://www.youtube.com/watch?v=SAhRFE4D6W0),文章 (https://archive.is/UjS8d))。 4. 之后手机被激活,但仍锁定 ATT,但用户可以正常使用。 里程碑 --- DevTeam 早期定义的六个里程碑遵循一条合乎逻辑的路径,将一块惰性电子设备变回智能手机。 - 获取读取权限以了解系统 → **破解 DMG 密码**。 - 让设备从休眠中苏醒 → **绕过激活**。 - 获取写入权限以修改系统 → **获取写入权限**。 - 使用自定义可执行文件修改系统 → **获取可工作工具链**。 - 做些事情让基带能连接任意运营商 → **解锁**。 - 创建一款应用来自动化整个过程 → **启用第三方应用** 解密里程碑 --- 要将设备恢复到出厂状态,iTunes 会下载一个 **IP**hone **S**oft**W**are 存档(扩展名 `.ipsw`)。这一步的目标是理解其中的每个文件。方便的是,这个存档仍然可以在 ipsw.me 上找到[\[6\]](https://fabiensanglard.net/iSummer/index.html#footnote_6),它使用 zip 格式,所以我们可以查看它。 `` % unzip -l iPhone1,1_1.0_1A543a_Restore.ipsw Archive: iPhone1,1_1.0_1A543a_Restore.ipsw Length Date Time Name --------- ---------- ----- ---- 15725706 06-26-2007 18:41 694-5259-38.dmg 86257664 06-04-2007 19:32 694-5262-39.dmg 0 05-22-2007 22:25 Firmware/all_flash/ 14474 05-22-2007 22:21 Firmware/all_flash/applelogo.img2 73866 05-22-2007 22:21 Firmware/all_flash/batterycharging.img2 65674 05-22-2007 22:21 Firmware/all_flash/batterylow0.img2 73866 05-22-2007 22:21 Firmware/all_flash/batterylow1.img2 43146 05-22-2007 22:21 Firmware/all_flash/DeviceTree.m68ap.img2 145546 05-22-2007 22:21 Firmware/all_flash/iBoot.m68ap.RELEASE.img2 51338 05-22-2007 22:21 Firmware/all_flash/LLB.m68ap.RELEASE.img2 175 05-22-2007 22:25 Firmware/all_flash/manifest 34954 05-22-2007 22:21 Firmware/all_flash/needservice.img2 26762 05-22-2007 22:21 Firmware/all_flash/recoverymode.img2 103562 05-22-2007 22:25 Firmware/dfu/iBSS.m68ap.RELEASE.dfu 9354 05-22-2007 22:25 Firmware/dfu/WTF.s5l8900xall.RELEASE.dfu 3073247 06-19-2007 13:51 kernelcache.restore.release.s5l8900xrb 1594 06-26-2007 18:41 Restore.plist --------- ------- 105700928 20 files // 整个 iOS 只有 105 MiB!! `` 其中有许多文件,它们的功能早在 (https://fabiensanglard.net/iSummer/index.html#footnote_7)[[8](https://fabiensanglard.net/iSummer/index.html#footnote_8) 较早时 (https://fabiensanglard.net/iSummer/index.html#footnote_9)就被识别出来了。其中包括在恢复过程中屏幕上显示的 `img2` 图像,存放基带相关所有内容的 `Firmware` 文件夹,以及 iOS 内核 (`kernelcache`)。 更重要的是,我们看到了两个巨大的 `dmg` 存档。第一个 `694-5259-38.dmg`(称为 ramdisk[\[10\]](https://fabiensanglard.net/iSummer/index.html#footnote_10))仅在 iTunes 恢复手机时使用。令人惊讶的是,它并未加密。简单的 `dd` 命令即可挂载它。 `` $ dd if=694-5259-38.dmg of=ramdisk.dmg bs=512 skip=4 conv=sync $ hdiutil attach ramdisk.dmg /dev/disk4 /Volumes/ramdisk $ find /Volumes/ramdisk > ramdisk.txt `` 这不是 iOS 文件系统(只有大约 100 个条目 (https://fabiensanglard.net/iSummer/ramdisk.txt)),但它让 DevTeam 能够窥探 `/private/etc/master.passwd`,并找到用户 `mobile`(运行应用程序)和用户 `root`(运行所有其他进程)的密码。 更重要的是,ramdisk 的内容使得访问第二个 dmg 文件 `694-5262-39.dmg` 成为可能,该文件包含正常运行时使用的 iOS 文件系统。这个存档是加密的,但通过在 ramdisk 中查看 `/usr/sbin/asr` 找到了它的密钥。 注意,他们找到的是密钥,而不是密码短语。他们无法使用 `hdiutil`,因此不得不编写自己的解密器 `vfdecrypt.c`[\[11\]](https://fabiensanglard.net/iSummer/index.html#footnote_11)。解密后,这个 img 便可以挂载,他们获得了对完整运行时文件系统的读取权限(文件列表请见 这里 (https://web.archive.org/web/20071005010951/http://iphone.fiveforty.net/wiki/index.php/SystemFileAndDirectoryList#System.2FLibrary.2FExtensions.2F_Source_Files))。 破解 DMG 密码绕过激活获取写入权限获取可工作工具链解锁手机启用第三方应用 激活里程碑 --- 刚开箱的 iPhone 就是一块砖头,尚未激活。用户订阅 ATT 后,会发生以下过程[\[12\]](https://fabiensanglard.net/iSummer/index.html#footnote_12)。 1. iTunes 收集设备的 DeviceID、IMEI 和 ICCID。 2. 将这三个字段拼接成一个令牌。 3. 令牌被发送到苹果服务器 (`albert.apple.com`),在那里用苹果的私钥签名。 4. 签名的令牌被送回设备。 5. 一个通过 USB 监听的守护进程 `lockdownd` (https://iphonedev.wiki/Lockdownd) 使用苹果的公钥验证令牌。 6. 有了令牌来自苹果的证据以及匹配的 DeviceID、IMEI 和 ICCID,`lockdownd` 将设备状态更新为“已激活”。 7. 然后用户就可以访问 iPhone 主屏幕 (https://fabiensanglard.net/iSummer/Apple-iPhone.webp) 和应用程序。 `` ┌─────────┐ │ iPhone │ ├─────────┤ ┌──────┐ ┌────────────────┐ │lockdownd│ │iTunes│ │albert.apple.com│ └────┬────┘ └──┬───┘ └───────┬────────┘ │ │ │ │ 1.dID,IMEI,ICCID │ │ ├─────────────────────►│ │ │ │ 2.Send token │ │ ├─────────────────►│ │ │ │ │ │ 3. f(token) │ │ │◄─────────────────┤ │ │ │ ├──────────────────────┤ │ │ 4.f(iD, IMEI, ICCID) │ │ │ == │ │ │ f(token) ? │ │ │ │ │ ▼ ▼ ▼ ACTIVATED! `` 激活方面的第一个突破来自著名的开发者 dvdjon,他发布了 PhoneActivationServer[\[13\]](https://fabiensanglard.net/iSummer/index.html#footnote_13)。 > dvdjon 通过修补 iTunes,使其对激活服务器使用 HTTP 而非 HTTPS,并将激活请求重定向到 PhoneActivationServer,从而创建了一种激活方法。PhoneActivationServer 随后向 iPhone 发送一个有效的账户令牌。然而,该令牌对应的 IMEI、ICCID 和 DeviceID 与当前设备不符。这种方法使手机处于 MismatchedICCID 状态,但允许访问用户界面。——iPhone Elite Dev Team[\[14\]](https://fabiensanglard.net/iSummer/index.html#footnote_14) 解释的关键是“有效令牌”。在没有私钥的情况下如何生成一个?事实证明,你并不需要。PhoneActivationServer 总是返回同一个从成功激活中捕获的签名令牌(可能是 dvdjon 自己的手机?),无论输入的令牌是什么。这是一个简单的重放技巧。 这一点在 George Hotz 的演讲“Hacking the iPhone”中进一步阐述。 > 将激活记录重新发送到另一部手机,lockdownd 并未检查响应中的 (iD, IMEI, ICCID) 是否真的匹配任何东西。——George Hotz[\[15\]](https://fabiensanglard.net/iSummer/index.html#footnote_15) DevTeam 编写了一个名为 `tools`[\[16\]](https://fabiensanglard.net/iSummer/index.html#footnote_16) 的命令行工具,它从 plist 文件加载一个硬编码的签名令牌,并通过接入 iTunesMobileDevice.dll 函数将其发送给任何 iPhone(后来改进为独立的 `iPhoneInterface`,无需 iTunes)。该工具附带了源代码 (https://att.newsmth.net/nForum/#!article/Apple/178321),如果你愿意,可以自己查看。 破解 DMG 密码绕过激活获取写入权限获取可工作工具链解锁手机启用第三方应用 写入权限里程碑 --- 激活后的手机将在 iTunes GUI 中出现,用户可以上传音乐和照片等文件。所以存在“某种”写入权限。但负责文件上传的进程 (`acfd`) 被 `chroot` 禁锢在 `/root/Media`[\[17\]](https://fabiensanglard.net/iSummer/index.html#footnote_17)。此外,只有用户分区以“rw”方式挂载,系统分区仅以“r”方式挂载。因此,双重目标是:逃出 `chroot` 监狱(“越狱”一词由此而来)并且能够写入系统分区。 `` ┌──────┐ │iPhone│ ┌──────┐ ├──────┤ │iTunes│ │ acfd │ └──┬───┘ └──┬───┘ │ │ │ write(file) │ ├──────────────►│ │ │ │ │ │ chroot │ │ │ ▼ ▼ /root/Media `` 团队似乎在 2007 年 7 月 8 日左右找到了解决方案[\[18\]](https://fabiensanglard.net/iSummer/index.html#footnote_18),并描述了一个涉及 ramdisk 的过程[\[19\]](https://fabiensanglard.net/iSummer/index.html#footnote_19)。 要理解其工作原理,我们需要了解 iPhone 的两种启动方式。手机启动时执行的第一条指令来自 BootROM。从此开始,一系列加载程序引导越来越复杂的阶段。注意,在启动新阶段之前,会检查其签名,因此只有苹果签名的程序才能运行。这个过程建立了一条信任链,一直延伸到运行应用程序的 Darwin 内核。 `` 正常操作启动链: ┌───────┐ ┌───┐ ┌─────┐ ┌──────┐ ┌───────────┐ │BootROM├────►│LLB├─────►│iBoot├─────►│Kernel├─────►│Normal Mode│ └───────┘ └───┘ └─────┘ └──────┘ └───────────┘ `` 还有第二种启动模式,允许 iTunes 将手机从不良状态恢复到良好状态。当手机以恢复模式启动时,它停留在 iBoot 阶段[\[20\]](https://fabiensanglard.net/iSummer/index.html#footnote_20)。此时手机期望下一阶段从 RAM 加载(所以我们现在明白了名为“ramdisk”的 dmg 存档,它是一个旨在上传到 RAM 的磁盘)。 `` 恢复模式启动链: ┌──────────────────────────────────┐ │ iTunes │ └───┬───────────┬───────────┬──────┘ │ │ │ push files to ▼ ▼ ▼ restore iOS ┌───────┐ ┌───┐ ┌─────┐ ┌───────┐ ┌──────┐ ┌───────────┐ │BootROM├────►│LLB├─────►│iBoot├───x│ramdisk├──►│Kernel├───►│RestoreMode│ └───────┘ └───┘ └─────┘ └───────┘ └──────┘ └───────────┘ `` DevTeam 查看了 `iTunesMobile.dll`,以了解 iTunes 如何写入文件系统来执行恢复。他们发现了诸如 `mount`、`umount` 和 `ditto`(用于复制文件)等命令,并编写了一个名为 iPHUC (https://github.com/svn2github/iphuc) 的命令行工具,能够通过 `iTunesMobile.dll` 的私有方法与处于恢复模式下的设备通信[\[21\]](https://fabiensanglard.net/iSummer/index.html#footnote_21)。 `iPHUC` 的源代码后来被公开,我们可以查看其工作原理。 1. 用户将手机置于恢复模式。 2. 向手机发送 ramdisk(grestore 命令) (https://github.com/svn2github/iphuc/blob/master/RecoveryInterface.cpp#L77C8-L77C24)[\[22\]](https://fabiensanglard.net/iSummer/index.html#footnote_22)[\[23\]](https://fabiensanglard.net/iSummer/index.html#footnote_23)。 3. 将 ramdisk 加载到手机 RAM 中。 (https://github.com/svn2github/iphuc/blob/df564835edd8a65f6c9e08fc5e837815bd546775/RecoveryInterface.cpp#L87) 4. 发送 kernelcache。 (https://github.com/svn2github/iphuc/blob/df564835edd8a65f6c9e08fc5e837815bd546775/RecoveryInterface.cpp#L100C5-L100C25) 5. 引导内核 poi

相似文章

我把我的真iPhone交给了我的智能体..

Reddit r/openclaw

一位开发者创建了一种方法,让AI智能体通过API控制真实iPhone,实现起草iMessage、运行iOS快捷指令和移动应用测试等任务。他们提供了70部手机供实验使用。