Android证书绑定绕过研究(三)

背景

第三篇以获取客户端证书并修改客户端证书为切入点,探索该方式绕过SSL pinning的可能性

客户端证书获取

  • Burp导出证书,然后转换
  • 证书格式转换
    • PEM到DER
      openssl x509 -in cert.crt -outform der-out cert.der
    • DER到PEM
      openssl x509 -in cert.crt -inform der -outform pem -out cert.pem

绕过校验

import frida, sys, re
import codecs, time

'''
Running example:
python ./frida_spawn.py ./ca.crt 
'''

APP_NAME = "com.xxx.android"

if(len(sys.argv)) < 2:
    print("Usage: ./frida_spawn.py [plain text certificate in PEM format]")
    quit()


def on_message(message, data):
    if message['type'] == 'error':
        print(message['stack'])


with codecs.open("./xxx_unpinning.js", 'r', encoding='utf8') as f:
    jscode  = f.read()
    device  = frida.get_usb_device(timeout=5)
    pid     = device.spawn([APP_NAME])
    session = device.attach(pid)
    print ("pid: {}".format(pid))
    script  = session.create_script(jscode)  
    print ("[*] Intercepting ...")
    script.on('message', on_message)
    script.load()

    with open(sys.argv[1]) as file:
        script.post({'type': 'input', 'payload': file.read()})

    script.exports.mybypass()
    
    device.resume(APP_NAME)
    sys.stdin.read()

function bypass() {

//Java.perform(function () {

    console.log('[*] Script started');
    
    const certificateArray = Java.use('[Ljava.lang.String;');
    const JavaString = Java.use('java.lang.String');
    var myCertificate = null;

    recv('input', function(value) {
        myCertificate = JavaString.$new(value.payload);
    });
    
    var HookedClass = Java.use('java.security.cert.CertificateFactory');
    const InputStream = Java.use('java.io.ByteArrayInputStream');
    var inStreamCertificate = InputStream.$new(myCertificate.getBytes());

    var done = false;

    HookedClass.generateCertificate.implementation = function (inStream) {
        
        if(!done) { // we will change only the first certificate to ours
            console.log("[*] Successfully changed the certificate");
            //done = true;
            return this.generateCertificate(inStreamCertificate);
        }
        return this.generateCertificate(inStream);
    }; 
//});

}

rpc.exports = {
    mybypass : bypass,
}

底层逻辑

通过底层PEM_read_bio_X509证书时,直接替换证书,感觉是比较通用的做法

参考

APP双向认证抓包_IOS

iOS应用程序绕过OpenSSL的证书

Github-SSLBypass

Github-Bypass-Snapchat-SSL-Certificate-Pinning

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值