Mobile/Frida
Anti-Debugging 우회 ( ptrace 선점 )
pyozzi
2020. 2. 29. 03:23
안티디버깅이 적용되어 있는 어플을 IDA나 GDB로 Attach하려고 하면 앱이 바로 종료되어 버린다.
또한, ptrace를 미리 선점하는 방식으로 안티디버깅이 적용된 경우도 있다.
이런 방식의 안티디버깅을 우회할 수 있는 방법 중 dlopen( )으로 우리가 원하는 라이브러리가 로드됐을 때,
바로 sleep을 걸어서 안티디버깅이 동작하기 전에 디버거를 Attach 해주는 방법이 있다.
Interceptor.attach(Module.findExportByName(null, "dlopen"),
{
onEnter: function(args)
{
this.libc_name = Memory.readUtf8String(args[0]);
if (this.libc_name.indexOf("libfoo.so") !== -1)
{
Thread.sleep(5); // Interval 조절
}
},
onLeave: function(retVal)
{
return 0;
}
});
Attach가 완료되면 Linker에 Call Function Symbol에 브레이크 포인트를 설정하고 init ~ init_array부터 분석하면 된다.
보통 init_array 부분에 언패킹 하는 로직과 함께 안티디버깅이 동작하는 로직이 포함되어 있다.
기술 출처: http://linforum.kr/bbs/board.php?bo_table=qa&wr_id=410