This lab Practice illustrates the concept of intent spoofing where the comp2 broadcatReceiver in App1 expects to get broadcast intent with data from Comp1 activity in the App1 but instead, it gets a malicious injection via an implicit intent sent by a malicious external app App2. This is an intra-app IPC with intent spoofing which can be prevented with secure programming. This Hands-on lab practice contains a receiver that is used for intent spoofing.
Create a new Android Studio project and name it “IntentSender” with company domain of "com.example" and click on Next
Open Android Application and build this project step by step as following. In this lab practice you need to find out security Bugs in your build code because as a software development process, a code builder needs to consider the security issue and malicious attacked can be attempt due to your poor coding activity while building an Apps. This process helps to understand to find out Security Bugs in programming code.
File->New-> New Project->Select Basic Activity->Click Next
Create a new Android Studio project and name it “intentsender” with the company domain of "com.example" and click on Next
Copy and paste the following code into “MainActivity.java” and "Other Pages"
//Copy and paste the following code into “MainActivity.java”.
//MainActivity.java
package example.com.intentsender;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.button1);
}
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("number", 1);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
intent.setComponent(new ComponentName("example.com.broadcastreceiver","example.com.broadcastreceiver.MyBroadCastReceiver"));
intent.setAction("com.example.MyBroadcast");
sendBroadcast(intent);
}
}
//Copy the following code into “activity_main.xml”. Make sure to click on the “Text” tab at the bottom left of the “activity_main.xml” window
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="example.com.intentsender.MainActivity"
tools:ignorae="MergeRootFrame" >
<Button
android:layout_gravity="center"
android:id="@+id/button1"
android:onClick="onClick"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Broadcast" />
</LinearLayout>
Note: Check FindBugs you need to follow module 1 for FindBugs configuration and you need to check the following configuration before run "SpotBugs".
Now Click the "SpotBugs"
Copy the following code into “activity_main.xml”. Make sure to click on the “Text” tab at the bottom left of the “activity_main.xml” window
Click"Analyze Scope Files" then click OK as show below