吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2972|回复: 7
收起左侧

[Android 原创] local Key Attestation 验证饶过

[复制链接]
pareto 发表于 2023-12-26 13:03
本帖最后由 pareto 于 2023-12-26 18:55 编辑

bootloaderspoofer 插件分析

自己做了一个本地绕过的脚本效果不是很理想,又去研究大佬的脚本,这个大佬的每次commit 基本我都看了,被大佬的底蕴折服,也印证了一句话,知识面越广,攻击面越广。
https://github.com/chiteroman/BootloaderSpoofer

核心流程见注释

[Java] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class Xposed implements IXposedHookLoadPackage {
    private static int indexOf(byte[] array) {
        final byte[] PATTERN = {48, 74, 4, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 10, 1, 2};
        outer:
        for (int i = 0; i < array.length - PATTERN.length + 1; i++) {
            for (int j = 0; j < PATTERN.length; j++) {
                if (array[i + j] != PATTERN[j]) {
                    continue outer;
                }
            }
            return i;
        }
        return -1;
    }
&#8203;
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
        try {
            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
            KeyStoreSpi keyStoreSpi = (KeyStoreSpi) XposedHelpers.getObjectField(keyStore, "keyStoreSpi");
            XposedHelpers.findAndHookMethod(keyStoreSpi.getClass(), "engineGetCertificateChain", String.class, new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    Certificate[] certificates = (Certificate[]) param.getResultOrThrowable();
                    if (certificates[0] instanceof X509Certificate cert) {
&#8203;
                        for (Method method : cert.getClass().getMethods()) {
                            if (method.getName().toLowerCase(Locale.ROOT).contains("verify")) {
                                // verify 不抛出异常表示验证通过
                                XposedBridge.hookMethod(method, XC_MethodReplacement.DO_NOTHING);
                            }
                        }
&#8203;
                        //获取证书编码,修改部分偏移的数据
                        //修改Device locked:true
                        //修改Verified boot state: Verified
                        byte[] bytes = cert.getEncoded();
                        if (bytes == null || bytes.length == 0) return;
                        int index = indexOf(bytes);//这个索引?
                        if (index == -1) return;
                        bytes[index + 38] = 1;
                        bytes[index + 41] = 0;
&#8203;
                        //替换证书
                        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
                        X509Certificate modCert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(bytes));
                        certificates[0] = modCert;
                        param.setResult(certificates);
                    }
                }
            });
        } catch (Throwable t) {
            XposedBridge.log(t);
        }
    }
}



这一版问题很明显,challenge 没有饶过,被修改的证书内容,实际无法通过公钥验证;又更新了一个版本,卧槽 被大佬深厚的底蕴震撼v3.5 , 这个版本的思路, 弥补之前的短板:
  • challenge 没有修复
  • 证书被修改后,实际没法通过公钥验证
那chiteroman怎么做的呢?
  • hook generateKeyPair ,返回插件预置的公私钥
  • hook setAttestationChallenge ,实时获取challenge
  • 替代 engineGetCertificateChain  函数,伪造整条证书链、并写入challenge
是吧 这个思路看起来很nice ,不过也存在问题 , 始终使用的内置的公私钥。换句话说,无论生成几次公私钥,始终是同一个公私钥,这一点问题。正常产生的公钥
image-20231222202803391.png

image-20231222202915406.png

怎么解决呢?
  • 内置多个证书
  • 中间人实时生产证书
我正在开发的脚本,思路就是直接走一个中间人发证书。因为个人兴趣原因,后续可能也会做很多设备异常判定的研究,有相同志向的小伙伴 不做黑产!!纯研究,可以私信我。我看人多的话,就拉个群大家一起交流。
https://github.com/chiteroman/BootloaderSpoofer
https://github.com/doom-man/bypasskeyattestation/blob/main/docs/other.md

免费评分

参与人数 3吾爱币 +9 热心值 +3 收起 理由
junjia215 + 1 + 1 谢谢@Thanks!
正己 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
saneyhy + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Hmily 发表于 2023-12-26 15:51
这个帖子图片也有问题会很快失效,看这个修改https://www.52pojie.cn/misc.php? ... 29&messageid=36
spawn_fly 发表于 2023-12-26 16:39
v12608 发表于 2023-12-27 20:46
Skyblue332 发表于 2023-12-28 02:26
这是不是和Android手机上的TEE有关?
 楼主| pareto 发表于 2023-12-28 14:50
Skyblue332 发表于 2023-12-28 02:26
这是不是和Android手机上的TEE有关?

是的,也可以是SE
zhangting2022 发表于 2023-12-30 05:56
感谢感谢分享
vae666 发表于 2024-11-21 17:13
佬,咋还断更了,继续学起来
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-4-27 20:24

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表