diff --git a/PLAN-PRUEBA.md b/PLAN-PRUEBA.md new file mode 100644 index 0000000..5fbf2ef --- /dev/null +++ b/PLAN-PRUEBA.md @@ -0,0 +1,141 @@ +# Plan de prueba en DFU — en tu equipo + +Objetivo: ver si el cambio de la rama altera algo real, con tres binarios comparados +en el mismo equipo, cable y puerto. + +La iPad se conecta a **tu** equipo, no al server. Todo lo de abajo corre local. + +--- + +## Paso 0 — Preparar (una sola vez) + +```bash +git clone https://git.t450lib.duckdns.org/ale/tr4mpass.git +cd tr4mpass + +# Versión original +git checkout main +./start.sh +cp tr4mpass /tmp/tr4mpass-main + +# Versión de la rama +git checkout fix/checkm8-usbipd-pause +make clean && make +cp tr4mpass /tmp/tr4mpass-pr + +ls -l /tmp/tr4mpass-main /tmp/tr4mpass-pr +``` + +Los dos binarios tienen que tener tamaño distinto. Si son iguales, algo falló. + +`./start.sh` instala las dependencias (pide sudo una vez). Si ya las tenés de antes, +alcanza con `make`. + +## Paso 1 — Confirmar que la iPad está en DFU + +Con la iPad conectada: + +```bash +watch -n1 'lsusb | grep -i 05ac' +``` + +Tiene que aparecer `Apple, Inc. Mobile Device (DFU Mode)` con el ID `05ac:1227`. +Si aparece `05ac:1281` es modo recovery, no DFU: repetí el procedimiento de DFU. + +Anotá el bus y la dirección que muestra `lsusb`: +``` +Bus 001 Device 014: ID 05ac:1227 Apple, Inc. Mobile Device (DFU Mode) + ^bus ^dev +``` + +Esos dos números son los que hay que buscar en `dmesg` después. + +--- + +## Paso 2 — Corrida de control con gaster (si lo tenés en este equipo) + +```bash +sudo dmesg -w > /tmp/ctl-dmesg.txt & +lsusb > /tmp/ctl-lsusb-antes.txt +/home/masrealquiedos/pwn/gaster/gaster pwn 2>&1 | tee /tmp/ctl-salida.txt +sudo pkill -f "dmesg -w"; lsusb > /tmp/ctl-lsusb-despues.txt +``` + +Buscar en `/tmp/ctl-salida.txt` la línea con `PWND:[`. Si gaster falla acá, el +problema es el equipo/cable/puerto y no tiene sentido seguir. + +**Después de gaster, la iPad queda pwned.** Hay que sacarla y volver a meterla en +DFU antes de la corrida siguiente. + +--- + +## Paso 3 — Corrida con el binario original + +```bash +sudo dmesg -w > /tmp/main-1-dmesg.txt & +lsusb > /tmp/main-1-lsusb-antes.txt +timeout 300 /tmp/tr4mpass-main -v 2>&1 | tee /tmp/main-1-salida.txt +echo "rc=$?" +sudo pkill -f "dmesg -w"; lsusb > /tmp/main-1-lsusb-despues.txt +``` + +## Paso 4 — Corrida con el binario de la rama + +Volver a poner la iPad en DFU primero. + +```bash +sudo dmesg -w > /tmp/pr-1-dmesg.txt & +lsusb > /tmp/pr-1-lsusb-antes.txt +timeout 300 /tmp/tr4mpass-pr -v 2>&1 | tee /tmp/pr-1-salida.txt +echo "rc=$?" +sudo pkill -f "dmesg -w"; lsusb > /tmp/pr-1-lsusb-despues.txt +``` + +## Paso 5 — Repetir + +Tres veces cada binario, alternando: main, rama, main, rama, main, rama. Así una +racha buena o mala no se confunde con el cambio. + +Cambiá el número en los nombres de archivo en cada vuelta. + +--- + +## Paso 6 — Devolver los resultados + +```bash +tar czf ~/dfu-test-$(date +%Y%m%d-%H%M).tar.gz \ + /tmp/ctl-* /tmp/main-*-salida.txt /tmp/main-*-dmesg.txt /tmp/main-*-lsusb-* \ + /tmp/pr-*-salida.txt /tmp/pr-*-dmesg.txt /tmp/pr-*-lsusb-* +ls -l ~/dfu-test-*.tar.gz +``` + +Ese archivo es lo que hace falta. También sirve pegar acá el contenido de un +`/tmp/main-1-salida.txt` y un `/tmp/pr-1-salida.txt`. + +--- + +## Qué miro yo en esos archivos + +| Señal | Qué significa | +|---|---| +| `send_overwrite: expected STALL, got -4` | El fallo conocido. Aparece igual en los dos binarios = el cambio no lo toca. | +| `stage 3 complete -- heap spray done` seguido de un hueco largo | El dispositivo se cayó durante o después del spray. | +| `USB disconnect` en el dmesg | Momento exacto en que salió del bus. Se compara con las líneas `usb:` de la salida. | +| Líneas `usb: ... ret=-4 elapsed=...` | La traza nueva. Dice si la transferencia que falló fue la primera después del hueco. | +| `lsusb` después con `05ac:1227` | El device sigue en DFU: solo falló la transferencia. | +| `lsusb` después vacío o con otro ID | El device se reinició o se fue: la secuencia lo mató. | + +## Sin gaster, igual sirve + +Si no tenés gaster compilado en este equipo, salteá el paso 2. El control más +importante son los dos binarios entre sí, mismos largos de corrida. + +## Si `dmesg` pide permisos + +Algunos sistemas tienen `kernel.dmesg_restrict=1`. En ese caso: + +```bash +sudo sysctl -w kernel.dmesg_restrict=0 +``` + +O usá `sudo journalctl -k -f > archivo &` en lugar de `dmesg -w`. diff --git a/src/exploit/checkm8_spray.c b/src/exploit/checkm8_spray.c index f20444c..4d66677 100644 --- a/src/exploit/checkm8_spray.c +++ b/src/exploit/checkm8_spray.c @@ -4,7 +4,6 @@ * Gaster typically converges in a handful of iterations; 100 is generous. */ #define MAX_STALL_RETRIES 100 -#include #include #include #include @@ -180,35 +179,6 @@ int checkm8_no_leak(libusb_device_handle *usb, uint8_t iserial_idx) /* Stage 3: Heap spray */ /* ------------------------------------------------------------------ */ -/* - * usbipd_present -- true when the device is reached through usbipd. - * - * WSL_DISTRO_NAME alone is not enough: sudo resets the environment by - * default, so the variable disappears exactly when the tool is run the - * way most of the reports run it. /proc/version keeps a marker that - * survives sudo. - */ -static int usbipd_present(void) -{ - FILE *f; - char buf[256]; - size_t n; - - if (getenv("WSL_DISTRO_NAME") != NULL) - return 1; - - f = fopen("/proc/version", "r"); - if (!f) - return 0; - - n = fread(buf, 1, sizeof(buf) - 1, f); - fclose(f); - buf[n] = '\0'; - - return strstr(buf, "microsoft") != NULL || - strstr(buf, "Microsoft") != NULL; -} - int checkm8_stage_spray(exploit_ctx_t *ctx) { libusb_device_handle *usb; @@ -325,20 +295,9 @@ int checkm8_stage_spray(exploit_ctx_t *ctx) * io_buffer cannot land at insecure_memory_base. * * Wait 1 second to ensure all spray buffers are freed by the - * device before stage 4's DFU_DNLOAD allocation. This is the setup - * the delay was written for: the vhci layer adds latency and the - * buffers are freed late. - * - * On a native host there is no evidence that the same wait is - * needed, and no measurement has been taken either way. One - * hypothesis is that the idle second is a window in which the - * device can leave dfuIDLE on its own, which would surface as - * NO_DEVICE (-4) at stage 4; that is unconfirmed. What this change - * claims is narrower: do not keep a delay on transports that never - * asked for it, so a native run behaves like the bus it runs on. + * device before stage 4's DFU_DNLOAD allocation. */ - if (usbipd_present()) - usleep(1000000); /* 1 s -- usbipd only */ + usleep(1000000); /* 1 s */ ctx->phase = EXPLOIT_PHASE_SPRAY; log_info("checkm8: stage 3 complete -- heap spray done"); diff --git a/src/exploit/checkm8_stages.c b/src/exploit/checkm8_stages.c index 3cb49ff..9e7626b 100644 --- a/src/exploit/checkm8_stages.c +++ b/src/exploit/checkm8_stages.c @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -38,37 +37,15 @@ int usb_ctrl_transfer_raw(libusb_device_handle *dev, unsigned int timeout_ms) { unsigned int effective_timeout_ms = timeout_ms; - struct timespec t0, t1; - long elapsed_us; - int ret; if (!dev) return LIBUSB_ERROR_INVALID_PARAM; if (effective_timeout_ms == 0) effective_timeout_ms = 1; - clock_gettime(CLOCK_MONOTONIC, &t0); - ret = libusb_control_transfer(dev, bmRequestType, bRequest, + return libusb_control_transfer(dev, bmRequestType, bRequest, wValue, wIndex, data, wLength, effective_timeout_ms); - clock_gettime(CLOCK_MONOTONIC, &t1); - - elapsed_us = (long)((t1.tv_sec - t0.tv_sec) * 1000000L - + (t1.tv_nsec - t0.tv_nsec) / 1000L); - - /* - * Trace every control transfer of the sequence with its result and - * how long it took. A -4 (NO_DEVICE) tells nothing on its own: it - * is the same code whether the device left the bus mid-transfer or - * between stages. The elapsed time of this transfer and of the one - * before it is what separates the two cases. - */ - log_debug("usb: bmRT=0x%02X bReq=0x%02X wVal=0x%04X wIdx=0x%04X " - "len=%u timeout=%ums ret=%d elapsed=%ldus", - bmRequestType, bRequest, wValue, wIndex, wLength, - effective_timeout_ms, ret, elapsed_us); - - return ret; } int usb_ctrl_transfer_no_data_raw(libusb_device_handle *dev, @@ -225,16 +202,6 @@ int usb_ctrl_transfer_dnload_abort(libusb_device_handle *dev, if (completed) actual_len = (int)transfer->actual_length; - /* - * The setup stage decides the pad length from this value. Log the - * three states separately: completed with a length, cancelled - * (actual_len reported as 0), and submit failure. A cancel that - * reports 0 makes the pad the whole overwrite_pad, which is a - * different state than the reference reaches on most attempts. - */ - log_debug("usb: async DNLOAD abort=%ums completed=%d actual_len=%d", - abort_ms, completed, actual_len); - free(buf); libusb_free_transfer(transfer); return actual_len;