Skip to content

Commit

Permalink
lib: add IMSI requested heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
wgreenberg committed Jan 8, 2025
1 parent 10592bb commit 0c213a7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/src/analysis/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use serde::Serialize;

use crate::{diag::MessagesContainer, gsmtap_parser};

use super::{/*imsi_provided::ImsiProvidedAnalyzer,*/ information_element::InformationElement, lte_downgrade::LteSib6And7DowngradeAnalyzer, null_cipher::NullCipherAnalyzer};
use super::{
imsi_requested::ImsiRequestedAnalyzer,
information_element::InformationElement,
lte_downgrade::LteSib6And7DowngradeAnalyzer,
null_cipher::NullCipherAnalyzer,
};

/// Qualitative measure of how severe a Warning event type is.
/// The levels should break down like this:
Expand All @@ -18,7 +23,7 @@ pub enum Severity {
High,
}

/// [QualitativeWarning] events will always be shown to the user in some manner,
/// `QualitativeWarning` events will always be shown to the user in some manner,
/// while `Informational` ones may be hidden based on user settings.
#[derive(Serialize, Debug, Clone)]
#[serde(tag = "type")]
Expand Down Expand Up @@ -113,7 +118,7 @@ impl Harness {
pub fn new_with_all_analyzers() -> Self {
let mut harness = Harness::new();
harness.add_analyzer(Box::new(LteSib6And7DowngradeAnalyzer{}));
//harness.add_analyzer(Box::new(ImsiProvidedAnalyzer{}));
harness.add_analyzer(Box::new(ImsiRequestedAnalyzer::new()));
harness.add_analyzer(Box::new(NullCipherAnalyzer{}));

harness
Expand Down
59 changes: 59 additions & 0 deletions lib/src/analysis/imsi_requested.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::borrow::Cow;

use super::analyzer::{Analyzer, Event, EventType, Severity};
use super::information_element::{InformationElement, LteInformationElement};

const PACKET_THRESHHOLD: usize = 150;

pub struct ImsiRequestedAnalyzer {
packet_num: usize,
}

impl ImsiRequestedAnalyzer {
pub fn new() -> Self {
Self { packet_num: 0 }
}
}

impl Analyzer for ImsiRequestedAnalyzer {
fn get_name(&self) -> Cow<str> {
Cow::from("IMSI Requested")
}

fn get_description(&self) -> Cow<str> {
Cow::from("Tests whether the ME sends an IMSI Identity Request NAS message")
}

fn analyze_information_element(&mut self, ie: &InformationElement) -> Option<Event> {
self.packet_num += 1;
let InformationElement::LTE(LteInformationElement::NAS(payload)) = ie else {
return None;
};

// NAS identity request
if payload == &[0x07, 0x55, 0x01] {
if self.packet_num < PACKET_THRESHHOLD {
return Some(Event {
event_type: EventType::QualitativeWarning {
severity: Severity::Low
},
message: format!(
"NAS identity request detected, however it was within \
the first {} packets of this analysis. If you just \
turned your device on, this is likely a \
false-positive.",
PACKET_THRESHHOLD
)
})
} else {
return Some(Event {
event_type: EventType::QualitativeWarning {
severity: Severity::High
},
message: format!("NAS identity request detected"),
})
}
}
None
}
}
8 changes: 7 additions & 1 deletion lib/src/analysis/information_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use telcom_parser::{decode, lte_rrc};
use thiserror::Error;
use crate::gsmtap::{GsmtapType, LteRrcSubtype, GsmtapMessage};
use crate::gsmtap::{GsmtapMessage, GsmtapType, LteNasSubtype, LteRrcSubtype};

#[derive(Error, Debug)]
pub enum InformationElementError {
Expand Down Expand Up @@ -40,6 +40,9 @@ pub enum LteInformationElement {
SbcchSlBch(lte_rrc::SBCCH_SL_BCH_Message),
SbcchSlBchV2x(lte_rrc::SBCCH_SL_BCH_Message_V2X_r14),

// FIXME: actually parse NAS messages
NAS(Vec<u8>),

// FIXME: unclear which message these "NB" types map to
//DlCcchNb(),
//DlDcchNb(),
Expand Down Expand Up @@ -79,6 +82,9 @@ impl TryFrom<&GsmtapMessage> for InformationElement {
};
Ok(InformationElement::LTE(lte))
},
GsmtapType::LteNas(LteNasSubtype::Plain) => {
Ok(InformationElement::LTE(LteInformationElement::NAS(gsmtap_msg.payload.clone())))
},
_ => Err(InformationElementError::UnsupportedGsmtapType(gsmtap_msg.header.gsmtap_type)),
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod analyzer;
pub mod information_element;
pub mod lte_downgrade;
pub mod imsi_provided;
pub mod imsi_requested;
pub mod null_cipher;

0 comments on commit 0c213a7

Please sign in to comment.