| 1021 | } |
| 1022 | |
| 1023 | void analyzeClientBehavior(const ProbeRequest &probe) { |
| 1024 | auto it = clientBehaviors.find(probe.fingerprint); |
| 1025 | |
| 1026 | if (it == clientBehaviors.end()) { |
| 1027 | if (clientBehaviors.size() >= MAX_CLIENT_TRACK) { |
| 1028 | uint32_t oldestFingerprint = 0; |
| 1029 | unsigned long oldestTime = UINT32_MAX; |
| 1030 | for (const auto &pair : clientBehaviors) { |
| 1031 | if (pair.second.lastSeen < oldestTime) { |
| 1032 | oldestTime = pair.second.lastSeen; |
| 1033 | oldestFingerprint = pair.first; |
| 1034 | } |
| 1035 | } |
| 1036 | if (oldestFingerprint != 0) { clientBehaviors.erase(oldestFingerprint); } |
| 1037 | } |
| 1038 | |
| 1039 | ClientBehavior behavior; |
| 1040 | behavior.fingerprint = probe.fingerprint; |
| 1041 | behavior.lastMAC = probe.mac; |
| 1042 | behavior.firstSeen = probe.timestamp; |
| 1043 | behavior.lastSeen = probe.timestamp; |
| 1044 | behavior.probeCount = 1; |
| 1045 | behavior.avgRSSI = probe.rssi; |
| 1046 | behavior.probedSSIDs.push_back(probe.ssid); |
| 1047 | behavior.favoriteChannel = probe.channel; |
| 1048 | behavior.lastKarmaAttempt = 0; |
| 1049 | behavior.isVulnerable = (!probeSSIDEmpty(probe) && !probeSSIDEquals(probe, "*WILDCARD*")); |
| 1050 | clientBehaviors[probe.fingerprint] = behavior; |
| 1051 | uniqueClients++; |
| 1052 | } else { |
| 1053 | ClientBehavior &behavior = it->second; |
| 1054 | behavior.lastSeen = probe.timestamp; |
| 1055 | behavior.probeCount++; |
| 1056 | behavior.avgRSSI = (behavior.avgRSSI + probe.rssi) / 2; |
| 1057 | if (probe.channel >= 1 && probe.channel <= 14) { |
| 1058 | channelActivity[probe.channel - 1]++; |
| 1059 | if (channelActivity[probe.channel - 1] > channelActivity[behavior.favoriteChannel - 1]) |
| 1060 | behavior.favoriteChannel = probe.channel; |
| 1061 | } |
| 1062 | bool ssidExists = false; |
| 1063 | for (const auto &existingSSID : behavior.probedSSIDs) { |
| 1064 | if (existingSSID == probe.ssid) { |
| 1065 | ssidExists = true; |
| 1066 | break; |
| 1067 | } |
| 1068 | } |
| 1069 | if (!ssidExists && !probeSSIDEmpty(probe) && !probeSSIDEquals(probe, "*WILDCARD*") && |
| 1070 | behavior.probedSSIDs.size() < 5) { |
| 1071 | behavior.probedSSIDs.push_back(probe.ssid); |
| 1072 | if (behavior.probedSSIDs.size() >= VULNERABLE_THRESHOLD) behavior.isVulnerable = true; |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | uint8_t calculateAttackPriority(const ClientBehavior &client, const ProbeRequest &probe) { |
| 1078 | uint8_t score = 0; |
no test coverage detected