how to watch source code in pwngdb

gdb로 디버깅 하다보면 glibc 상에서 정확한 코드를 보고 싶을때가 있다. 이때 하는 법을 알려주겠다.

디버깅 심볼을 얻을때와 일맥상통하다

여기서 해당 버전을 찾은뒤

상당에 있는 glibc-source의 링크를 복사한뒤

wget로 받아오면 된다.

그럼 아카이브로 오기에 ar x 명령어로 아카이브를 풀어주고

data.tar.xz 파일만 압축 해제 하면된다. 그럼 usr 폴더가 생기는데

C
root@500a25569bbf:/home/bypass_valid_vtable/usr/src/glibc# ls
debian  glibc-2.27  glibc-2.27.tar.xz

안에서도 glibc tar을 풀어줘야 한다. 이제

C
pwndbg> info source
Current source file is genops.c
Compilation directory is /build/glibc-OTsEL5/glibc-2.27/libio
Located in /build/glibc-OTsEL5/glibc-2.27/libio/genops.c
Source language is c.
Producer is GNU C11 7.3.0 -mtune=generic -march=x86-64 -g -O2 -O3 -std=gnu11 -fgnu89-inline -fmerge-all-constant
s -frounding-math -fstack-protector-strong -fPIC -fexceptions -ftls-model=initial-exec -fstack-protector-strong.
Compiled with DWARF 2 debugging format.
Does not include preprocessor macro info.

pwndbg 에서 info source 명령어로 확인해보면

안뜨면 → info sources

C
/build/glibc-OTsEL5/glibc-2.27/libio

이런식으로 지금 사용하고 있는 source 디렉토리 위치가 나오는데 libio는 내부니깐 상관이 없고 그 앞에

C
/build/glibc-OTsEL5/glibc-2.27/

경로를 이제 우리가 바꿔주면 된다.

C
set substitute-path /build/glibc-OTsEL5/glibc-2.27 /home/bypass_valid_vtable/usr/src/glibc/glibc-2.27

다음과 같이 하면 된다.

gdbinit에 설정을 하는게 편하기에

C
echo "set substitute-path /build/glibc-OTsEL5/glibc-2.27 /home/bypass_valid_vtable/usr/src/glibc/glibc-2.27" >> ~/.gdbinit

다음과 같이 하면 된다.

홈 이름 바꿔서 붙여넣기 용

C
echo "set substitute-path /build/glibc-2ORdQG/glibc-2.27/ ./usr/src/glibc/glibc-2.27" >> ~/.gdbinit

추가적으로 분석했다