diff --git a/include/device/chip_db_table.h b/include/device/chip_db_table.h index 9468fb7..8b681fb 100644 --- a/include/device/chip_db_table.h +++ b/include/device/chip_db_table.h @@ -40,11 +40,11 @@ static const chip_info_t g_chip_table[] = { .payload_dest_armv7 = 0x34039800, }, - /* CPID 0x8950 -- iBoot-1145.3 */ + /* CPID 0x8950 -- S5L8950 (A5-class), Apple TV 3rd gen, iBoot-1145.3 */ { .cpid = 0x8950, - .name = "A9", - .marketing = "Apple TV (3rd gen)", + .name = "S5L8950", + .marketing = "Apple TV (3rd gen) (A5-class)", .checkm8_vulnerable = 1, .config_large_leak = 659, .config_overwrite_pad = 0x640, @@ -61,11 +61,11 @@ static const chip_info_t g_chip_table[] = { .payload_dest_armv7 = 0x10079800, }, - /* CPID 0x8955 -- iBoot-1145.3.3 */ + /* CPID 0x8955 -- S5L8955 (A5-class), Apple TV 3rd gen rev A, iBoot-1145.3.3 */ { .cpid = 0x8955, - .name = "A9", - .marketing = "Apple TV (3rd gen, rev A)", + .name = "S5L8955", + .marketing = "Apple TV (3rd gen, rev A) (A5-class)", .checkm8_vulnerable = 1, .config_large_leak = 659, .config_overwrite_pad = 0x640, @@ -199,7 +199,7 @@ static const chip_info_t g_chip_table[] = { /* gaster: iBoot-1704.10 */ { .cpid = 0x8960, - .name = "A10", + .name = "A10 (iBoot-1704)", .marketing = "iPhone 7 / iPhone 7 Plus", .checkm8_vulnerable = 1, .config_large_leak = 7936, @@ -268,3 +268,5 @@ static const chip_info_t g_chip_table[] = { /* Part 2 continues in chip_db_table_rop.h (ROP chips + A12+ entries) */ #include "device/chip_db_table_rop.h" + +#endif /* CHIP_DB_TABLE_H */ diff --git a/include/device/chip_db_table_rop.h b/include/device/chip_db_table_rop.h index 610bdab..1598ce9 100644 --- a/include/device/chip_db_table_rop.h +++ b/include/device/chip_db_table_rop.h @@ -4,6 +4,8 @@ * Included by chip_db_table.h inside the g_chip_table[] array. * Do not include this file directly. All values from gaster. */ +#ifndef CHIP_DB_TABLE_ROP_H +#define CHIP_DB_TABLE_ROP_H /* ================================================================ */ /* ARM64 chips with ROP gadgets (A9X, A10, A10X, A11, T2) */ @@ -44,7 +46,7 @@ /* gaster: iBoot-2696.0.0.1.33 */ { .cpid = 0x8010, - .name = "A10", + .name = "A10 (iBoot-2696)", .marketing = "iPhone 7 / iPod touch 7G", .checkm8_vulnerable = 1, .config_overwrite_pad = 0x5C0, @@ -183,4 +185,4 @@ }; /* clang-format on */ -#endif /* CHIP_DB_TABLE_H */ +#endif /* CHIP_DB_TABLE_ROP_H */ diff --git a/include/exploit/checkm8_internal.h b/include/exploit/checkm8_internal.h index 1bca6df..056108f 100644 --- a/include/exploit/checkm8_internal.h +++ b/include/exploit/checkm8_internal.h @@ -37,11 +37,18 @@ /* ARMv7 32-bit chips (payload_dest_armv7 != 0) */ #define CPID_IS_ARMV7(cpid) \ - ((cpid) == 0x7002 || (cpid) == 0x8002 || (cpid) == 0x8004) + ((cpid) == 0x7002 || (cpid) == 0x8002 || (cpid) == 0x8004 || \ + (cpid) == 0x8950 || (cpid) == 0x8955) -/* A9-class chips that use the TTBR0 payload variant */ -#define CPID_IS_A9_CLASS(cpid) \ - ((cpid) == 0x8950 || (cpid) == 0x8955 || (cpid) == 0x8947) +/* + * CPID_IS_LEGACY_64 -- ARM64 chips that use payload_hdr_a9_t (the simpler + * 64-bit header without ROP gadgets or tlbi). This groups A7 (0x8947) with + * the A9-family (0x8000, 0x8003) which share the same header layout. + * Note: 0x8950 and 0x8955 are 32-bit ARMv7 chips; they belong in + * CPID_IS_ARMV7, not here. + */ +#define CPID_IS_LEGACY_64(cpid) \ + ((cpid) == 0x8947) /* Chips with ROP gadgets (tlbi != 0 means newer overwrite path) */ #define CPID_HAS_TLBI(chip) ((chip)->tlbi != 0) diff --git a/src/device/usb_dfu.c b/src/device/usb_dfu.c index cbbbd1b..ff06bd1 100644 --- a/src/device/usb_dfu.c +++ b/src/device/usb_dfu.c @@ -118,13 +118,12 @@ int usb_dfu_find(libusb_device_handle **handle) return -1; } + libusb_detach_kernel_driver(*handle, 0); /* Linux: detach kernel driver; ignore error */ + /* Claim interface 0 (DFU interface) */ int ret = libusb_claim_interface(*handle, 0); - if (ret != LIBUSB_SUCCESS) { - log_warn("failed to claim interface 0: %s (continuing anyway)", - libusb_strerror(ret)); - /* Non-fatal: macOS may have the kernel driver attached */ - } + if (ret != LIBUSB_SUCCESS) + log_warn("failed to claim interface 0: %s (continuing anyway)", libusb_strerror(ret)); return 0; } @@ -141,16 +140,19 @@ int usb_dfu_find(libusb_device_handle **handle) static int parse_hex_field(const char *serial, const char *key, uint64_t *out) { const char *p; + char *endptr; if (!serial || !key || !out) return -1; - p = strstr(serial, key); if (!p) return -1; - - p += strlen(key); - *out = strtoull(p, NULL, 16); + endptr = NULL; + *out = strtoull(p, &endptr, 16); + if (!endptr || endptr == p) { + log_warn("parse_hex_field: garbage value for key '%s'", key); + *out = 0; + } return 0; } @@ -178,6 +180,8 @@ int usb_dfu_read_info(libusb_device_handle *handle, uint32_t *cpid, return -1; } + if (ret >= (int)sizeof(buf)) + ret = (int)sizeof(buf) - 1; buf[ret] = '\0'; log_debug("DFU serial string: %s", (char *)buf); @@ -217,23 +221,20 @@ int usb_dfu_read_info(libusb_device_handle *handle, uint32_t *cpid, int usb_dfu_send(libusb_device_handle *handle, const void *data, size_t len) { size_t sent = 0; + uint16_t block_num = 0; int ret; if (!handle || (!data && len > 0)) return -1; - /* - * DFU DNLOAD: bmRequestType = host-to-device, class, interface - * bRequest = DFU_DNLOAD (1), wValue = block number, wIndex = 0 - * Send in chunks of DFU_MAX_TRANSFER. - */ + /* DFU DNLOAD: send in DFU_MAX_TRANSFER chunks; wValue is block number (DFU spec). */ while (sent < len) { size_t chunk = len - sent; if (chunk > DFU_MAX_TRANSFER) chunk = DFU_MAX_TRANSFER; ret = usb_ctrl_transfer(handle, DFU_REQUEST_OUT, DFU_DNLOAD, - 0, 0, (unsigned char *)data + sent, + block_num, 0, (unsigned char *)data + sent, (uint16_t)chunk, DFU_USB_TIMEOUT); if (ret < 0) { log_error("DFU DNLOAD failed at offset %zu: %s", @@ -243,7 +244,8 @@ int usb_dfu_send(libusb_device_handle *handle, const void *data, size_t len) } sent += (size_t)ret; - log_debug("DFU DNLOAD: sent %zu / %zu bytes", sent, len); + log_debug("DFU DNLOAD block %u: sent %zu / %zu bytes", (unsigned)block_num, sent, len); + block_num++; } return 0; diff --git a/src/exploit/checkm8_payload.c b/src/exploit/checkm8_payload.c index feab50d..2de19a1 100644 --- a/src/exploit/checkm8_payload.c +++ b/src/exploit/checkm8_payload.c @@ -116,8 +116,8 @@ int assemble_payload(exploit_ctx_t *ctx) /* * Select payload variant based on chip type: - * - ARMv7 (0x7002, 0x8002, 0x8004): armv7 header + armv7 shellcode - * - A9-class (0x8950, 0x8955, 0x8947, 0x8000, 0x8003): a9 header + arm64 + * - ARMv7 (0x7002, 0x8002, 0x8004, 0x8950, 0x8955): armv7 header + armv7 shellcode + * - legacy 64-bit (0x8947, 0x8000, 0x8003): a9 header + arm64 shellcode * - Everything else (A10+): notA9 header + arm64 shellcode */ if (CPID_IS_ARMV7(chip->cpid)) { @@ -126,12 +126,12 @@ int assemble_payload(exploit_ctx_t *ctx) sc_len = checkm8_shellcode_armv7_len; log_debug("assemble_payload: ARMv7 variant (hdr=%zu, sc=%zu)", hdr_len, sc_len); - } else if (CPID_IS_A9_CLASS(chip->cpid) || + } else if (CPID_IS_LEGACY_64(chip->cpid) || chip->cpid == 0x8000 || chip->cpid == 0x8003) { hdr_len = sizeof(payload_hdr_a9_t); sc = checkm8_shellcode_arm64; sc_len = checkm8_shellcode_arm64_len; - log_debug("assemble_payload: A9 variant (hdr=%zu, sc=%zu)", + log_debug("assemble_payload: legacy-64 variant (hdr=%zu, sc=%zu)", hdr_len, sc_len); } else { hdr_len = sizeof(payload_hdr_notA9_t); @@ -151,7 +151,7 @@ int assemble_payload(exploit_ctx_t *ctx) /* Build the chip-specific header at the start of the buffer */ if (CPID_IS_ARMV7(chip->cpid)) { build_hdr_armv7((payload_hdr_armv7_t *)buf, chip); - } else if (CPID_IS_A9_CLASS(chip->cpid) || + } else if (CPID_IS_LEGACY_64(chip->cpid) || chip->cpid == 0x8000 || chip->cpid == 0x8003) { build_hdr_a9((payload_hdr_a9_t *)buf, chip); } else {