Book Image

Mobile Device Exploitation Cookbook

By : Akshay Dixit
Book Image

Mobile Device Exploitation Cookbook

By: Akshay Dixit

Overview of this book

Mobile attacks are on the rise. We are adapting ourselves to new and improved smartphones, gadgets, and their accessories, and with this network of smart things, come bigger risks. Threat exposure increases and the possibility of data losses increase. Exploitations of mobile devices are significant sources of such attacks. Mobile devices come with different platforms, such as Android and iOS. Each platform has its own feature-set, programming language, and a different set of tools. This means that each platform has different exploitation tricks, different malware, and requires a unique approach in regards to forensics or penetration testing. Device exploitation is a broad subject which is widely discussed, equally explored by both Whitehats and Blackhats. This cookbook recipes take you through a wide variety of exploitation techniques across popular mobile platforms. The journey starts with an introduction to basic exploits on mobile platforms and reverse engineering for Android and iOS platforms. Setup and use Android and iOS SDKs and the Pentesting environment. Understand more about basic malware attacks and learn how the malware are coded. Further, perform security testing of Android and iOS applications and audit mobile applications via static and dynamic analysis. Moving further, you'll get introduced to mobile device forensics. Attack mobile application traffic and overcome SSL, before moving on to penetration testing and exploitation. The book concludes with the basics of platforms and exploit tricks on BlackBerry and Windows Phone. By the end of the book, you will be able to use variety of exploitation techniques across popular mobile platforms with stress on Android and iOS.
Table of Contents (11 chapters)
Mobile Device Exploitation Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface

Creating a simple Android app and running it in an emulator


Now that we are ready with the Android SDK, let's write our first Android application. A little bit of coding skill is needed to get started. However, don't worry if source code scares you. There is a lot of sample code available in the Internet communities for you to use to get started.

Getting ready

To get ready to code the Android application, you need the SDK to be working well. If you have followed the first recipe and know a little bit of Java programming, the rest is easy and you are all set to code your very first Android application.

How to do it...

Let's write a very simple program to add two numbers together. I used the Eclipse IDE and created an Android application project called Addition:

  1. Create the graphical layout. Drag and drop three text fields (one each for the first number and the second number, and the last one to print the sum of the first two numbers), two TextView boxes to display text so that the user knows to enter two numbers, and finally a button for the addition action.

    • The activity_main.xml file is autogenerated. Edit it to look like the following code:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <TextView>
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="First Number"
    Text displayed to guide user to input first number
        </TextView>
    
        <EditText>
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:id="@+id/e1"
    Variable e1 is declared to be referenced in java file.
            android:inputType="textPassword"
        </EditText>
    
        <TextView>
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Second Number"
        </TextView>
    
        <EditText>
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:id="@+id/e2"
            android:inputType="textPassword"
        </EditText>
    
        <Button>
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="122dp"
            android:text="Add"
    
    • Add the declared button:

        </Button>   
        <EditText>
            android:text=""
            android:id="@+id/t3" 
    
    • Finally, the third variable, which will contain the sum of the two numbers, is declared:

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
        </EditText>
    </RelativeLayout>
    
  2. Now we have to write Java code to input and add the numbers, and output the sum. At this point, don't worry if you do not know Activity, Intent, and so on. Just focus on getting the code error-free. Eclipse guides you at each step. We start our program with MainActivity, coded like this:

    package com.android.addition;
     
    import android.os.Bundle;
    import android.app.Activity;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Button;
    import android.view.View;
     
    public class MainActivity extends Activity {
        EditText e1;
        EditText e2;
        TextView t3;
        Button add;
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            add=(Button)findViewById(R.id.action_settings);
            add.setOnClickListener(new Button.OnClickListener()
                {
            public void onClick
            (View v){Sum();}});
        }
            private void Sum(){
              int s1=Integer.parseInt(e1.getText().toString());
              int s2=Integer.parseInt(e2.getText().toString());
              int s3=s1+s2;
              t3.setText(Integer.toString(s3));
             }
    }
     
    

    See how straightforward this program is; it just takes two numbers, adds them together, and provides the result.

  3. Debug and run the program. The emulator opens up and the program runs.

See also

  • Android In Action, Ableson, Sen, King, Manning Publications Co.