patchelf 0.6 및 0.8을 사용하여 ld-linux-x86-64.so.2에서 RUNPATH를 설정한 후 bash를 chroot할 수 없습니다.

patchelf 0.6 및 0.8을 사용하여 ld-linux-x86-64.so.2에서 RUNPATH를 설정한 후 bash를 chroot할 수 없습니다.

RUNPATH동적 연결이 변수와 어떻게 작동하는지 테스트 하고 bash최소한의 chroot디렉터리에서 실행하려고 합니다.

$ find dir_chroot/ -type f
dir_chroot/bin/bash
dir_chroot/lib/x86_64-linux-gnu/libc.so.6
dir_chroot/lib/x86_64-linux-gnu/libdl.so.2
dir_chroot/lib/x86_64-linux-gnu/libtinfo.so.5
dir_chroot/lib64/ld-linux-x86-64.so.2

-- 이는 종속성 이며 심볼릭 링크가 아닌 bash실제 바이너리( )입니다 . find -type f그들도 마찬가지입니다 RUNPATH:

$ find dir_chroot/ -type f -exec sh -c "readelf -d {} | grep RUNPATH" \;
$ 

chroot이 디렉토리에서는 잘 작동합니다:

$ sudo chroot dir_chroot /bin/bash
bash-4.3# exit
exit

그러나 모든 것을 복사하고 에 설정하면 RUNPATH다음 을 $ORIGIN/실행할 때 종료 코드 (?) lib64/ld-linux-x86-64.so.2가 표시됩니다 .139segfaultchroot

$ cp -R dir_chroot dir_chroot4
$ find dir_chroot4/ -type f -exec sh -c "echo {} `readelf -d {} | grep RUNPATH`" \; 
dir_chroot4/bin/bash
dir_chroot4/lib/x86_64-linux-gnu/libc.so.6
dir_chroot4/lib/x86_64-linux-gnu/libdl.so.2
dir_chroot4/lib/x86_64-linux-gnu/libtinfo.so.5
dir_chroot4/lib64/ld-linux-x86-64.so.2
$
$ patchelf --set-rpath "\$ORIGIN/" dir_chroot4/lib64/ld-linux-x86-64.so.2
$ find dir_chroot4/ -type f -exec sh -c "echo {} `readelf -d {} | grep RUNPATH`" \; 
dir_chroot4/bin/bash
dir_chroot4/lib/x86_64-linux-gnu/libc.so.6
dir_chroot4/lib/x86_64-linux-gnu/libdl.so.2
dir_chroot4/lib/x86_64-linux-gnu/libtinfo.so.5
dir_chroot4/lib64/ld-linux-x86-64.so.2 0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/]
$
$ sudo chroot dir_chroot4 /bin/bash
$
$ echo $status
139

-- $status셸의 상태 변수입니다.fish

ld-linux-x86-64.so.2패치된 경우에만 다른 라이브러리와 bash실행 파일이 함께 작동할 수 있습니다 RUNPATH. 이유는 무엇입니까?

답변1

확실히,ld-linux-x86-64.so.2적어도 내 시스템에서는 정적으로 연결되어 있습니다.

>ldd ld-linux-x86-64.so.2
statically linked

같지 않은libc.so.6,libdl.so.2그리고libtinfo.so.5

>ldd libc.so.6 libdl.so.2 libtinfo.so.5

libc.so.6:
/lib64/ld-linux-x86-64.so.2 (0x000056469847a000)
linux-vdso.so.1 =>  (0x00007ffe95185000)

libdl.so.2:
linux-vdso.so.1 =>  (0x00007fffc4718000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa1df136000)
/lib64/ld-linux-x86-64.so.2 (0x0000558334a9c000)

libtinfo.so.5:
linux-vdso.so.1 =>  (0x00007ffe1b7bd000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffa990b9000)
/lib64/ld-linux-x86-64.so.2 (0x00005590bfced000)

이로 인해 로더가 미친 듯이 작동하고 강제 주입 시 세그폴트가 발생합니다.실행 경로들어가세요.

관련 정보