RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
Karma watch stays bounded under a beacon flood: transmitters and names per transmitter capped
CIS-C0a6cbc04f824e
diff --git a/app/src/main/java/com/rfsentinel/app/usb/KarmaWatch.kt b/app/src/main/java/com/rfsentinel/app/usb/KarmaWatch.ktindex 5eb2337..29d0847 100644--- a/app/src/main/java/com/rfsentinel/app/usb/KarmaWatch.kt+++ b/app/src/main/java/com/rfsentinel/app/usb/KarmaWatch.kt@@ -21,6 +21,8 @@ object KarmaWatch {/** One alert per transmitter this often while it goes on. */const val REPEAT_MS = 5 * 60_000Lprivate const val MAX_TRANSMITTERS = 2_000+ /** Names kept per transmitter (a beacon flood cycles through thousands); also caps the alert's list. */+ private const val MAX_NAMES = 32/** Set by the scanning service; called (on the RX thread) when a fake access point is found. */@Volatile var onAttack: ((Attack) -> Unit)? = null@@ -37,11 +39,17 @@ object KarmaWatch {/** A beacon or probe response from [transmitter] under network name [ssid]. */fun frame(transmitter: String, ssid: String, channel: Int, now: Long = System.currentTimeMillis()): Attack? {val attack = synchronized(this) {- if (txs.size > MAX_TRANSMITTERS) txs.entries.removeAll { now - it.value.lastSeen > WINDOW_MS }+ if (txs.size > MAX_TRANSMITTERS) {+ txs.entries.removeAll { now - it.value.lastSeen > WINDOW_MS }+ // A flood from random addresses: everything is recent, so the least recently heard go.+ if (txs.size > MAX_TRANSMITTERS) txs.entries.sortedBy { it.value.lastSeen }+ .take(txs.size - MAX_TRANSMITTERS / 2).map { it.key }.forEach { txs.remove(it) }+ }val t = txs.getOrPut(transmitter) { Tx() }t.lastSeen = nowt.names.remove(ssid); t.names[ssid] = nowt.names.entries.removeAll { now - it.value > WINDOW_MS }+ while (t.names.size > MAX_NAMES) t.names.remove(t.names.keys.first())if (t.names.size < MIN_NAMES || now - t.lastReport < REPEAT_MS) return@synchronized nullt.lastReport = nowAttack(transmitter, t.names.keys.reversed(), channel, (WINDOW_MS / 1000).toInt())diff --git a/app/src/test/java/com/rfsentinel/app/detect/SignalSweepIdeasTest.kt b/app/src/test/java/com/rfsentinel/app/detect/SignalSweepIdeasTest.ktindex 982bf4c..34fa52f 100644--- a/app/src/test/java/com/rfsentinel/app/detect/SignalSweepIdeasTest.kt+++ b/app/src/test/java/com/rfsentinel/app/detect/SignalSweepIdeasTest.kt@@ -283,6 +283,20 @@ class SignalSweepIdeasTest {assertNull(KarmaWatch.frame("00:30:44:00:00:01", "HomeNet4", 6, t + KarmaWatch.WINDOW_MS + 1))}+ @Test+ fun aBeaconFloodStaysBounded() {+ val heard = ArrayList<KarmaWatch.Attack>()+ KarmaWatch.onAttack = { heard += it }+ // One transmitter cycling through thousands of names: the alert lists a bounded few.+ repeat(5_000) { KarmaWatch.frame("00:13:37:00:00:01", "Free WiFi $it", 6, it.toLong()) }+ assertEquals(1, heard.size)+ assertTrue(heard[0].names.size <= 32)+ // Random addresses, one name each, all within the window: never an alert, and it keeps working.+ repeat(20_000) { KarmaWatch.frame("02:00:%02x:%02x:00:01".format(it / 256 % 256, it % 256), "x", 6, 10_000L + it) }+ assertEquals(1, heard.size)+ assertNull(KarmaWatch.frame("00:30:44:00:00:09", "HomeNet", 6, 40_000L))+ }+// ---- Deauth@Test