From 496a24210a349fff61c2d0e644a365396a7f1f1e Mon Sep 17 00:00:00 2001 From: luzhisheng Date: Sun, 4 Feb 2024 09:29:43 +0800 Subject: [PATCH] =?UTF-8?q?aes=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../新-sec2-lesson8-响应数据有加密/__init__.py | 0 .../lesson8-test_aes.py | 41 ++ .../lesson8-test_hook_aes.py | 584 ++++++++++++++++++ 3 files changed, 625 insertions(+) create mode 100644 猿人学app逆向/新-sec2-lesson8-响应数据有加密/__init__.py create mode 100644 猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_aes.py create mode 100644 猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_hook_aes.py diff --git a/猿人学app逆向/新-sec2-lesson8-响应数据有加密/__init__.py b/猿人学app逆向/新-sec2-lesson8-响应数据有加密/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_aes.py b/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_aes.py new file mode 100644 index 0000000..91bcf58 --- /dev/null +++ b/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_aes.py @@ -0,0 +1,41 @@ +from Crypto.Cipher import AES +import base64 +import json + +# 如果text不足16位的倍数就用空格补足为16位 +def add_to_16(text): + if len(text.encode('utf-8')) % 16: + add = 16 - (len(text.encode('utf-8')) % 16) + else: + add = 0 + text = text + ('\0' * add) + return text.encode('utf-8') + + + # 加密 +def encrypt(text): + key = '9999999999999999'.encode('utf-8') + mode = AES.MODE_CBC + iv = b'qqqqqqqqqqqqqqqq' + text = add_to_16(text) + cryptos = AES.new(key, mode, iv) + cipher_text = cryptos.encrypt(text) + return base64.b64encode(cipher_text) + + + # 解密后,去掉补足的空格用strip() 去掉 +def decrypt(): + + key = 'u9J7A4LkUTQSdak='.encode('utf8') + print(key) + text = base64.b64decode('QJrIAL7j4+5jAmY3y1J/ebTwcqBVFBTad5mDggFkMXfu33sn5TEaMKD6FRJE9MYVmm3x9oBa9DY5OlqjYnopK5KkQEpGZFvyr9dw1GCXLdA=') + iv = b"6di50aH901duea7d" + mode = AES.MODE_CBC + cryptos = AES.new(key, mode, iv) + + plain_text = cryptos.decrypt(text) + #print(plain_text) + print(plain_text.decode('unicode_escape')) + +decrypt() + \ No newline at end of file diff --git a/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_hook_aes.py b/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_hook_aes.py new file mode 100644 index 0000000..a705a37 --- /dev/null +++ b/猿人学app逆向/新-sec2-lesson8-响应数据有加密/lesson8-test_hook_aes.py @@ -0,0 +1,584 @@ +import frida, sys + +test_hook = """ +Java.perform(function(){ + + var MAppliction = Java.use('com.xbiao.MAppliction') + console.log(MAppliction.getInstance().getResources().getString(2131820921)) + + + console.log('ddddddddddddddddd') + Java.enumerateClassLoaders({ + onMatch: function(loader){ + Java.classFactory.loader = loader; + var TestClass; + try{ + TestClass = Java.use("com.xbiao.utils.AESedeUtil"); + TestClass.decrypt.implementation = function(p1,p2){ + console.log('decrypt p1:'+p1) + console.log('decrypt p2:'+p2) + return this.decrypt(p1,p2) + } + }catch(error){ + if(error.message.includes("ClassNotFoundException")){ + console.log(" You are trying to load encrypted class, trying next loader"); + } + else{ + console.log(error.message); + } + } + }, + onComplete: function(){ + + } + }) +}) + + +""" + +hook_class =""" +Java.perform(function(){ + hookclass('com.xbiao.login.PhoneLoginActivity') +}) + +function printstack() { + console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new())) +} + +function hookclass(className){ + var Myclasa = Java.use(className) + //得到类下的所有方法 + var methods = Myclasa.class.getDeclaredMethods() + //遍历所有方法 + methods.forEach(function(method){ + //获得方法名 + var methodName = method.getName() + //获得该方法得所有重载 + var overloads = Myclasa[methodName].overloads + //遍历重载 + overloads.forEach(function(overload){ + //hook 重载 + + var prot = '(' + for (var i=0; i