Bypassing screen locks

Just like most other devices, Android devices have got a screen lock mechanism to prevent unauthorized use of someone's device, as shown in the following screenshot:

Bypassing screen locks

Android devices usually have the following types of screen lock:

As the first two types do not require any additional skills to bypass the screen lock, we will discuss some techniques available to bypass the other three types of screen lock.

Pattern lock on Android devices is a type of screen lock where the user needs to connect the right combination of dots, as shown in the following screenshot:

Bypassing pattern lock using adb

We can imagine those dots with numbers as shown below:

Bypassing pattern lock using adb

The preceding pattern in this case becomes 14789.

When a user sets the pattern, Android hashes the input pattern value and stores it in a file called gesture.key located in /data/system. This is accessible only to the root and thus we need root privileges in order to access this file.

There are two possibilities to bypass pattern locks on rooted devices:

Bypassing the password/PIN require the same steps to be followed. However, this is not as straightforward as we saw with pattern lock:

Bypassing password/PIN using adb

When a user creates a password/PIN, a hash will be created and it will be stored in a file called password.key in /data/system. Additionally, a random salt is generated and stored in a file called locksettings.db in the /data/system path. It is required to use this hash and salt in order to brute force the PIN.

Let's first pull password.key and locksettings.db from their respective locations shown following:

/data/system/password.key

/data/system/locksettings.key

I am using the same steps we used with gesture.key.

Copy the files on to the SD card:

Pull the files from the sdcard:

Now, let's get the hash from the password.key file. We can open the password.key file in a hex editor and grab the hash, as shown in the following screenshot:

Bypassing password/PIN using adb

Let's open up the locksettings.db file using the SQLite3 command-line tool and get the salt.

It is stored in the locksettings table and can be found at the lockscreen.password_salt entry:

We now have both the hash and salt. We need to brute force the PIN using these two.

The folks at http://www.cclgroupltd.com have written a nice Python script that can brute force the PIN using the hash and salt. This can be downloaded from the link below and it is free:

http://www.cclgroupltd.com/product/android-pin-password-lock-tool/Run the following command using the BruteForceAndroidPin.py file:

Python BruteForceAndroidPin.py [hash] [salt] [max_length_of_PIN]

Running the preceding command will reveal the PIN, as shown following:

Bypassing password/PIN using adb

The time required to crack this PIN depends on the complexity of the PIN set by the user.

In 2013, Curesec disclosed a vulnerability that allowed the lock screen to be cleared without the appropriate user interaction on Android devices. This is basically a vulnerability in the com.android.settings.ChooseLockGeneric class. A user can send an intent to disable any type of screen lock:

Running the preceding command will disable the lock screen.