首页
社区
课程
招聘
[原创]Frida Bypass Android SSL pinning example 1
发表于: 2018-11-24 23:44 10244

[原创]Frida Bypass Android SSL pinning example 1

2018-11-24 23:44
10244

Package

$ aapt d badging com.p1.mobile.***.apk
package: name='com.p1.mobile.***' versionCode='233' versionName='3.2.8' platformBuildVersionName='8.0.0'
sdkVersion:'16'
targetSdkVersion:'22'

Details

package l;

/* renamed from: l.cNi */
final class C3253cNi extends C5966cNk {
    static final class iF extends C5967cNq {
        /* renamed from: ˏ */
        public final C5967cNq m16620(X509TrustManager x509TrustManager) {
            try {
                Class cls = Class.forName("android.net.http.X509TrustManagerExtensions");
                return new iF(cls.getConstructor(new Class[]{X509TrustManager.class}).newInstance(new Object[]{x509TrustManager}), cls.getMethod("checkServerTrusted", new Class[]{X509Certificate[].class, String.class, String.class}));
            } catch (Exception unused) {
                return super.m16518(x509TrustManager);
            }
        }
    }
}

在l.cNi中有个函数m16620使用的 X509TrustManagerExtensions.checkServerTrusted 获取证书链

 

Android源码中X509TrustManagerExtensions.checkServerTrusted的定义

public List<X509Certificate> checkServerTrusted(X509Certificate[] chain, String authType,
                                                String host) throws CertificateException {

X509Certificate[] chain 是当前域名的证书

 

String host 是当前域名

 

不打开Charles,看看checkServerTrusted的参数和返回值

checkServerTrusted - Arg 0: Certificate:
                            Data:
                                Version: 3 (0x2)
                                Serial Number:
                                    6e:ee:71:d4:91:20:32:f7:a2:98:7d:a5:89:a1:2f:14
                            Signature Algorithm: sha256WithRSAEncryption
                                Issuer: C=US, O=GeoTrust Inc., CN=GeoTrust SSL CA - G3
                                Validity
                                    Not Before: Dec 29 00:00:00 2016 GMT
                                    Not After : Dec 29 23:59:59 2018 GMT
                                Subject: C=CN, ST=Beijing, L=Beiijing, O=*** Cultural Development (Beijing) Co., Ltd., OU=DevOps, CN=*.***app.com
                                Subject Public Key Info:
                                    Public Key Algorithm: rsaEncryption
                                        Public-Key: (2048 bit)
                            ... //Arg 0的Certificate打印出来有很多数据,这里省略部分数据
checkServerTrusted - Arg 1: RSA
checkServerTrusted - Arg 2: account.***app.com
checkServerTrusted - Result: 
                            ...
                            [Certificate:
                            Data:
                                Version: 3 (0x2)
                                Serial Number:
                                    6e:ee:71:d4:91:20:32:f7:a2:98:7d:a5:89:a1:2f:14
                            Signature Algorithm: sha256WithRSAEncryption
                                Issuer: C=US, O=GeoTrust Inc., CN=GeoTrust SSL CA - G3
                                Validity
                                    Not Before: Dec 29 00:00:00 2016 GMT
                                    Not After : Dec 29 23:59:59 2018 GMT
                                Subject: C=CN, ST=Beijing, L=Beiijing, O=*** Cultural Development (Beijing) Co., Ltd., OU=DevOps, CN=*.***app.com
                                Subject Public Key Info:
                                    Public Key Algorithm: rsaEncryption
                                        Public-Key: (2048 bit)
                            ...

打开Charles,看看checkServerTrusted的参数和返回值

checkServerTrusted - Arg 0: Certificate:
                            ...
                            Signature Algorithm: sha256WithRSAEncryption
                                Issuer: CN=Charles Proxy Custom Root Certificate (built on mac.lan, 23 五月 2016), OU=http://charlesproxy.com/ssl, O=XK72 Ltd, L=Auckland, ST=Auckland, C=NZ
                                Validity
                                    Not Before: Dec 29 00:00:00 2016 GMT
                                    Not After : Dec 29 23:59:59 2018 GMT
                                Subject: C=CN, ST=Beijing, L=Beiijing, O=*** Cultural Development (Beijing) Co., Ltd., OU=DevOps, CN=*.***app.com
                                Subject Public Key Info:
                                    Public Key Algorithm: rsaEncryption
                                        Public-Key: (2048 bit)
checkServerTrusted - Arg 1: RSA
checkServerTrusted - Arg 2: account.***app.com
checkServerTrusted - Result: [Certificate:
                                ...
                                Signature Algorithm: sha256WithRSAEncryption
                                    Issuer: CN=Charles Proxy Custom Root Certificate (built on mac.lan, 23 五月 2016), OU=http://charlesproxy.com/ssl, O=XK72 Ltd, L=Auckland, ST=Auckland, C=NZ
                                    Validity
                                        Not Before: Dec 29 00:00:00 2016 GMT
                                        Not After : Dec 29 23:59:59 2018 GMT
                                    Subject: C=CN, ST=Beijing, L=Beiijing, O=*** Cultural Development (Beijing) Co., Ltd., OU=DevOps, CN=*.***app.com
                                    Subject Public Key Info:
                                        Public Key Algorithm: rsaEncryption
                                            Public-Key: (2048 bit)

那么我们要绕过他的证书校验,只需要每次都给checkServerTrusted的arg0传入真正的证书就可以了。

 

以下是frida的脚本

/*
使用说明:按以下顺序执行步骤
    1. 关闭抓包工具
    2. frida 注入脚本
    3. app中正常访问一下,会打印出真正的证书“Subject: C=CN, ST=Beijing, L=Beiijing, O=*** Cultural Development (Beijing) Co., Ltd., OU=DevOps, CN=*.***app.com”
    4. 打开抓包工具
*/

setImmediate(function() {
    console.log("[*]start bypass script...");
    Java.perform(function () {
        var X509TrustManager = Java.use("android.net.http.X509TrustManagerExtensions");
        var ArrayList = Java.use('java.util.ArrayList');
        var checkServerTrusted_arg1= null;
        console.log(checkServerTrusted_arg1);

        X509TrustManager.checkServerTrusted.implementation = function(arg1, arg2, arg3) {
            if (checkServerTrusted_arg1 != null) {
                arg1 = checkServerTrusted_arg1;
            }
            var result = this.checkServerTrusted(arg1, arg2, arg3);
            var items = ArrayList.$new(result);
            console.log("X509TrustManager.checkServerTrusted:", arg1, arg2, arg3, "\r\n\r\n", items);
            checkServerTrusted_arg1 = arg1;
            return result;
        };
    });
});

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2018-11-25 00:10 被Imyang编辑 ,原因:
收藏
免费 5
支持
分享
打赏 + 1.00雪花
打赏次数 1 雪花 + 1.00
 
赞赏  junkboy   +1.00 2018/11/25
最新回复 (6)
雪    币: 11716
活跃值: (133)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
支持一下
2018-11-25 00:10
0
雪    币: 3907
活跃值: (5817)
能力值: ( LV12,RANK:200 )
在线值:
发帖
回帖
粉丝
3
已经被人发了无数遍了。。。
2018-11-25 16:32
0
雪    币: 14471
活跃值: (5723)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
https协议,目前大部分APP不是直接使用代理进行get或post,而是使用connect命令后让代理变成转发包的工具,替换证书根本行不通。
最后于 2018-11-28 08:54 被tDasm编辑 ,原因:
2018-11-27 11:07
0
雪    币: 36
活跃值: (74)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
TargetSdkVersion为22的包,大多数都可以信任Fiddler/Charles证书后直接看到HTTPS请求和返回
2018-11-27 16:23
0
雪    币: 222
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
6
Imyang表哥,因无发短信权限在此贴向你提问,你在另一个贴“关于某款特殊的Android APP抓包问题”https://bbs.pediy.com/thread-248038.htm的回复是“开个vpn,转发到代理工具上”,我也下载这个软件,但是我也无法抓包,请问你是如何抓包的,能否解答下,谢谢。
2019-1-21 14:42
0
雪    币:
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
7
有大佬知道,这个代码,第一次运行正常,第二次运行时报错argument types do not match any of xxx:
{'type': 'error', 'description': "Error: checkServerTrusted(): argument types do not match any of:\n\t.overload('[Ljava.security.cert.X509Certificate;', 'java.lang.String', 'java.lang.String')", 'stack': "Error: checkServerTrusted(): argument types do not match any of:\n\t.overload('[Ljava.security.cert.X509Certificate;', 'java.lang.String', 'java.lang.String')\n    at X (frida/node_modules/frida-java-bridge/lib/class-factory.js:569)\n    at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:973)\n    at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:553)\n    at <anonymous> (/script1.js:77)\n    at apply (native)\n    at ne (frida/node_modules/frida-java-bridge/lib/class-factory.js:620)\n    at <anonymous> (frida/node_modules/frida-java-bridge/lib/class-factory.js:598)", 'fileName': 'frida/node_modules/frida-java-bridge/lib/class-factory.js', 'lineNumber': 569, 'columnNumber': 1}

感觉是第二次运行时第一个参数(就是之前保存的参数)给的不对?
2022-10-9 06:00
0
游客
登录 | 注册 方可回帖
返回
//