IOS
[iOS] / frida script 코드 예시
삼전동해커
2024. 12. 19. 22:36
import frida
import sys
def on_message(message, data):
if message['type'] == 'send': #정상적으로 전송되었다면 payload 출력
print("[+] {0}".format(message['payload']))
elif message['type'] == 'error':
print("[!] {0}".format(message['stack']))
def main(target):
session = frida.attach(target) #타켓 프로세스 attach
script_code = """ #javascript가 python에서 동작할 수 있도록 함
var _bind = Module.findExportByName(null, "_bind"); #findExportByName: 찾고자 하는 모듈(라이브러리 이름)과 심볼(함수 이름)의 이름을 대상으로 검색, 모듈은 None이고 _bind 심볼을 검색하고 주소를 반환
if (_bind) {
send("_bind found at: " + _bind);
Interceptor.attach(_bind, { #찾은 메모리 주소를 가지고
onEnter: function (args) { #onEnter: 함수가 호출될 때마다 실행할 함수
send("_bind called with arguments: " + args[0].toInt32() + ", " + args[1].toInt32()); #찾은 함수에 전달된 매개변수를 호출
},
onLeave: function (retval) { #onLeave: 함수가 반환될 때 실행할 함수
send("_bind returned: " + retval.toInt32()); #반환한 값을 출력
}
});
} else {
send("_bind not found in the target process.");
}
"""
script = session.create_script(script_code) #스크립트 코드를 세션에 전달
script.on('message', on_message) #on_message 함수의 결과를 가져옴, send되었는지 에러가 발생했는지 확인
script.load() #작성한 스크립트 함수를 프로세스에 로드하여 후킹 활성화
sys.stdin.read() #스크립트가 지속적으로 동작하도록 유지
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python hook_bind.py <target_process>")
sys.exit(1)
target_process = sys.argv[1]
main(target_process)