| 4615 | } |
| 4616 | |
| 4617 | void runWriteAccessTest(NimBLEAddress target) { |
| 4618 | AutoCleanup cleanup([]() { BLEStateManager::deinitBLE(true); }); |
| 4619 | |
| 4620 | if (!confirmAttack("Test write access on all characteristics?")) return; |
| 4621 | |
| 4622 | String connectionMethod = ""; |
| 4623 | NimBLEClient *pClient = attemptConnectionWithStrategies(target, connectionMethod); |
| 4624 | if (!pClient) { |
| 4625 | showAttackResult(false, "Failed to connect"); |
| 4626 | return; |
| 4627 | } |
| 4628 | |
| 4629 | BLEStateManager::registerClient(pClient); |
| 4630 | showAttackProgress("Connected! Testing write access...", TFT_GREEN); |
| 4631 | |
| 4632 | std::vector<String> writeableChars; |
| 4633 | const std::vector<NimBLERemoteService *> &services = pClient->getServices(true); |
| 4634 | for (auto &service : services) { |
| 4635 | const std::vector<NimBLERemoteCharacteristic *> &chars = service->getCharacteristics(true); |
| 4636 | for (auto &ch : chars) { |
| 4637 | if (ch->canWrite()) { |
| 4638 | String uuidStr = String(service->getUUID().toString().c_str()); |
| 4639 | String charUuid = String(ch->getUUID().toString().c_str()); |
| 4640 | writeableChars.push_back(uuidStr + " -> " + charUuid); |
| 4641 | } |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | pClient->disconnect(); |
| 4646 | BLEStateManager::unregisterClient(pClient); |
| 4647 | NimBLEDevice::deleteClient(pClient); |
| 4648 | cleanup.disable(); |
| 4649 | |
| 4650 | if (!writeableChars.empty()) { |
| 4651 | std::vector<String> lines; |
| 4652 | lines.push_back("WRITABLE CHARACTERISTICS:"); |
| 4653 | lines.push_back("Connection: " + connectionMethod); |
| 4654 | lines.push_back("Found: " + String(writeableChars.size())); |
| 4655 | |
| 4656 | for (int i = 0; i < std::min(5, (int)writeableChars.size()); i++) lines.push_back(writeableChars[i]); |
| 4657 | |
| 4658 | if (writeableChars.size() > 5) |
| 4659 | lines.push_back("... and " + String(writeableChars.size() - 5) + " more"); |
| 4660 | |
| 4661 | showDeviceInfoScreen("WRITE ACCESS TEST", lines, TFT_BLUE, TFT_WHITE); |
| 4662 | } else { |
| 4663 | showAttackResult(false, "No writable characteristics found"); |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | void runProtocolFuzzer(NimBLEAddress target) { |
| 4668 | AutoCleanup cleanup([]() { BLEStateManager::deinitBLE(true); }); |
no test coverage detected