frida常见算法hook
2021/10/25 20:41:16
本文主要是介绍frida常见算法hook,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
function showStacks() { Java.perform(function () { send(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new())); }); } function bytesToHex(arr) { var str = ""; for(var i=0; i<arr.length; i++) { var tmp = arr[i]; if (tmp < 0) { tmp =(255+tmp+1).toString(16); } else { tmp = tmp.toString(16); } if(tmp.length == 1) { tmp = "0" + tmp; } str += tmp; } return str; } function bytesToBase64(arr) { var str = ""; for(var i=0; i<arr.length; i++) { var tmp = arr[i]; if (tmp < 0) { tmp =(255+tmp+1).toString(16); } else { tmp = tmp.toString(16); } if(tmp.length == 1) { tmp = "0" + tmp; } str += tmp; } return str; } function bytesToString(arr) { var str = ""; for(var i=0; i<arr.length; i++) { var tmp = arr[i]; if (tmp < 0) { tmp =(255+tmp+1).toString(16); } else { tmp = tmp.toString(16); } if(tmp.length == 1) { tmp = "0" + tmp; } str += tmp; } return str; } Java.perform(function () { var secretKeySpec = Java.use('javax.crypto.spec.SecretKeySpec'); secretKeySpec.$init.overload('[B','java.lang.String').implementation = function (a,b) { showStacks(); var result = this.$init(a, b); send("======================================"); send("算法名:" + b + "|Dec密钥:" + bytesToString(a)); send("算法名:" + b + "|Hex密钥:" + bytesToHex(a)); return result; } var mac = Java.use('javax.crypto.Mac'); mac.getInstance.overload('java.lang.String').implementation = function (a) { showStacks(); var result = this.getInstance(a); send("======================================"); send("算法名:" + a); return result; } mac.update.overload('[B').implementation = function (a) { showStacks(); this.update(a); send("======================================"); send("update:" + bytesToString(a)) } mac.update.overload('[B','int','int').implementation = function (a,b,c) { showStacks(); this.update(a,b,c) send("======================================"); send("update:" + bytesToString(a) + "|" + b + "|" + c); } mac.doFinal.overload().implementation = function () { showStacks(); var result = this.doFinal(); send("======================================"); send("doFinal结果:" + bytesToHex(result)); send("doFinal结果:" + bytesToBase64(result)); return result; } mac.doFinal.overload('[B').implementation = function (a) { showStacks(); var result = this.doFinal(a); send("======================================"); send("doFinal参数:" + bytesToString(a)); send("doFinal结果:" + bytesToHex(result)); send("doFinal结果:" + bytesToBase64(result)); return result; } var md = Java.use('java.security.MessageDigest'); md.getInstance.overload('java.lang.String','java.lang.String').implementation = function (a,b) { showStacks(); send("======================================"); send("算法名:" + a); return this.getInstance(a, b); } md.getInstance.overload('java.lang.String').implementation = function (a) { showStacks(); send("======================================"); send("算法名:" + a); return this.getInstance(a); } md.update.overload('[B').implementation = function (a) { showStacks(); send("======================================"); send("update:" + bytesToString(a)) return this.update(a); } md.update.overload('[B','int','int').implementation = function (a,b,c) { showStacks(); send("======================================"); send("update:" + bytesToString(a) + "|" + b + "|" + c); return this.update(a,b,c); } md.digest.overload().implementation = function () { showStacks(); send("======================================"); var result = this.digest(); send("digest结果:" + bytesToHex(result)); send("digest结果:" + bytesToBase64(result)); return result; } md.digest.overload('[B').implementation = function (a) { showStacks(); send("======================================"); send("digest参数:" + bytesToString(a)); var result = this.digest(a); send("digest结果:" + bytesToHex(result)); send("digest结果:" + bytesToBase64(result)); return result; } var ivParameterSpec = Java.use('javax.crypto.spec.IvParameterSpec'); ivParameterSpec.$init.overload('[B').implementation = function (a) { showStacks(); var result = this.$init(a); send("======================================"); send("iv向量:" + bytesToString(a)); send("iv向量:" + bytesToHex(a)); return result; } var cipher = Java.use('javax.crypto.Cipher'); cipher.getInstance.overload('java.lang.String').implementation = function (a) { showStacks(); var result = this.getInstance(a); send("======================================"); send("模式填充:" + a); return result; } cipher.update.overload('[B').implementation = function (a) { showStacks(); var result = this.update(a); send("======================================"); send("update:" + bytesToString(a)); return result; } cipher.update.overload('[B','int','int').implementation = function (a,b,c) { showStacks(); var result = this.update(a,b,c); send("======================================"); send("update:" + bytesToString(a) + "|" + b + "|" + c); return result; } cipher.doFinal.overload().implementation = function () { showStacks(); var result = this.doFinal(); send("======================================"); send("doFinal结果:" + bytesToHex(result)); send("doFinal结果:" + bytesToBase64(result)); return result; } cipher.doFinal.overload('[B').implementation = function (a) { showStacks(); var result = this.doFinal(a); send("======================================"); send("doFinal参数:" + bytesToString(a)); send("doFinal结果:" + bytesToHex(result)); send("doFinal结果:" + bytesToBase64(result)); return result; } var x509EncodedKeySpec = Java.use('java.security.spec.X509EncodedKeySpec'); x509EncodedKeySpec.$init.overload('[B').implementation = function (a) { showStacks(); var result = this.$init(a); send("======================================"); send("RSA密钥:" + bytesToBase64(a)); return result; } var rSAPublicKeySpec = Java.use('java.security.spec.RSAPublicKeySpec'); rSAPublicKeySpec.$init.overload('java.math.BigInteger','java.math.BigInteger').implementation = function (a,b) { showStacks(); var result = this.$init(a,b); send("======================================"); //send("RSA密钥:" + bytesToBase64(a)); send("RSA密钥N:" + a.toString(16)); send("RSA密钥E:" + b.toString(16)); return result; } });
这篇关于frida常见算法hook的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?
- 2024-12-23汽车4S店运营效率提升的核心工具