-
Android Frida Script by ChatGPT#1 - Security/Android 2022. 12. 16. 11:19
ChatGPT 이용하여 libc.so 의 open함수 Frida Hooking code 요청을 해봤다.
전체 소스코드는 이렇다
// First, import the Frida API and the `Process` module var frida = require('frida'); var Process = frida.Process; // Next, find the PID of the process you want to attach to // In this example, we'll attach to the process with PID 1234 var pid = 1234; // Attach to the process Process.attach(pid).then(function (process) { // Enumerate the imports of the process to find the `open` function var imports = process.enumerateImportsSync("libc.so"); var openFunction = null; imports.forEach(function (imp) { if (imp.name === "open") { openFunction = imp.address; } }); // If the `open` function was found, create a trampoline to hook it if (openFunction !== null) { // Define the hook function var hook = function () { console.log("open function called with arguments:", JSON.stringify(arguments)); return 0; // Return a value to avoid the application crashing }; // Create the trampoline var trampoline = Memory.alloc(Process.pageSize); var hookCode = new NativeFunction(hook, 'int', ['pointer', 'int']); hookCode.copy(trampoline, { size: Process.pageSize }); // Enable the hook Interceptor.attach(openFunction, { onEnter: function (args) { // args[0] is the first argument of the `open` function (the file name) console.log("Opening file: " + Memory.readUtf8String(args[0])); args[0] = trampoline.add(Process.pageSize); }, onLeave: function (retval) { // retval is the return value of the `open` function console.log("File opened with descriptor: " + retval); } }); } });
신기하기도 하고.. 앞으로 많은 활용이 가능할거로 보인다
위의 코드는 전체 다 사용할 필욘 없어보이고 적당히 커스텀해서 쓰면 될 거 같다.
추후엔 string obfuscation, control flow graph 등 여러가지 deobfuscation 영역까지도
활성화되면 분석하기 참 편할거 같다
나중가면 사실 기계가 다 분석할듯..
'#1 - Security > Android' 카테고리의 다른 글
안드로이드 인증서 경로 (0) 2021.04.05 Shared Object(.so) 로드 순서 (0) 2020.08.10 system 디렉터리 remount 안될 때 (0) 2020.01.10 안드로이드 apk 추출(adb) (0) 2019.09.30