攻防世界app2 frida獲取金鑰
阿新 • • 發佈:2020-08-12
環境準備
安裝mumu模擬器
pip安裝frida,這裡到最後一步setup需要很長時間。
在frida github下載對應服務端。
apk下載:https://adworld.xctf.org.cn/media/task/attachments/2554cf208cfb4cdf9218a840fa9bf237.apk
分析程式碼
使用jadx開啟app,並來到MainActivity。
在click事件的處理當中,startActivity一個新的SecondActivity,進入它的onCreate
這裡使用了Encryto.doRawData對資料進行處理,對這個函式進行檢視,發現是從so檔案中匯入的函式。使用ida分析這個so檔案。
開啟後來到doRawData這個函式的位置,發現是使用了AES_128_ECB_PKCS5Padding_Encrypt進行加密。這裡需要一個16位的金鑰。使用frida,hook住該函式,取出對應的值就可以了
獲取金鑰
使用adb連線mumu。adb路徑在:\MuMu\emulator\nemu\vmonitor\bin
當前無連線裝置
連線裝置
將之前下載的檔案傳到mumu裡,並修改許可權位777 。這裡需要傳入32位的檔案。
直接執行,無報錯即可
編寫python指令碼
import sys import threading import frida PACKAGE= 'com.tencent.testvuln' def get_device(): mgr = frida.get_device_manager() changed = threading.Event() def on_changed(): changed.set() mgr.on('changed', on_changed) device = None while device is None: devices = [dev for dev in mgr.enumerate_devices() if dev.type == 'usb'] if len(devices) == 0: print('Waiting for usb device...') changed.wait() else: device = devices[0] mgr.off('changed', on_changed) return device if __name__ == '__main__': jscode = """ Java.perform(function () { var nativePointer = Module.findExportByName("libJNIEncrypt.so", "AES_128_ECB_PKCS5Padding_Encrypt"); send("native: " + nativePointer); Interceptor.attach(nativePointer, { onEnter: function(args){ send(args); console.log("args[0]",Memory.readByteArray(args[0],20)) console.log("args[1]",Memory.readByteArray(args[1],20)) }, onLeave: function(retval){ send(retval); console.log("output",Memory.readByteArray(retval,30)) } }); }); """ def message(message, data): if message["type"] == 'send': print("[*] {0}".format(message['payload'])) else: print(message) device = get_device() print(device) process = device.attach(PACKAGE) print(process) script = process.create_script(jscode) script.on("message", message) script.load() sys.stdin.read()
執行結果
找到了輸入的值,金鑰,和輸出的值