how to use patchelf
C
root@4279ae4a965e:/home/ow_rtld# ldd ow_rtld
linux-vdso.so.1 (0x00007ffc61968000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000076b1d69a9000)
/lib64/ld-linux-x86-64.so.2 (0x000076b1d6f9c000)
root@4279ae4a965e:/home/ow_rtld# cp ld-2.27.so /lib64/ld-linux-x86-64.so.2
Bus error (core dumped)
root@4279ae4a965e:/home/ow_rtld# ls
-bash: /bin/ls: Input/output error
root@4279ae4a965e:/home/ow_rtld# ls
-bash: /bin/ls: Input/output error
root@4279ae4a965e:/home/ow_rtld# ls
-bash: /bin/ls: Input/output error
root@4279ae4a965e:/home/ow_rtld# file /lib64/ld-linux-x86-64.so.2
-bash: /usr/bin/file: Input/output error
root@4279ae4a965e:/home/ow_rtld# ls
-bash: /bin/ls: Input/output error
root@4279ae4a965e:/home/ow_rtld# 임의로 로더 자체를 바꿀려고 했는데 바로… 벽돌이 되어 벼렸다.
그래서 이참에 알아보는 Patchelf를 써보자
C
# 인터프리터(로더) 설정: ld.so를 현재 디렉토리로
patchelf --set-interpreter ./ld-2.27.so ./ow_rtld
# 라이브러리 검색 경로(RPATH) 설정: 현재 디렉토리에서 libc 찾게
patchelf --set-rpath . ./ow_rtldpatchelf --set-rpath . ./ow_rtld 참고로 이건 잘 안되어서 그냥 LD_PRELOAD 로 특정라이브러리를 올린다