Cracking the Pattern Lock on Android

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.

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.

%d bloggers like this: