gdb
2024년 6월 6일
pwndbg #
설치 #
git clone https://github.com/pwndbg/pwndbg
cd pwndbg
./setup.sh
사용법 #
1$ gdb <target>
2$ LD_PRELOAD=./libc-2.27.so gdb ./tcache_poison # LD_PRELOAD로 라이브러리 세팅
-
catch : 이벤트가 발생할 때 breakpoint 처럼 프로세스를 정지시킨다.
ex) fs 레지스터는info reg fs나print $fs로 확인할 수 없기 때문에 syscall을 확인한다.1$ gdb -q ./canary 2# arch_prctl(ARCH_SET_FS, addr) 에서 addr을 확인 3pwndbg> catch syscall arch_prctl 4Catchpoint 1 (syscall 'arch_prctl' [158]) -
entry : Entry Point 위치에서 정지하며, 전체 상황을 보여준다. 실행 중간에 명령어를 입력하면 다시 EP로 이동한다.
-
context : 현재 전체 상황을 표시해주는 명령.
-
finish : 함수를 나갈때 사용한다. step out
-
pdisasemble (pd) : 줄여서 pd로 사용하며, pwndbg의 disassemble 명령이다. 조금 더 편하게 표시됨
-
x : 특정 주소에서 원하는 길이만큼 원하는 형식으로 인코딩해서 출력해주는 명령어
- Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal), t(binary), f(float), a(address), i(instruction), c(char), s(string) and z(hex, zero padded on the left). Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
-
telescope (tele) : 메모리 덤프 기능. 방향으로 이 주소에 어떤 포인터값, 상수값이 들어있는지 볼 수 있다.
-
vmmap : 가상주소에 매핑된 메모리맵을 볼 수 있다.
-
python code
- argv : 디버기의 인자로 python 입력
r $(python3 -c "print('\xff' * 100)") - input : 유저 입력으로 전달할때
<<<를 사용한다.
r $(python3 -c "print('\xff' * 100)") <<< $(python3 -c "print('dongkim')") - input file: 위의 방법에서는 null 값을 못넣는데, 파일에 작성 후
r < file_path로 전달하면 null 값도 입력할 수 있다.
- argv : 디버기의 인자로 python 입력
-
search : 문자열을 검색하는 명령어.
-
heap : 힙 메모리의 청크를 확인하는 명령어.
-
set : 특정 메모리를 변수화 시켜서 구조체로 인식하게 하거나 이름을 붙인다.
-
print : 특정 메모리 주소를 출력하는데, 형변환과 함께 사용하면 구조체 형태로 출력할 수 있다.
자주 사용하는 명령 #
break 포인트 제거 #
1pwndbg> info break
2Num Type Disp Enb Address What
32 breakpoint keep y 0x00000000004006e8 <main>
43 breakpoint keep y 0x0000000000400723 <main+59>
5pwndbg> delete 2
6pwndbg> i b
7Num Type Disp Enb Address What
83 breakpoint keep y 0x0000000000400723 <main+59>
브레이크 포인트에 도달할 때마다 명령어 실행 #
1pwndbg> b *0x142745 if shadow_buffer_.config_.horizontal_resolution == 260
2pwndbg> c
3
4pwndbg> commands
5Type commands for breakpoint(s) 2, one per line.
6End with a line saying just "end".
7>printf "intersection = (%d, %d) (%d, %d)\n", intersection.pos.x, intersection.pos.y, intersection.size.x, intersection.size.y
8>printf "this = (%d, %d) (%d, %d)\n", pos.x, pos.y, Size().x, Size().y
9>printf "area = (%d, %d) (%d, %d)\n", area.pos.x, area.pos.y, area.size.x, area.size.y
10>pi gdb.execute("continue")
11>end
12pwndbg> set gdb-workaround-stop-event 2
ni/si vs n/s #
ni/si 는 어셈블리 한줄을 실행시키는 명령어이다.
n/s 는 디버깅을 위한 소스코드가 제공되는 경우 소스코드 기준으로 한줄을 실행시킨다.