frida捕获加密调用

2020-08-21  本文已影响0人  静析机言

本篇文章演示如何用Frida拦截Cipher.init()调用监控加密调用并捕获有关使用的加密类型和密钥的详细信息。

function main() {

if (Java.available) {

Java.perform(function(){

const Cipher = Java.use('javax.crypto.Cipher');

Cipher.init.overload('int', 'java.security.Key', 'java.security.spec.AlgorithmParameterSpec').implementation = function (opmode, key, iv){

if (iv.$className == 'javax.crypto.spec.IvParameterSpec'){

var opmodestring = this.getOpmodeString(opmode);

var algo = this.getAlgorithm();

const keyclass = Java.use('javax.crypto.spec.SecretKeySpec');

const ivclass = Java.use('javax.crypto.spec.IvParameterSpec');

var keystoreKey = Java.cast(key, keyclass);

var ivInstance = Java.cast(iv,ivclass);

var result=this.init(opmode,key,iv);

console.log('[] opmode:'+opmodestring);

console.log('[] algorithm:'+algo);

console.log('[] key className:'+key.$className);

console.log('[] key value:'+ JSON.stringify(keystoreKey.getEncoded());

console.log('[] iv value:'+JSON.stringify(ivInstance.getIV());

}

return result;

}

})

}

}

setImmediate(main)

其中,this.getAlgorithm()确定使用哪种加密算法;key.$className,iv.$ className将为我们提供对象的类名; keystoreKey.getEncoded()获取密钥的内容;ivInstance.getIV()获取IV值。

使用如下以下命令运行脚本,传递包名和我们创建的cipher.js脚本

frida -U -f 包名 -l cipher.js --no-pause

上一篇 下一篇

猜你喜欢

热点阅读