So now we have a simple shopping list app obviously it's not Market ready but we just wanted to show 1
a simple app that uses some of the main features in an app. 2
Now let's imagine that the person creating this app has a malicious intent say for example they want 3
to intercept incoming SMS messages and send them to their server so to do this we need to create a broadcast 4
receiver. Think of a broadcast receiver as a service running in the background that listens to system 5
wide events such as an SMS being received and the phone booting up so any app that wants to trigger 6
an event upon seeing that a system wide event occurred has to implement a broadcast receiver let's create 7
a new class called SMS receiver. 8
Leave the default config for now OK this is a plain class let's make it extend broadcast receivers. 9
This will give errors so alt and enter to fix the errors and you see that it creates a new method called 10
on receive so for now this is a generic broadcast receiver. 11
The first thing we need to do is determine what system wide event just occurred and we want to determine 12
if it is sms received so to do this. 13
Define a string called SMS received and set it to Android dot provider dot to left any dot SMS underscore 14
received now first thing we're going to do is say if intent dot get action dot equals S M S received 15
and then we want to do something OK. 16
So here we see that we have an on receive event. 17
This could be S M S received but it could also be other events so we are asking the system OK what is 18
the event that just occurred. 19
Is it s m s received? Yes then OK let's do this on the S M S received. 20
Now again remember that as a developer you would just Google Android receive S M S programmatically 21
first answer is usually Stack Overflow. Usually someone is asking a question then someone provides a 22
correct answer find an example that looks right. 23
And copy and paste the content and fix the issues. 24
Now let's toast the message, toast means to alert the user. 25
So show text in a pop up window. 26
OK. 27
So toast. 28
Dot. 29
Make text. 30
Context the string to pass let's copy this from the log. 31
Give the length of the toast. 32
So how long to keep the message prompted. 33
Then show. 34
Now this is not going to work out of the box. 35
This is for two reasons one. 36
We need to define this broadcast in our manifest since this is an android component and two we need 37
to add the permission of S.M.S receive to the app. 38
Now to add a receiver just add receiver and Android name then add an intent filter and say Action. 39
Android colon name equals Android dot provider. 40
The telephony DOT SMS underscore received then we define the permission on top of the application. 41
Just add uses permissions and find receive S M S then close the permission. OK. 42
So without these the S M S receiving functionality will not work. 43
Now as reverse engineers. 44
This is great for us. 45
Say we have the suspicion that an app is stealing received S M S the first thing we need to do is 46
go to the manifest and see if there is such a broadcast and if there is the S M S permission. If this 47
is the case then we know that indeed the app is receiving S M S's. 48
Then we would look into the defined broadcast receiver to see what the app is actually doing with the 49
S M S's. 50
We will be doing exactly this in the next section. 51
OK so before we run since Android version 6 a new step was added when requesting dangerous permissions 52
so inside our main activity we need to create a method that prompts the user to explicitly allow the 53
permission at runtime so the first time the user runs the app they will be prompted to confirm that 54
the app can receive S M S's, so to do this we will create a method called request permission. I'll just 55
copy the text here. 56
Again this is a very common operation so just Google how to request permission programmatically. Here you'll 57
see that we're checking for the app version then we are checking if the permissions are already granted 58
and if not we are requesting the permissions. OK so let's run the app, here we will be prompted to allow 59
S M S receive now here there is this utility that allows us to emulate a number of operations such as 60
the receipt of an SMS. So here we are emulating the receipt of an S M S so go to phone add the number 61
add the text and click Send message and you will see the S M S being prompted. Obviously the malicious 62
code will not want to prompt to the user but rather sent to a malicious server and this is what we will 63
do in the next lesson.