Cracking PIN and Password Locks on Android
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.
Tags: ADEL, Android, forensic, screen lock
March 15th, 2012 at 4:05 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 4:11 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 4:13 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 4:23 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 4:53 PM
[...] the FBI is apparently "unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques" to crack the phone and grab its [...]
March 15th, 2012 at 5:57 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 6:23 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 10:42 PM
[...] is apparently “unable, or reluctant to use commercially accessible forensics collection or widely documented hardware-hacking techniques” to moment a phone and squeeze a data.Soghoian also wonders if a [...]
March 15th, 2012 at 11:12 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 11:28 PM
[...] the FBI is apparently “unable, or unwilling to use commercially available forensics tools or widely documented hardware-hacking techniques” to crack the phone and grab its [...]
March 15th, 2012 at 11:37 PM
I just hope Google doesn't allow the FBI to mock the us constitution which was set forth by our forefathers. it's more than them trying to unlock a pimp's smart phone riding on this. there are laws that govern this kinda stuff. what about due-process? due-diligence? right to privacy? search and seizure? i've read many of articles and the actual search warrant regarding this matter, it's all he say-she say, or mere assumptions from this man's past-life. nothing factual.
if Google provides entry into this man's phone; where does our society go from here? who's rights are violated next? o yea, it will continue, think about it.... IT MAY BE YOU! are we a democracy? or, are we becoming a communist society? hnmmmmm!
March 17th, 2012 at 3:11 AM
[...] quiere usar herramientas forenses disponibles a nivel comercial o técnicas para hackear hardware ampliamente documentadas” para crackear el teléfono y obtener la [...]
March 30th, 2012 at 8:52 PM
[...] Dank,Greetz Lp Das Video ist nicht auffindbar.Eventuell spielst Du aber auf diesen Link hier an?http://forensics.spreitzenbarth.de/2012/02/28/cracking-pin-and-password-locks-on-android/T S__________Ich bin ein [...]
April 2nd, 2012 at 4:11 PM
[...] very first line of defense, but know that this is a feeble defense at best. Handy instructions on how to crack a pin and password lock on Android are here, how to crack the pattern lock here, and for good measure, see how easy it is to crack the face [...]
April 4th, 2012 at 3:50 PM
Didn't you mean:
If you deal with a rooted smartphone OR USB debugging is enabled
Because USB debugging allows easy access to all files with adb shell. Rooted phones often have options to make entire file system backups to the SD card (just boot into backup mode). I'm refering to: "just have to dump the file". How?
April 4th, 2012 at 4:17 PM
Hi floyd,
no, in this case I really mean AND.
when you have a rooted device with enabled USB debugging you can run the following commands on your PC (with installed android sdk):
$ adb pull /data/system/password.key .
$ adb pull /data/data/com.android.providers.settings/databases/settings.db .
if your device is not rooted and USB debugging is enabled this commands won't work because you have insufficient access rights for these two folders
if you have a rooted device with disabled USB debugging you can try to enable USB debugging remotely or boot into recovery mode, create a android backup and restore the files from this backup on your local PC.
I hope this answers your question.
Best Regards,
Michael
April 4th, 2012 at 8:27 PM
[...] Zugriffsschutz auszuhebeln. Auch bei einigen Android-Versionen ist bereits dokumentiert, wie man Passcode-Sperre und Mustereingabe umgeht. Während der Aufwand bei gerooteten Geräten überschaubar ist, ist das [...]
April 4th, 2012 at 10:09 PM
@mspreitz
If the phone is rooted, debugging disabled, encrypted using ICS, does that change anything?
April 4th, 2012 at 10:22 PM
@Whatevs
unfortunately, I hadn't the chance to get my hands on an ICS running device yet.
April 10th, 2012 at 10:54 PM
For a newbie but interested in learning this. Can you tell me how to bruteforce ?
Some automatic way to bruteforce using the information acquired?
My phone is nexus S, rooted and running Icecream sandwitch
April 18th, 2012 at 10:15 AM
Hi PsyRead,
I'm not sure how it is working in ICS, as far as I have seen the Android source code right now, there were some modifications in this area (e.g. no md5 hashes anymore) and our own scripts inside ADEL are not working with Android 4.0.3 at present. But we are working on a solution!
Best regards,
Michael
May 14th, 2012 at 3:19 PM
Hi Michael,
In your comments, you're talking about enable USB debugging remotely. How is it possible? Do you have some example?
Thanks a lot
Geo
October 25th, 2012 at 5:21 PM
[...] [...]
November 3rd, 2012 at 12:43 AM
[...] ge”JTAG”ten Android-Phones zeigt, wie schnell man um die Passwortsperre herumkommt: Link. Doch ist es schon einmal eine erstes Hindernis und man kann nicht mal eben an das Ding heran, [...]
January 28th, 2013 at 12:43 AM
If the phone is already locked, how do you get access to these files?
January 28th, 2013 at 12:53 AM
It depends on the phone type. On some phones you can use a modified recovery image with enabled adb and root shell, on other phones you can extract this data with the help of a JTAG box.