From 97f367de2f7e39a5e6f66a90c76c0b01af80dbff Mon Sep 17 00:00:00 2001 From: JayPiKay Date: Wed, 11 Aug 2021 10:58:02 +0200 Subject: [PATCH] PoC: Set SSID 77777777 and Pass 88888888 --- main.c | 332 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 182 insertions(+), 150 deletions(-) diff --git a/main.c b/main.c index 7d70574..cb4703b 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,12 @@ #include "config.h" +#define ERR_EXIT(errcode) do { perr(" %s\n", libusb_strerror((enum libusb_error)errcode)); return -1; } while (0) +#define CALL_CHECK(fcall) do { int _r=fcall; if (_r < 0) ERR_EXIT(_r); } while (0) +#define CALL_CHECK_CLOSE(fcall, hdl) do { int _r=fcall; if (_r < 0) { libusb_close(hdl); ERR_EXIT(_r); } } while (0) + +#define REQUEST_SENSE_LENGTH 0x12 + // Section 5.1: Command Block Wrapper (CBW) struct command_block_wrapper { uint8_t dCBWSignature[4]; @@ -45,14 +51,10 @@ static const uint8_t cdb_length[256] = { 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, // C 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, // D 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, // E - 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, // F + 00,00,00,00,00,00,00,00,00,00,00,00,00,16,16,16, // F }; - -#define REQUEST_SENSE_LENGTH 0x12 - - -static struct libusb_device_handle *devh = NULL; +// static struct libusb_device_handle *devh = NULL; static void perr(char const *format, ...) { @@ -63,6 +65,34 @@ static void perr(char const *format, ...) va_end(args); } +static void display_buffer_hex(unsigned char *buffer, unsigned size) +{ + unsigned i, j, k; + + for (i=0; i 126)) { + printf("."); + } else { + printf("%c", buffer[i+j]); + } + } + } + } + printf("\n" ); +} + static int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, uint8_t lun, uint8_t *cdb, uint8_t direction, int data_length, uint32_t *ret_tag) { @@ -80,6 +110,8 @@ static int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpo return -1; } + display_buffer_hex(cdb, cdb_length[cdb[0]]); + cdb_len = cdb_length[cdb[0]]; if ((cdb_len == 0) || (cdb_len > sizeof(cbw.CBWCB))) { perr("send_mass_storage_command: don't know how to handle this command (%02X, length %d)\n", @@ -111,178 +143,178 @@ static int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpo i++; } while ((r == LIBUSB_ERROR_PIPE) && (ibNumInterfaces; k++) { - iface = &dev_conf->interface[k]; - for (int l = 0; l < iface->num_altsetting; l++) { - iface_desc = &iface->altsetting[l]; - if (libusb_kernel_driver_active(devh, iface_desc->bInterfaceNumber)) { - libusb_detach_kernel_driver(devh, iface_desc->bInterfaceNumber); - } - - libusb_set_configuration(devh, dev_conf->bConfigurationValue); - libusb_claim_interface(devh, iface_desc->bInterfaceNumber); - - int e = 0; - while (libusb_claim_interface(devh, iface_desc->bInterfaceNumber) && (e < 10)) { - sleep(1); - e++; - } - } - } - - libusb_free_config_descriptor(dev_conf); - } - - return devh; - } - - devh = NULL; - return NULL; -} - static int get_mass_storage_status(libusb_device_handle *handle, uint8_t endpoint, uint32_t expected_tag) { - int i, r, size; - struct command_status_wrapper csw; + int i, r, size; + struct command_status_wrapper csw; - // The device is allowed to STALL this transfer. If it does, you have to - // clear the stall and try again. - i = 0; - do { - r = libusb_bulk_transfer(handle, endpoint, (unsigned char*)&csw, 13, &size, 1000); - if (r == LIBUSB_ERROR_PIPE) { - libusb_clear_halt(handle, endpoint); - } - i++; - } while ((r == LIBUSB_ERROR_PIPE) && (i