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
Fake cells: strong new cell while still, odd area among neighbours
CIS-C0cd3b84bbbf73
diff --git a/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt b/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.ktindex 6ca371a..fd618eb 100644--- a/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt+++ b/app/src/main/java/com/rfsentinel/app/detect/CellAnalyzer.kt@@ -7,6 +7,9 @@ package com.rfsentinel.app.detect* ciphering or signalling messages, so none of this is proof - each sign has* innocent explanations, which is why most are weak on their own.*+ * Two more follow AIMSICD's and SnoopSnitch's non-root checks: a never-seen cell that takes over+ * far stronger than the last while you stand still, and an area code none of the neighbours share.+ ** Several checks follow EFF Rayhunter's analyzers as far as Android lets an* app see them: Rayhunter reads the modem's signalling (a "release with* redirect to 2G", incomplete system information); here only their visible@@ -74,6 +77,8 @@ class CellAnalyzer(private val knownAreas: MutableMap<String, Int> = LinkedHashMprivate var lastRaw: Set<String> = emptySet()/** Consecutive snapshots in which a known cell showed up with another area. */private val areaMismatch = HashMap<String, Int>()+ /** When each cell identity was first seen this session (cells known from before aren't in it). */+ private val firstSeen = HashMap<String, Long>()/** Analyses one snapshot of visible cells; returns the warning signs found in it. */fun analyze(cells: List<Cell>, ctx: Context): List<Anomaly> {@@ -92,8 +97,10 @@ class CellAnalyzer(private val knownAreas: MutableMap<String, Int> = LinkedHashMisolated(serving, window)?.let { raw += it to false }reservedIdentity(serving)?.let { raw += it to false }clonedIdentity(serving)?.let { raw += it to false }+ strongNewCell(serving, window)?.let { raw += it to false }+ oddAreaAmongNeighbours(serving, cells)?.let { raw += it to false }}- learnAreas(cells)+ learnAreas(cells, ctx.time)val out = raw.filter { (a, immediate) -> immediate || a.key in lastRaw }.map { it.first }.toMutableList()// Two or more signs on the same cell at once weigh more than either alone.@@ -238,15 +245,57 @@ class CellAnalyzer(private val knownAreas: MutableMap<String, Int> = LinkedHashM)}+ /**+ * A cell never seen before took over just now, far stronger than the cell before it, while you+ * stood still (AIMSICD's signal-strength and SnoopSnitch's new-cell checks): standing still the+ * cells around you don't change, and a fake station close by outshines the real ones.+ */+ private fun strongNewCell(serving: Cell, window: List<Seen>): Anomaly? {+ val id = serving.idKey ?: return null+ val dbm = serving.dbm ?: return null+ val start = runStart(window) { it.registered?.idKey == id }+ val run = window.subList(start, window.size)+ val prev = window.getOrNull(start - 1) ?: return null+ val prevDbm = prev.registered?.dbm ?: return null+ // First seen this session, or right now; a cell known from an earlier session isn't new.+ val first = firstSeen[id] ?: if (id !in knownAreas) window.last().time else return null+ if (first < run.first().time - SUDDEN_MS || window.last().time - run.first().time > RECENT_MS) return null+ if (run.any { it.stationary != true } || prev.stationary != true) return null+ if (dbm < STRONG_SERVING_DBM || dbm - prevDbm < JUMP_DB) return null+ return Anomaly(+ "strong-new:${serving.key}", "New, unusually strong cell while you weren't moving",+ "Your phone moved to a cell it had never seen, at $dbm dBm, ${dbm - prevDbm} dB stronger than the one " ++ "before, while GPS shows you standing still. A fake station nearby is often the strongest cell around. " ++ "A newly switched-on or repaired real cell looks the same.", 40+ )+ }++ /**+ * The serving cell's area code is shared by none of its neighbours, which all agree on another+ * one (AIMSICD's area consistency check): fake cells pick a new area to make phones register.+ */+ private fun oddAreaAmongNeighbours(serving: Cell, cells: List<Cell>): Anomaly? {+ val area = serving.area?.takeIf { it !in RESERVED_AREA } ?: return null+ val areas = cells.filter { !it.registered && it.rat == serving.rat && it.mcc == serving.mcc && it.mnc == serving.mnc }+ .mapNotNull { it.area?.takeIf { a -> a !in RESERVED_AREA } }+ if (areas.size < MIN_NEIGHBOUR_AREAS || areas.distinct().size != 1 || areas[0] == area) return null+ return Anomaly(+ "odd-area:${serving.key}", "Area code none of the neighbours share",+ "Your cell announces area $area while all ${areas.size} neighbouring cells of the same network are in " ++ "area ${areas[0]}. Fake cells use their own area to make phones re-register. At an area border " ++ "this can be normal.", 35+ )+ }+/** Remembers each cell's area; a changed area is adopted once it has persisted (a re-planned network). */- private fun learnAreas(cells: List<Cell>) {+ private fun learnAreas(cells: List<Cell>, now: Long) {for (c in cells) {val id = c.idKey ?: continueval area = c.area?.takeIf { it !in RESERVED_AREA } ?: continueval known = knownAreas[id]if (known == null || known == area) {areaMismatch.remove(id)- if (known == null) knownAreas[id] = area+ if (known == null) { knownAreas[id] = area; firstSeen[id] = now }} else {val n = (areaMismatch[id] ?: 0) + 1areaMismatch[id] = n@@ -254,6 +303,7 @@ class CellAnalyzer(private val knownAreas: MutableMap<String, Int> = LinkedHashM}}while (knownAreas.size > MAX_KNOWN) knownAreas.remove(knownAreas.keys.first())+ if (firstSeen.size > MAX_KNOWN) firstSeen.entries.removeIf { now - it.value > WINDOW_MS }}/** Index in [window] where the trailing run of snapshots matching [f] starts ([window].size if none). */@@ -274,6 +324,11 @@ class CellAnalyzer(private val knownAreas: MutableMap<String, Int> = LinkedHashMconst val STRONG_DBM = -105/** Snapshots in a row after which a cell's new area is taken as real. */const val ADOPT_AFTER = 8+ /** A new serving cell this strong, and [JUMP_DB] above the last, stands out. */+ const val STRONG_SERVING_DBM = -65+ const val JUMP_DB = 20+ /** Neighbours with a known area needed before the serving cell's area can be the odd one out. */+ const val MIN_NEIGHBOUR_AREAS = 3const val MAX_KNOWN = 5000/** ITU test / reserved codes. */val TEST_MCC = setOf("001", "002", "999")diff --git a/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt b/app/src/main/java/com/rfsentinel/app/service/CellMonitor.ktindex 7152270..d6f691e 100644--- a/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt+++ b/app/src/main/java/com/rfsentinel/app/service/CellMonitor.kt@@ -127,6 +127,9 @@ class CellMonitor(private val context: Context) {}}.getOrNull()+ /** Signal in dBm, or null when the modem didn't report one (UNAVAILABLE / out of range). */+ private fun dbm(v: Int) = v.takeIf { it in -150..-20 }+private fun Int.orNull() = takeIf { it != CellInfo.UNAVAILABLE && it != Int.MAX_VALUE && it >= 0 }private fun toCell(info: CellInfo): CellAnalyzer.Cell? {@@ -134,18 +137,18 @@ class CellMonitor(private val context: Context) {return when (info) {is CellInfoLte -> info.cellIdentity.let {CellAnalyzer.Cell(CellAnalyzer.Rat.LTE, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.tac.orNull(), it.ci.orNull()?.toLong(),- info.cellSignalStrength.dbm, it.earfcn.orNull(), it.pci.orNull(), opName(it))+ dbm(info.cellSignalStrength.dbm), it.earfcn.orNull(), it.pci.orNull(), opName(it))}is CellInfoGsm -> info.cellIdentity.let {CellAnalyzer.Cell(CellAnalyzer.Rat.GSM, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.lac.orNull(), it.cid.orNull()?.toLong(),- info.cellSignalStrength.dbm, it.arfcn.orNull(), it.bsic.orNull(), opName(it))+ dbm(info.cellSignalStrength.dbm), it.arfcn.orNull(), it.bsic.orNull(), opName(it))}is CellInfoWcdma -> info.cellIdentity.let {CellAnalyzer.Cell(CellAnalyzer.Rat.WCDMA, reg, mcc(it.mccCompat()), mnc(it.mncCompat()), it.lac.orNull(), it.cid.orNull()?.toLong(),- info.cellSignalStrength.dbm, it.uarfcn.orNull(), it.psc.orNull(), opName(it))+ dbm(info.cellSignalStrength.dbm), it.uarfcn.orNull(), it.psc.orNull(), opName(it))}is CellInfoCdma -> CellAnalyzer.Cell(CellAnalyzer.Rat.CDMA, reg, null, null,- info.cellIdentity.networkId.orNull(), info.cellIdentity.basestationId.orNull()?.toLong(), info.cellSignalStrength.dbm)+ info.cellIdentity.networkId.orNull(), info.cellIdentity.basestationId.orNull()?.toLong(), dbm(info.cellSignalStrength.dbm))else -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) newer(info, reg) else null}}@@ -154,12 +157,12 @@ class CellMonitor(private val context: Context) {private fun newer(info: CellInfo, reg: Boolean): CellAnalyzer.Cell? = when (info) {is CellInfoNr -> (info.cellIdentity as CellIdentityNr).let {CellAnalyzer.Cell(CellAnalyzer.Rat.NR, reg, it.mccString, it.mncString, it.tac.orNull(),- it.nci.takeIf { n -> n != CellInfo.UNAVAILABLE_LONG && n >= 0 }, info.cellSignalStrength.dbm,+ it.nci.takeIf { n -> n != CellInfo.UNAVAILABLE_LONG && n >= 0 }, dbm(info.cellSignalStrength.dbm),it.nrarfcn.orNull(), it.pci.orNull(), opName(it))}is CellInfoTdscdma -> info.cellIdentity.let {CellAnalyzer.Cell(CellAnalyzer.Rat.TDSCDMA, reg, it.mccString, it.mncString, it.lac.orNull(), it.cid.orNull()?.toLong(),- info.cellSignalStrength.dbm, it.uarfcn.orNull(), it.cpid.orNull(), opName(it))+ dbm(info.cellSignalStrength.dbm), it.uarfcn.orNull(), it.cpid.orNull(), opName(it))}else -> null}diff --git a/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt b/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.ktindex cb75266..d225022 100644--- a/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt+++ b/app/src/test/java/com/rfsentinel/app/detect/CellAnalyzerTest.kt@@ -136,4 +136,41 @@ class CellAnalyzerTest {val a = an.analyze(listOf(modern(area = 300, id = 42)), ctx(30_000, stationary = true))assertEquals(65, a.of("combined").single().confidence)}++ @Test+ fun aNeverSeenCellFarStrongerWhileStillIsASign() {+ val an = CellAnalyzer()+ an.analyze(listOf(modern(id = 1, dbm = -95)), ctx(0, stationary = true))+ an.analyze(listOf(modern(id = 1, dbm = -95)), ctx(15_000, stationary = true))+ assertTrue(an.analyze(listOf(modern(id = 7, dbm = -60)), ctx(30_000, stationary = true)).isEmpty())+ val a = an.analyze(listOf(modern(id = 7, dbm = -60)), ctx(45_000, stationary = true))+ assertEquals(40, a.of("strong-new").single().confidence)+ }++ @Test+ fun aStrongCellAlreadyKnownOrWhileMovingIsNot() {+ val known = CellAnalyzer()+ known.analyze(listOf(modern(id = 1, dbm = -95), cell(Rat.LTE, false, id = 7, dbm = -70)), ctx(0, stationary = true))+ known.analyze(listOf(modern(id = 1, dbm = -95)), ctx(60_000, stationary = true))+ known.analyze(listOf(modern(id = 7, dbm = -60)), ctx(75_000, stationary = true))+ assertTrue(known.analyze(listOf(modern(id = 7, dbm = -60)), ctx(90_000, stationary = true)).of("strong-new").isEmpty())+ val moving = CellAnalyzer()+ moving.analyze(listOf(modern(id = 1, dbm = -95)), ctx(0, stationary = false))+ moving.analyze(listOf(modern(id = 7, dbm = -60)), ctx(15_000, stationary = false))+ assertTrue(moving.analyze(listOf(modern(id = 7, dbm = -60)), ctx(30_000, stationary = false)).of("strong-new").isEmpty())+ }++ @Test+ fun anAreaNoNeighbourSharesIsASign() {+ val cells = listOf(cell(Rat.GSM, true, area = 555, id = 9)) ++ (2L..4L).map { cell(Rat.GSM, false, area = 100, id = it) }+ val an = CellAnalyzer()+ an.analyze(cells, ctx(0))+ assertEquals(35, an.analyze(cells, ctx(15_000)).of("odd-area").single().confidence)+ // One neighbour in the same area, or neighbours split between areas: a border, not a sign.+ val border = CellAnalyzer()+ val mixed = cells + cell(Rat.GSM, false, area = 555, id = 5)+ border.analyze(mixed, ctx(0))+ assertTrue(border.analyze(mixed, ctx(15_000)).of("odd-area").isEmpty())+ }}diff --git a/docs/SIGNATURES.md b/docs/SIGNATURES.mdindex a3118f9..b823714 100644--- a/docs/SIGNATURES.md+++ b/docs/SIGNATURES.md@@ -184,6 +184,10 @@ Read every 15 s from the cells Android reports (no root, location permission onl| Serving cell's MCC differs from the SIM's while not roaming (US 310-316 and India 404/405 are treated as one country) | 55 || Location / tracking area changed while GPS shows you standing still for 2+ minutes | 40 || Switched to a cell with no neighbours where several were visible moments ago | 35 |+| Serving cell announces a reserved area (0, 0xFFFE, 0xFFFF) or cell number 0 | 45 |+| A cell number seen before in another area (cloned identity) | 50 |+| A never-seen cell took over at -65 dBm or stronger, 20+ dB above the cell before it, while you stood still (after AIMSICD / SnoopSnitch) | 40 |+| Serving cell's area is shared by none of 3+ neighbours of the same network, which all agree on another (after AIMSICD) | 35 |Signs at or above the alert threshold alert; the rest go to the match history.