<?xml version="1.0" encoding="utf-8"?>
<!--
    examples/inert-sample/AndroidManifest.xml

    ==========================================================================
    INERT TEACHING SAMPLE. THIS IS NOT MALWARE AND NEVER WAS.
    ==========================================================================

    Every component below is declared so that a triage tool has something real
    to find, and every component's implementation writes a line to logcat and
    returns. There is no payload, no command-and-control channel, no
    exfiltration, no evasion and no privilege escalation anywhere in this
    sample. It was written from scratch for chapter 69 of this repository.

    All indicators it carries resolve to nothing: the config blob decrypts to
    hostnames under `.invalid`, which RFC 2606 reserves permanently so that no
    such name can ever be registered or resolved.

    WHAT IT DOES DEMONSTRATE, and why each one is here:

      * ContentProvider persistence   BootstrapProvider runs inside
                                      ActivityThread.installContentProviders(),
                                      which is BEFORE Application.onCreate().
                                      Chapter 09 measured that ordering.
      * Boot persistence              BootReceiver listens for BOOT_COMPLETED,
                                      MY_PACKAGE_REPLACED and the OEM
                                      QUICKBOOT_POWERON alias.
      * Multi-process watchdog shape  SentinelService (main process) and
                                      GuardService (:guard process) each name
                                      the other. Neither restarts anything;
                                      both log what a live pair would do.
      * Granted-capability surface    An accessibility service, a notification
                                      listener and a device-admin receiver are
                                      DECLARED. None is ever requested, enabled
                                      or activated by any code in this sample,
                                      and all three implementations are empty.
      * Attribution surface           The app is signed with a throwaway key
                                      generated by build.sh, so the signer hash
                                      differs on every machine. That is the
                                      point of the attribution lab.
      * Encrypted config              assets/cfg-xor.bin and assets/cfg-aes.bin
                                      hold the two encodings that real config
                                      blobs overwhelmingly use.

    HOW TO BUILD:  ./build.sh          (builds out of tree; nothing lands here)
    HOW TO ANALYSE: ../../scripts/apk-triage.py "$OUTDIR/inert-sample.apk"

    DO NOT INSTALL THIS ON A PHONE YOU CARE ABOUT. It is harmless, but the
    habit is what matters, and the habit is: samples go on an emulator.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pentest.ch69.inert"
    android:versionCode="1"
    android:versionName="0.1-inert">

    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />

    <!-- Network access. The sample opens no socket; the permission exists so
         that the capability profile printed by apk-triage.py is not empty. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Persistence group. -->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

    <!-- Reconnaissance group. QUERY_ALL_PACKAGES is the one that matters:
         since API 30 an app cannot see the installed package list without it,
         so its presence in a sideloaded app is a strong triage signal. -->
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

    <!-- Overlay. Declared, never requested. On API 23+ this is a special
         access that the user must grant in a Settings screen the app cannot
         click for itself, unless it already holds accessibility. -->
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

    <!-- Messaging group. The sample registers no SMS receiver and reads no
         inbox. These are here so the triage tool's SMS capability row fires,
         and so lab 02 has something to adjudicate. -->
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />

    <!-- Package management. REQUEST_DELETE_PACKAGES is what a dropper uses to
         offer to remove its own stage one. -->
    <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

    <application
        android:label="Inert Sample CH69"
        android:allowBackup="false"
        android:hasFragileUserData="false"
        android:extractNativeLibs="true">

        <!-- ============================================================
             PERSISTENCE HOOK 1: the ContentProvider.
             onCreate() is called from ActivityThread.installContentProviders,
             which handleBindApplication invokes BEFORE Application.onCreate()
             for any provider whose android:multiprocess is false and whose
             process matches. initOrder only orders providers relative to each
             other; it does not move them after the Application.
             ============================================================ -->
        <provider
            android:name=".BootstrapProvider"
            android:authorities="com.pentest.ch69.inert.bootstrap"
            android:exported="false"
            android:initOrder="900"
            android:enabled="true" />

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="Inert Sample CH69">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- ============================================================
             PERSISTENCE HOOK 2: boot and self-update receivers.
             MY_PACKAGE_REPLACED fires after the app updates itself, which is
             how a stage-one survives its own upgrade. QUICKBOOT_POWERON is a
             non-AOSP alias several OEMs send instead of BOOT_COMPLETED.
             ============================================================ -->
        <receiver
            android:name=".BootReceiver"
            android:exported="true"
            android:enabled="true"
            android:directBootAware="false">
            <intent-filter android:priority="999">
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

        <!-- ============================================================
             PERSISTENCE HOOK 3: the watchdog pair.
             Two services in two processes, each naming the other. In live
             malware each restarts its peer when the peer dies, so killing one
             is not enough. Here neither restarts anything: both log the
             decision they would have taken. See the INERT constant in
             SentinelService.java.
             ============================================================ -->
        <service
            android:name=".SentinelService"
            android:exported="false"
            android:enabled="true"
            android:foregroundServiceType="dataSync"
            android:stopWithTask="false" />

        <service
            android:name=".GuardService"
            android:exported="false"
            android:enabled="true"
            android:process=":guard"
            android:stopWithTask="false" />

        <!-- ============================================================
             GRANTED-CAPABILITY SURFACE.
             Declared so that the triage tool reports them. Nothing in this
             sample ever asks the user to enable any of the three, and all
             three implementations are empty by design.
             ============================================================ -->
        <service
            android:name=".InertAccessibilityBridge"
            android:exported="true"
            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>

        <service
            android:name=".InertNotificationRelay"
            android:exported="true"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" />
            </intent-filter>
        </service>

        <receiver
            android:name=".InertAdminReceiver"
            android:exported="true"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>

        <!-- A meta-data key that looks like a config pointer. Triage tools
             flag these; this one points at an asset, not a server. -->
        <meta-data
            android:name="com.pentest.ch69.inert.CONFIG_ASSET"
            android:value="cfg-aes.bin" />

    </application>
</manifest>
