Posts Tagged ‘screen lock’

Cracking PIN and Password Locks on Android

Tuesday, February 28th, 2012

As you may know it is possible to get around the pin and password lock on an Android smartphone. In this post we will describe the following two ways to get around it:

  • on a rooted smartphone
  • with the help of the JTAG interface

Some Background Information

Since version 2.2 Android provides the option of a numeric PIN or alphanumeric password as an alternative to screen lock. Both pass phrases are required to be between 4 and 16 digits or characters in length.

     

Android stores this pattern in a special file called password.key in /data/system/. As storing the pattern in plain text wouldn't be very save, this time Android stores an salted SHA1-hashsum and MD5-hashsum of the PIN or password. The numeric PIN and the alphanumeric passwords are processed in the same way (see the following code snippet).

 public byte[] passwordToHash(String password) {
        if (password == null) {
            return null;
        }
        String algo = null;
        byte[] hashed = null;
        try {
            byte[] saltedPassword = (password + getSalt()).getBytes();
            byte[] sha1 = MessageDigest.getInstance(algo = "SHA-1").digest(saltedPassword);
            byte[] md5 = MessageDigest.getInstance(algo = "MD5").digest(saltedPassword);
            hashed = (toHex(sha1) + toHex(md5)).getBytes();
        } catch (NoSuchAlgorithmException e) {
            Log.w(TAG, "Failed to encode string because of missing algorithm: " + algo);
        }
        return hashed;
}

Due to the fact that the hash is salted this time, its unfeasible to crack the password with help of a dictionary attack. For cracking the password it is important to get the salt and enough time for attempting a brute force attack. The salt is a string of the hexadecimal representation of a random 64-bit integer. To get this salt, there are two ways from which you can choose.

On a Rooted Smartphone:

If you deal with a rooted smartphone and USB debugging is enabled, cracking of the pattern lock is quite simple. You just have to dump the file /data/system/password.key and the salt, which is stored in a SQLite database under the lockscreen.password_salt key. The corresponding database can be found in /data/data/com.android.providers.settings/databases and is called settings.db (see the figure below). After you got both information you just need to start brute forcing the password.

With the Help of the JTAG Interface:

If you deal with a stock or at least unrooted smartphone this whole process is a bit more complicated. First of all, you need special hardware like a Riff-Box and an JIG-adapter or some soldering skills. After you have gained a physical dump of the complete memory chip the chase for the password lock can start. To find the hashsums of the passphrase you need to have the following points in mind:

  • The dump of the memory is broken into chunks of 2048 bytes
  • The password.key file contains two hashes, together 72 bytes long:
    • a SHA-1 hash (20 bytes long)
    • a MD5 hash (16 bytes long)
  • These hashes only contain the characters 0-9 and A-F
  • The following 1960 bytes of the chunk are zeros
  • The remaining 16 bytes of the chunk are random

Finding the SQLite-database an the salt in it is way harder as finding the hashes. As SQLite stores all data in plain text we have one first reference point - the lockscreen.password_salt string. When we find this string in our dump, we should be very close to the actual salt. At this point it is important to understand the SQLite-File-Format.

Using this information we can create two rulesets to find the position of the salt as well as the actual salt (refer to the figure below for a better understanding):

  • Search for the string "lockscreen.password_salt".
  • The byte directly in front has to be between 0x0F and 0x35. This byte represents the length of our salt and is called byteA for a better understanding of the rest of this article.
  • In front of this byte, there has to be a byte with 0x3D (indicates a serial type representing a string with a length of 24). This is the length of our string we searched for.
  • In front of this byte has to be a zero byte

If the first ruleset applies, we have found the right position in our dump and we can now start to extract the salt.

  • Decoding byteA gives us the length of the salt and has to between 1 and 20 bytes.
  • Now we have to extract this amount of bytes directly after the string "lockscreen.password_salt"
  • These bytes are the salt!

After we got both information (hashes and salt) we can again start our brute force attack! In our test we could crack PIN's (with up to 10 digits) and simple passwords (with up to 5 chars) within one hour.

Cracking the Pattern Lock on Android

Tuesday, February 28th, 2012

As you maybe know it is very easy to get around the pattern lock on an Android smartphone. In this post we will describe the following two ways to get around it:

  • on a rooted smartphone
  • with the help of the JTAG interface

Some Background Information

The pattern lock is entered by the user joining points on a 3×3 matrix in his/her chosen order. Since Android 2.3.3 this pattern must involve a minimum of 4 points (on older Android versions the minimum was 3 points) and each point can only be used once. The points of the matrix are registered in a numbered order starting by 0 in the upper left corner and ending by 8 in the bottom right corner. So the pattern of the lock screen in the next figure would be 0 - 3 - 6 - 7 - 8.

      

Android stores this pattern in a special file called gesture.key in /data/system/. As storing the pattern in plain text wouldn't be very save, Android only stores an unsalted SHA1-hashsum of this pattern (see the code snippet afterwards). Accordingly, our pattern is stored as c8c0b24a15dc8bbfd411427973574695230458f0.

private static byte[] patternToHash(List pattern) {
    if (pattern == null) {
        return null;
    }

    final int patternSize = pattern.size();
    byte[] res = new byte[patternSize];
    for (int i = 0; i < patternSize; i++) {
        LockPatternView.Cell cell = pattern.get(i);
        res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
    }
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] hash = md.digest(res);
        return hash;
    } catch (NoSuchAlgorithmException nsa) {
        return res;
    }
}

Due to the fact, that the pattern has a finite and very small number of possible combinations the use of an unsalted hash isn't very save. It is possible to generate a dictionary (rainbow table) with all possible hashes and compare the stored hash with that dictionary in a few seconds. To assure some more safety, Android stores the gesture.key file in a restricted area of the filesystem where a normal user can't access it. If you have to get around it, there are two ways from which you can choose.

On a Rooted Smartphone:

If you deal with a rooted smartphone and USB debugging is enabled, cracking of the pattern lock is quite easy. You just have to dump the file /data/system/gesture.key and compare the bytes of this file with your dictionary. If the smartphone is rooted but USB debugging is disabled, you just need to google a bit, there are plenty ways to enable debugging from outside the phone.

With the Help of the JTAG Interface:

If you deal with a stock or at least unrooted smartphone this whole process is a bit more complicated. First of all, you need special hardware like a Riff-Box and an JIG-adapter or some soldering skills. After you have gained a physical dump of the complete memory chip the chase for the pattern lock can start. In our experiment we used a HTC Wildfire with a custom ROM and Android 2.3.3 flashed on it and the pattern lock from the beginning of this post. After looking at the dump, we noticed that every chunk has an exact size of 2048 bytes. Since we know that our gesture.key file has 20 bytes of data (SHA1-hashsum) we searched for this combination of bytes and noticed, that there is one chunk starting with this 20 bytes followed by 2012 bytes of zeros and about 16 random bytes (seems to be some meta filesystem information). We did the same search on several other smartphone dumps (mainly older Android versions on the same phone) and it came out, that this method is the easiest way to get the pattern lock without being root.

In other words:

  • try to get a physical dump of the complete memory
  • search for a chunk with a size of 2048 bytes, starting with 20bytes random, followed by 2012 bytes zeros and 16 bytes random
  • extract that 20 bytes random at the beginning of the chunk
  • compare these 20 bytes with your dictionary
  • type in the corresponding pattern on the smartphone itself

We also included this functionality and a dictionary in our forensic toolkit ADEL.

Cracking the Face Recognition Lock on Android

Tuesday, February 28th, 2012

Since Android 4.0 is available, the user has the possibility to unlock his smartphone by looking in the front-camera. This feature is called face unlock.

Just some hours after Google has presented the new Android version including this feature, it was broken by some blogger who just hold a picture of the person the smartphone belongs to in front of the locked smartphone. As a proof, there are plenty videos on youtube. With this demonstration in mind, you have to come to the conclusion that face recognition isn't a real lock feature, its more a fancy way of the old screen lock were you just have to swipe over the display.

In all fairness, Google did mention that face unlock is less secure than a pattern, pin or password and that someone that looks similar to you could unlock your phone, but they didn't mention, that it is so easy to unlock it.

In other words:

  • just take a picture of the smartphone owner
  • hold this picture in front of the smartphone when unlocking it