// 73-Labs/examples/chain-target/src/com/pentest/ch73/chain/AdminReceiver.java
//
// Lab 02's DECOY. This receiver is exported and it does something alarming, and
// it is NOT a finding.
//
//   Finding 3 (decoy)  exported="true" with a signature-level permission. A
//                      scanner reports "exported receiver performing a
//                      destructive action". A tester who stops at the manifest
//                      files it as high severity. Nobody can reach it: the
//                      permission is protectionLevel="signature", so only a
//                      package signed with the same certificate may send the
//                      broadcast, and no such package exists.
//
// Lab 02 section 6 asks you to try to trigger it, fail, read the failure, and
// then write the sentence that belongs in a report -- which is not "not
// exploitable" but "unreachable by any caller we could construct, because X".
//
// The difference between those two sentences is most of what separates a
// finding from a false positive, and it is why the dynamic stage exists.
//
// AUTHORISED TESTING ONLY. This receiver does not actually delete anything; it
// logs what it would have done.

package com.pentest.ch73.chain;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;

public class AdminReceiver extends BroadcastReceiver {

    private static final String TAG = "ch73chain";

    @Override
    public void onReceive(Context context, Intent intent) {
        // If you ever see this line in logcat, the permission gate did not
        // hold and the decoy has become a real finding. Say so in the report,
        // and say which device it happened on.
        Log.w(TAG, "AdminReceiver reached by uid "
                + android.os.Binder.getCallingUid()
                + " action=" + (intent == null ? "(null)" : intent.getAction()));

        SharedPreferences prefs =
                context.getSharedPreferences("vault", Context.MODE_PRIVATE);
        Log.w(TAG, "AdminReceiver would clear " + prefs.getAll().size()
                + " preference entries (it does not, this is a lab)");
    }
}
