[Tips] PIE 보호 기법이 걸려 경우 gdb 디버깅 - gef
[*]
PIE가 걸려 있는 경우 디버깅을 할 수 있는 방법은 다양하지만 특히 gef를 사용하면 pie가 걸려 있을 때 편한 디버깅을 지원해주는 pie 명령어를 지원해주기 때문에 훠어어얼씬 편하게 디버깅을 할 수 있다. (맨날 pwndbg로 pie 디버깅하다가 gef로 쓰니까 신세계가 따로 없었따...)
[*] gef 설치
$ wget -O ~/.gdbinit-gef.py -q https://gef.blah.cat/py
$ echo source ~/.gdbinit-gef.py >> ~/.gdbinit
- 참고(공식 깃헙) : https://github.com/hugsy/gef
GitHub - hugsy/gef: GEF (GDB Enhanced Features) - a modern experience for GDB with advanced debugging capabilities for exploit d
GEF (GDB Enhanced Features) - a modern experience for GDB with advanced debugging capabilities for exploit devs & reverse engineers on Linux - GitHub - hugsy/gef: GEF (GDB Enhanced Features) - ...
github.com
위 명령어 두줄만 입력하면 간단하게 gef를 설치 할 수 있다.
[*] PIE 디버깅 사용법
gef➤ pie
[!] Syntax
pie (breakpoint|info|delete|run|attach|remote)
- 기본적으로 pie 뒤에 키워드를 붙이면 된다. 주의할 점은 그냥 run과 pie run은 아얘 다른 방식으로 작동하니 주의하자
- pie breakpoint(or b) <offset> : pie offset 값으로 breakpoint를 추가한다.
- pie info : 추가한 pie breakpoint 리스트를 보여준다.
gef➤ pie info
VNum Num Addr
1 6 0x1244
2 7 0x130a
3 8 0x1344
4 9 0x134b
5 10 0x1376
- pie delete : pie breakpoint를 제거한다
- pie run : pie breakpoint를 기준으로 바이너리를 실행한다. 그냥 run과는 다르므로 주의하자.
그냥 run은 pie breakpoint에 있는 값들을 무시하고 실행됨
- pie attach <pid> : pie breakpoint를 기준으로 실행 중인 바이너리에 attach한다.
- pie remote :
평소엔 pie 걸린 경우에 attach해서 동적 디버깅하기 너무 귀찮았는데 이걸 쓰면 그 문제점이 바로 해결된다. 굿