在前段时间的中科实数比赛中,很多同学被一道破解Android模拟器锁屏图案的问题难住了,在这里我简单写一下破解的思路和脚本:
0x00 gatekeeper.pattern.key
在早期版本(2.3-5.1)的Android手机中,锁屏密码相关的文件如下,这种类型的加密方式比较简单,只需要破解相关的SHA1的哈希值即可。
/data/system/password.key
/data/system/gesture.key
在6.0-8.0版本的Android手机中,锁屏密码相关的文件如下,该类型的加密方式则相对复杂,应该采用的是scrypt-hash算法(https://github.com/
dannycoates/scrypt-hash)。
/data/system/gatekeeper.pattern.key
/data/system/gatekeeper.password.key
0x01 解密
1.根据题目的信息,我们首先找到nox-disk2.vmdk
2.下一步,我们使用X-Ways Forensics 加载该文件,并看到
gatekeeper.pattern.key,gatekeeper.password.key以及device_policies.xml文件
3.根据device_policies.xml文件中,我们可以得到该解锁图案的长度为9.
4.根据https://nelenkov.blogspot.com/2015/06/password-storage-in-android-m.html提供的信息,并结合scrypt-hash算法,然后对文中给出的m-pass-hash.py进行改进后编写如下Python脚本,至于具体的算法原理,见https://github.com/dannycoates/scrypt-hash。
#!/usr/bin/python
# -*- coding:utf-8 -*-
import struct
import binascii
import scrypt
N = 16384;
r = 8;
p = 1;
f=open('gatekeeper.pattern.key', 'rb') #读取gatekeeper.pattern.key文件
blob = f.read()
s = struct.Struct('<'+'17s 8s 32s')
(meta, salt, signature) = s.unpack_from(blob) #提取其中关键的信息
f1=open('password.txt','r') #读取字典
lines=f1.readlines()
for data in lines:
password=data.strip()
to_hash = meta
to_hash += password #将字典中读取的密码和meta信息组合成to_hash
hash = scrypt.hash(to_hash, salt, N, r, p)
print 'signature %s' % signature.encode('hex')
print 'Hash: %s' % hash[0:32].encode('hex') #取hash值的前32位
print 'Equal: %s' % (hash[0:32] == signature)
if hash[0:32] == signature: #如果相同,程序结束
print "OK"
exit()
5.上面的py脚本中的password.txt实际上是所有不重复的9位数的组合,由以下代码生成(逻辑比较简单,同学们可自行优化):
file1=open('password.txt','a')
for a in "123456789":
for b in "123456789":
for c in "123456789":
for d in "123456789":
for e in "123456789":
for f in "123456789":
for g in "123456789":
for h in "123456789":
for i in "123456789":
if a != b and a != c and a != d and a != e and a != f and a!= g and a != h and a!= i
and b != c and b!= d and b != e and b != f and b!= g and b != h and b!= i
and c!= d and c != e and c != f and c!= g and c != h and c!= i
and d != e and d != f and d!= g and d != h and d!= i
and e != f and e!= g and e != h and e!= i
and f!= g and f != h and f!= i
and g != h and g!= i
and h!= i:
password = a + b + c + d + e + f + g + h + i
file1.write(password+'n')
file1.close()
0x02 运行该脚本(建议在Python2环境下运行),Pattern Get!
0x03 解锁成功!
原文始发于微信公众号(电子取证及可信应用协创中心):Cracking gatekeeper.pattern.key