Please note, this is a STATIC archive of website hashcat.net from 08 Oct 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.

hashcat Forum

Full Version: Cracking Android Pattern Hash
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The pattern hash on an Android phone is stored as a byte string like 0x00030607080502 to represent the pattern 0367852. However, this byte string is in hex and converted to nonsense characters first and then hashed with an SHA-1 hash. For example, the byte string would have to be run through xxd -r first before it was hashed. Is there a way to make hashcat assume that the input is in hex and then convert it before hashing? I could make a file with the hashcat mask processor and then use a script to hex-encode all the entries in the file and then use that as a wordlist, but I'm wondering if hashcat supports this so I dont have to do it. Thanks
if you can post here some step-by-step example from passcode to final hash i can see that i add it to hashcat
See this thread as a good example: https://hashcat.net/forum/thread-2011.html
Hi budabob07,

I don't think that there is something special w/ the pattern hashes... Maybe the only thing that you could argue is that they are (ALSO) special insecure...
I mean, it is correct that they use sha1 and that the security model should prevent someone to dump the content of gesture.key in /data/system/, but otherwise there is no sign of security... no salt.. iterations etc. NOTHING...

Therefore, they are plain sha1 hashes... and I do *not* think that atom should add something specific for those hashes.
Warning: I have a custom rom, therefore it could be different for someones stock rom. I do not know.

Why I think it is dangerous only having sha1... I often tell my friends that I have NOT enough credit on my phone, I just want to make a call (iff I don't have credit of course). I could simply take there *rooted* phone, open Android Terminal Emulator, cat /data/system/gesture.key and have the lock pattern... or? YES!

I want to document something here so others can test themself:
Hint: the enumeration is as follows:
0 1 2
3 4 5
6 7 8
1. This should be the widget in question: https://github.com/android/platform_fram...Utils.java
2. Class to handle the lock settings: https://github.com/android/platform_fram...rvice.java
3. My test:
Code:
$ adb devices
$ adb pull /data/system/gesture.key gesture.key01458
$ wc gesture.key01458
0 1 20 gesture.key01458
$ # several test show, that length is ALWAYS 20 (sha1?)
$ cat gesture.key01458|xxd -g1
0000000: ae 93 f0 d3 b7 7f 4a b4 2a 4c 90 de 52 91 a8 a1  ......J.*L..R...
0000010: 9b b6 54 0f                                      ..T.
$ javac PatternLock.java;java PatternLock 01458
ae93f0d3b77f4ab42a4c90de5291a8a19bb6540f
4. The fast written,*not* beautiful,to improve code that generates (hex version of) a test gesture.key file:
Code:
import java.lang.Integer;
import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;

public class PatternLock {
    public static void printHash(byte[] hash) {
        // a simple dumper, use other Java build-ins instead if u prefer
        int i;
        if (hash.length!=20) {
            System.out.print("[!] Warning: hash length is different than 20...w t f ?");
        }
        for (i=0;i<hash.length;i++) {
            System.out.printf("%02x",hash[i]);
        }
        System.out.println();
    }
    public static void main(String[] args) {
        if (args.length<1) {
            System.out.println("[-] Please specify the pattern as first command line argument, e.g 01234");
            System.exit(1);
        }
        // size check
        String pattern=args[0];
        if (pattern.length()<4) {
            System.out.println("[!] Warning: Android does *not* allow pattern smaller than 4");
        }
        int i,cur_pattern;
        byte[] res=new byte[pattern.length()];
        for (i=0;i<pattern.length();i++) {
            try {
                cur_pattern=Integer.parseInt(pattern.substring(i,i+1));
                if (cur_pattern>=0 && cur_pattern<9) {
                    res[i]=(byte)cur_pattern;
                } else { // we should never be able to enter here !?
                    System.out.println("[!] Warning: The number is *not* within the allowed range");
                }
            } catch(NumberFormatException e) {
                System.out.println("[!] Warning: C'mmon the pattern should be numerical");
            }
        }
        try {
            MessageDigest md=MessageDigest.getInstance("SHA-1");
            byte[] hash=md.digest(res);
            printHash(hash);
        } catch (NoSuchAlgorithmException nsa) {
            printHash(res);
        }
    }
}


Therefore, nothing special for hashcat (and atom, hehe) to do... Maybe Android should do somehing about it!?

You can dump (cat) the gesture.key file and convert it to hex and feet it to hashcat iff you really want....
That was easy Smile

Hashcat already supports this, check out this example:

Quote:
root@ht:~/hashcat-0.45# cat hash
ae93f0d3b77f4ab42a4c90de5291a8a19bb6540f

root@ht:~/hashcat-0.45# ./hashcat-cliXOP.bin -m 100 -a 3 -o key hash --hex-charset -1 000102030405060708 ?1?1?1?1?1
Initializing hashcat v0.45 by atom with 8 threads and 32mb segment-size...

Added hashes from file hash: 1 (1 salts)
Activating quick-digest mode for single-hash

...

All hashes have been recovered

root@ht:~/hashcat-0.45# xxd key
0000000: 6165 3933 6630 6433 6237 3766 3461 6234 ae93f0d3b77f4ab4
0000010: 3261 3463 3930 6465 3532 3931 6138 6131 2a4c90de5291a8a1
0000020: 3962 6236 3534 3066 3a00 0104 0508 0a 9bb6540f:......


Take a close look at the last line:

0000020: 3962 6236 3534 3066 3a00 0104 0508 0a 9bb6540f:......
(03-24-2013, 04:10 PM)atom Wrote: [ -> ]That was easy Smile

Hashcat already supports this, check out this example:

Quote:
root@ht:~/hashcat-0.45# cat hash
ae93f0d3b77f4ab42a4c90de5291a8a19bb6540f

root@ht:~/hashcat-0.45# ./hashcat-cliXOP.bin -m 100 -a 3 -o key hash --hex-charset -1 000102030405060708 ?1?1?1?1?1
Initializing hashcat v0.45 by atom with 8 threads and 32mb segment-size...

Added hashes from file hash: 1 (1 salts)
Activating quick-digest mode for single-hash

...

All hashes have been recovered

root@ht:~/hashcat-0.45# xxd key
0000000: 6165 3933 6630 6433 6237 3766 3461 6234 ae93f0d3b77f4ab4
0000010: 3261 3463 3930 6465 3532 3931 6138 6131 2a4c90de5291a8a1
0000020: 3962 6236 3534 3066 3a00 0104 0508 0a 9bb6540f:......


Take a close look at the last line:

0000020: 3962 6236 3534 3066 3a00 0104 0508 0a 9bb6540f:......
Alright, I tried --hex-charset before with just ?d flags but I didn't define a custom mask. This works. Thank you!