| 239 | } |
| 240 | |
| 241 | DeviceProfile BLEAttackManager::profileDevice(NimBLEAddress target) { |
| 242 | DeviceProfile profile; |
| 243 | std::string addressStr = target.toString(); |
| 244 | profile.address = String(addressStr.c_str()); |
| 245 | profile.connected = false; |
| 246 | profile.hasFastPair = false; |
| 247 | profile.hasAVRCP = false; |
| 248 | profile.hasHID = false; |
| 249 | profile.hasBattery = false; |
| 250 | profile.hasDeviceInfo = false; |
| 251 | |
| 252 | prepareForConnection(); |
| 253 | NimBLEClient *pClient = nullptr; |
| 254 | if (!connectToDevice(target, &pClient, false)) { |
| 255 | cleanupAfterAttack(); |
| 256 | return profile; |
| 257 | } |
| 258 | |
| 259 | profile.connected = true; |
| 260 | if (pClient->discoverAttributes()) { |
| 261 | const std::vector<NimBLERemoteService *> &services = pClient->getServices(true); |
| 262 | for (auto &service : services) { |
| 263 | NimBLEUUID uuid = service->getUUID(); |
| 264 | std::string uuidStr = uuid.toString(); |
| 265 | profile.services.push_back(String(uuidStr.c_str())); |
| 266 | if (uuidStr.find("fe2c") != std::string::npos) profile.hasFastPair = true; |
| 267 | if (uuidStr.find("110e") != std::string::npos || uuidStr.find("110f") != std::string::npos) |
| 268 | profile.hasAVRCP = true; |
| 269 | if (uuidStr.find("1812") != std::string::npos) profile.hasHID = true; |
| 270 | if (uuidStr.find("180f") != std::string::npos) profile.hasBattery = true; |
| 271 | if (uuidStr.find("180a") != std::string::npos) profile.hasDeviceInfo = true; |
| 272 | |
| 273 | const std::vector<NimBLERemoteCharacteristic *> &chars = service->getCharacteristics(true); |
| 274 | for (auto &ch : chars) { |
| 275 | std::string charUuid = ch->getUUID().toString(); |
| 276 | CharacteristicInfo charInfo; |
| 277 | charInfo.uuid = String(charUuid.c_str()); |
| 278 | charInfo.canRead = ch->canRead(); |
| 279 | charInfo.canWrite = ch->canWrite(); |
| 280 | charInfo.canNotify = ch->canNotify(); |
| 281 | profile.characteristics.push_back(charInfo); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | pClient->disconnect(); |
| 287 | BLEStateManager::unregisterClient(pClient); |
| 288 | NimBLEDevice::deleteClient(pClient); |
| 289 | cleanupAfterAttack(); |
| 290 | return profile; |
| 291 | } |
| 292 | |
| 293 | //============================================================================= |
| 294 | // Connection Strategy Engine |
no outgoing calls
no test coverage detected